Hello, everybody
I try to use glTexSubImage2D in my program.
when i read the imagedata from a image file, i want to use part of the image as texture on the surface, the program code is as following
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, (float)GL_REPEAT);//(float)GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (float)GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexSubImage2D(GL_TEXTURE_2D,0,10,10,BLOCKSIZE,BLOCKSIZE,GL_RGB,GL_UNSIGNED_BYTE,pBlockImage[0]);
glEnable(…)
but the result is not correct, no image was textured on the surface of terrain.
can anyone tell me the reason.
many thanks
Are you using glTexSubImage to create a new texture perhaps? Well, that function is used to replace parts of an existing texture, and won’t create a new one. Do that with glTexImage.
Originally posted by zed:
[b]glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, (float)GL_REPEAT);
aye whys that float there? GL_REPEAT is an int or unit (though thats not important just write GL_REPEAT without the cast)
is pBlockImage containing enuf space ie it has BLOCKSIZEBLOCKSIZE3 GLubyte’s
also try pBlockImage (without the [0] or chuck a & infront of it) would u believe i start programming in C 16 years ago [/b]
the pBlockImage[0] is the the address of the image. I divide thelarge image into several blocks, each blocks contains the image data the address is pBlockImage[i].
Originally posted by Spaceboy: the pBlockImage[0] is the the address of the image. I divide thelarge image into several blocks, each blocks contains the image data the address is pBlockImage[i].
If the pBlockImage contains image data for multiple textures you need to setup the pixel transfer pipeline to extract the correct sub-image. Take a look at the GL_UNPACK_ROW_LENGTH, GL_UNPACK_SKIP_PIXELS, GL_UNPACK_SKIP_ROWS parameters for glPixelStorei.