PDA

View Full Version : why does not glTexSubImage2D function



Spaceboy
01-26-2002, 02:45 AM
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);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);

glTexSubImage2D(GL_TEXTURE_2D,0,10,10,BLOCKSIZE,BL OCKSIZE,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

zed
01-26-2002, 10:45 AM
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 BLOCKSIZE*BLOCKSIZE*3 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 http://www.opengl.org/discussion_boards/ubb/smile.gif

Bob
01-26-2002, 12:25 PM
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.

Spaceboy
01-26-2002, 03:54 PM
Originally posted by zed:
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 BLOCKSIZE*BLOCKSIZE*3 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 http://www.opengl.org/discussion_boards/ubb/smile.gif

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].

dorbie
01-28-2002, 01:40 AM
Use the integer version of the call, glTexParameteri, and the GL_REPEAT constant, don't cast to float. Do the same for the other parameter calls.

[This message has been edited by dorbie (edited 01-28-2002).]

Husted
01-28-2002, 03:24 AM
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.

-- Niels