View Full Version : Need help with glPixelStorei (and glTexImage2D)

07-12-2009, 04:46 AM
I used the search, but seems that no-one has such problem like me. The story is:

Im taking big BMP (for example 768x128) that contains 64x64 tiles. I need to extract these tiles and create textures from each one with glTexImage2D. I have done something already but it doesn't work like i need and want.
Practically same problem like here:
http://www.opengl.org/discussion_boards/...true#Post236512 (http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=236512&Searchpa ge=4&Main=46795&Words=glpixelstorei&Search=true#Po st236512)

here is the code:

// generate 24 textures

glGenTextures(24, @tekstures);

// 12 columns

for i:=0 to 11 do

// 2 rows of tiles in total

for j:=0 to 1 do

glBindTexture(GL_TEXTURE_2D, tekstures[i]);


glPixelStorei(GL_UNPACK_ROW_LENGTH,768); //image width=768
glPixelStorei(GL_UNPACK_SKIP_PIXELS, i * 64);

glPixelStorei(GL_UNPACK_SKIP_ROWS, j * 64);
// pBits contains image data

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE,pbits );


PROBLEM: it just jumps to the last row and just skips the any previous ones. So as result: i have only textures generated from the last row of my tilesheet.

I guess more calculations must be done?
But what calculations? This is the place im stuck.

Why it skips to last row and doesn't generate textures from whole BMP ?

07-12-2009, 07:46 AM
I don't understand what you are doing. Or the practicality of it. :)

Why not leave the tiles in the BMP, and then just use it as a texture atlas to render from? Less binding then surely?

07-12-2009, 07:53 AM
I don't know how to use texture atlas.
That's the problem. But i will try to find stuff about it on Google.