OpenGL tex-mapping: the whole object is a single texel color

I have been trying to get a HUD texture to display for a simulator for a while with no success.

First, I bind the texture like this:

glGenTextures(1,&hudTexObj);
gHud = getPPM("textures/purplenebula/hud.ppm",&n,&m,&s);
glBindTexture(GL_TEXTURE_2D,hudTexObj);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); 
//glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,n,m,0,GL_RGB,GL_UNSIGNED_INT, gHud);

      

And then I try to match it to QUAD, which causes the whole square to be a single brown color and I want it to use all texels. This is how I draw:

    glBindTexture(GL_TEXTURE_2D,hudTexObj);

glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glVertex2f(0,0);

glTexCoord2f(0.0,1.0);
glVertex2f(0,m);

glTexCoord2f(1.0,1.0);
glVertex2f(n,m);

glTexCoord2f(1.0,0.0);
glVertex2f(n,0);
glEnd();

      

The weird thing is that I was able to get the exact code above to render the texture in my own program, but when I put it in my main program, it fails. Could this have to do with the texture matrix? I am stunned at this moment.

0


a source to share


1 answer


Silly, I turned on the automatic generation of tex codes far in another part of the code. So if you see a single texel color spanning the whole image, this is the likely cause.



+1


a source







All Articles