Search code examples
qtopengltexturestexture-mapping

Texture coordinates issue with OpenGL, QT


Whatever I use for the texture coordinates, only the bottom-left pixel is ever shown (the rectangle has a solid color).

Here I set the texture coordinates:

glMatrixMode(GL_TEXTURE);
glPushMatrix();
glLoadIdentity();
glTranslatef(0.5,0.0,0.0); //Have no effect

glMatrixMode(GL_MODELVIEW);
glPushMatrix();

...

glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);

glBegin(GL_QUADS);

glTexCoord2f(0, 1);
glVertex2f(0, 0);

glTexCoord2f(0, 0);
glVertex2f(0, 1);

glTexCoord2f(1, 0);
glVertex2f(1, 1);

glTexCoord2f(1, 1);
glVertex2f(1, 0);

glEnd();

It is very serious. It is rendered in two different QGLWidgets. In one Widget the texture looks fine and in the other I get only the bottom left pixel.


Solution

  • I found the mistake. I think that anywhere between the two render processes of the two widgets , is the flag GL_TEXTURE_RECTANGLE_NV setted. I thought that glEnable(GL_TEXTURE_2D); disabled automatically the GL_TEXTURE_RECTANGLE_NV flag. But it seems not.

    So the following solved my Problem:

    glDisable(GL_TEXTURE_RECTANGLE_NV);