PDA

View Full Version : perspective correct texturing anomally



04-06-2001, 04:26 AM
I'm drawing a very basic scene: a textured quad in the forground and a non-textured quad in the background. When I don't draw the backgound quad the forground quad appears as expected. But, I'm getting a weird texture warping/swimming effect (on the foreground quad) when I draw the background quad (marked with #if...#endif).
glHint() doesn't seem to do anything. Here are the relevant functions:

void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

#if 1
// setup model matrix
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();

// setup proj matrix
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluOrtho2D(-1,1,-1,1);

// no textures, depth test
glDisable(GL_TEXTURE_2D);
glDisable(GL_DEPTH_TEST);

// draw background gradient
glBegin(GL_QUADS);
glColor3f(0.4f,0.0f,0.0f);
glVertex2i(-1,-1);
glVertex2i(1,-1);
glColor3f(0.0f,0.0f,0.4f);
glVertex2i(1,1);
glVertex2i(-1,1);
glEnd();

// restore proj & model matr.
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
#endif

// use textures, depth test
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);

// rotate scene from mouse input
glPushMatrix();
glTranslatef(g_cam_mov[0],g_cam_mov[1],g_cam_mov[2]);
glRotatef(g_cam_rot[0], 1.0f, 0.0f, 0.0f);
glRotatef(g_cam_rot[1], 0.0f, 1.0f, 0.0f);
glRotatef(g_cam_rot[2], 0.0f, 0.0f, 1.0f);

DrawScene();

glPopMatrix();

glutSwapBuffers();
}//display

void DrawScene()
{
glBegin(GL_QUADS);
glColor4f(1,0,0,1); glTexCoord2f(0,0); glVertex2f(-1,-1);
glColor4f(0,1,0,1); glTexCoord2f(1,0); glVertex2f(1,-1);
glColor4f(0,0,1,1); glTexCoord2f(1,1); glVertex2f(1,1);
glColor4f(1,1,1,0); glTexCoord2f(0,1); glVertex2f(-1,1);
glEnd();
}//DrawScene

void SetupTextures()
{
static GLubyte checker[4*4]=
{
0,0,0,0xff, 0xff,0xff,0xff,0,
0xff,0xff,0xff,0, 0,0,0,0xff
};

glPixelStorei(GL_UNPACK_ALIGNMENT,1);
glTexImage2D(GL_TEXTURE_2D,0,4,2,2,0,GL_RGBA,GL_UN SIGNED_BYTE, checker);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_NEAREST);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DE CAL);

glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef(10,10,10);
glMatrixMode(GL_MODELVIEW);

glEnable(GL_TEXTURE_2D);
glHint(GL_PERSPECTIVE_CORRECTION_HINT,GL_NICEST);
}//SetupTextures

Korval
04-06-2001, 09:18 AM
Your OpenGL implementation may not support Perspective correct textures. What implementation are you using?