Question

I have a an odd problem with some texturing in opengl:

enter image description here

This scene is comprised of an open box composed of 4 textured quadrics (floor and 3 walls) and some crude mushrooms made from gluSpheres that have been translated, scaled and textured respectively.

If you look specifically at the floor, you'll see that half of the quadric has had it's texture massively warped, I have triple checked the texture coordinates for the floor, and there appears to be nothing wrong with them (as you can see, the other three walls are fine and they follow the same pattern as the floor). This happens with any texture that I use (I'm just using RAW RGB data).

I take my mushrooms out of the scene and the warping goes away, it's really bizzare. Has anyone seen this before? i'm relatively new to opengl, so I didn't know what to look for when I saw this. Thanks in advance.

Edit:

Code for the box:

    void drawRoom(void) {
        glPushMatrix();
            glScalef(10,10,10);
            GLuint texture = LoadTextureRAW("cave_two.raw",1);
            glEnable(GL_TEXTURE_2D);
            glBegin(GL_QUADS);

            //Floor
            glVertex3f(-1,-1,-1); glTexCoord2f(0,0); glNormal3f(0,1,0);
            glVertex3f(1,-1,-1); glTexCoord2f(1,0); glNormal3f(0,1,0);
            glVertex3f(1,-1,1); glTexCoord2f(1.0,1.0); glNormal3f(0,1,0);
            glVertex3f(-1,-1,1); glTexCoord2f(0.0,1.0); glNormal3f(0,1,0);


            //Back wall
            glVertex3f(-1,-1,-1); glTexCoord2f(0,0); glNormal3f(0,0,1);
            glVertex3f(1,-1,-1); glTexCoord2f(1,0); glNormal3f(0,0,1);
            glVertex3f(1,1,-1); glTexCoord2f(1.0,1.0); glNormal3f(0,0,1);
            glVertex3f(-1,1,-1); glTexCoord2f(0.0,1.0); glNormal3f(0,0,1);

            //Right wall
            glVertex3f(1,1,1); glTexCoord2f(0,0); glNormal3f(-1,0,0);
            glVertex3f(1,-1,1); glTexCoord2f(1,0); glNormal3f(-1,0,0);
            glVertex3f(1,-1,-1); glTexCoord2f(1.0,1.0); glNormal3f(-1,0,0);
            glVertex3f(1,1,-1); glTexCoord2f(0.0,1.0); glNormal3f(-1,0,0);

            //Left wall
            glVertex3f(-1,1,1); glTexCoord2f(0,0); glNormal3f(1,0,0);
            glVertex3f(-1,-1,1); glTexCoord2f(1,0); glNormal3f(1,0,0);
            glVertex3f(-1,-1,-1); glTexCoord2f(1.0,1.0); glNormal3f(1,0,0);
            glVertex3f(-1,1,-1); glTexCoord2f(0.0,1.0); glNormal3f(1,0,0);

            glEnd();
            glDisable(GL_TEXTURE_2D);
            glDeleteTextures( 1, &texture );
        glPopMatrix();
        }
Was it helpful?

Solution

Without seeing the code, all we can do is wild guesses. Here's mine.

I suspect that you specify a vertex first (glVertex*), and the texture coordinates for that vertex second (glTexCoord*). This is the wrong way round: the texcoords become part of the state, and get applied to all subsequently drawn vertices. With a texture like this, you wouldn't notice that it is actually 90 degrees rotated.

Furthermore, I suspect you draw the mushrooms first, and the box second. Then, the first vertex of the box receives the texcoord that the last mushroom happened to use on its last vertex, which happened to be wrong. Without the shrooms, it gets the last texcoord from the last box face, which happened to be correct.

You might also want to specify GL_LINEAR_MIPMAP_LINEAR instead of GL_LINEAR_MIPMAP_NEAREST to make the mipmapping artifacts go away, since now there's a clear edge between where the 0th and 1st level mipmap are used.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top