Problem with glTexImage2D

I am relatively new to OpenGL programming (only about 6 months experience) and I have having some troubles using glTexImage2D and Texture objects. My application draws a polygon (rectangular polygon made from two triangles) in 3D space and textures an image onto it. Sometimes, during the course of execution the image is modified somewhat, and I need to make sure that the polygon’s texture changes to reflect it. My application is XWindows based, using Motif GLwDrawingArea widgets. This is all of the texture code in my application:

This code is present in my object’s constructor to create the texture object and store some texture settings

// Initialize texture object
glGenTextures(1,&_textureObj);
glBindTexture(GL_TEXTURE_2D, textureObj);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP);

Whenever the image changes, this code is called to modify the texture object to reflect the change. _imageBuf contains the correct image data (I have verified this)

// Bind (select) this image’s texture object
glBindTexture(GL_TEXTURE_2D, _textureObj);

// Assign the texture image
glTexImage2D(GL_TEXTURE_2D, 0 , 3, _texWidth, _texHeight, 0, GL_LUMINANCE,GL_UNSIGNED_BYTE, _imageBuf);

My draw routine contains this code to draw the polygon and texture it.

// Draw the fluoro image
glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
glBindTexture(GL_TEXTURE_2D,di->getTextureObj());

glBegin(GL_TRIANGLE_FAN);
glTexCoord2f(1.0,1.0);
glVertex2f((float)(texWidth/2),(-1.0*(texHeight/2)));
glTexCoord2f(1.0,0.0);
glVertex2f((float)(texWidth/2),(float)(texHeight/2));
glTexCoord2f(0.0,0.0);
glVertex2f((-1.0*(texWidth/2)),(float)(texHeight/2));
glTexCoord2f(0.0, 1.0); glVertex2f((-1.0*(texWidth/2)),(-1.0*(texHeight/2)));
glEnd();
glDisable(GL_TEXTURE_2D);

Now, I have gotten into a state where sometimes the texture is updated and sometimes it is not. I am just looking to any of the gurus out there who may be able to point out a serious flaw in my way of texturing. Sorry for the long-winded post.

G

[This message has been edited by GregR (edited 05-11-2000).]

No, there is no flaw in the way you handle textures, as far as I can see. You do exactly what I would do. The code looks allright to me. Maybe I’m not “guru” enough to see the problem Anyone else out there who has a suggestion?