How to wrap a 8000x2000 texture onto a cylinder?

Hello there,

I’m building a sort of panorama application where I need to wrap 8000x2000px cylindrical panoramass (jpegs) onto an OpenGL cylinder. I’ve managed to get a 2048x512 image to fit nicely on a gluCylinder but anything bigger goes blank. My GL_MAX_TEXTURE_SIZE is 2048 so I guess I’ve hit some kind of limit.

So. i’m new to OpenGL but I presume there are ways to make this work. Splitting the huge image into four smaller?

If some of you bright people could point me in the right direction I’d be super grateful!



yes, you’ll definitely have to split the image into four smaller ones…

make four new buffers of unsigned char[3*2000*2000] then copy row by row. something like this (untested code):

unsigned char* hugeImagePixels = hugeImage.getPixels();  
unsigned char* sections[4];  
for ( int i=0; i<4 ;i++)  
  sections[i] = new unsigned char[2000*2000*3];  
  for (int j=0;j<2000; j++ )  
    // copy 1 row of pixels from hugeImagePixels to sections  
    memcpy( sections[i][j*2000*3], hugeImagePixels[j*2000*3*4+i*2000*3], 2000*3 );  

(this is assuming RGB images - for RGBA change all the 3’s into 4’s.)

then just make four ofxTexture or ofxImage objects and call setFromPixels passing in each of sections[] as a pixels pointer.

don’t forget to delete[] each of the sections[] arrays you new[]'d.

Thanks a bunch!

Now, I have two related cylindrical questions. Any hints appreciated.

  1. How can I apply the four images as if they were one, large, texture filling the whole of the inside of the cylinder?

  2. How can i mirror the image so it looks correct on the inside of the cylinder, not the outside?


1.You have to construct each vertex of the cylinder manually and give texture coordinates to it. Group them by texture and when drawing bind the relevant texture. pseudocode:

// loop through all vertices for quadrant1 and glTexCoord2f, glVertex  
// loop through all vertices for quadrant2 and glTexCoord2f, glVertex  
// loop through all vertices for quadrant3 and glTexCoord2f, glVertex  
// loop through all vertices for quadrant4 and glTexCoord2f, glVertex  

  1. To mirror the image, it’s just a case of flipping the texture coordinates.

It may be worth considering just doing this in a 3D app like blender / cinema4d / 3dsmax and exporting as 3DS. If you are comfortable with a 3D app, it’ll probably be quicker to do it that way.