I got some problem when I tried to map a texture to a polygon, here is the code:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, opacityTexture);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
gluPerspective(50, 1, 0.1, 100);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
gluLookAt(0, 0, 1,
0, 0, 0,
0, 1, 0);
glEnable(GL_TEXTURE_2D);
glColor4f(1.0, 0.0, 0.0, 1.0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.45, -0.45, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(0.45, -0.45, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.45, 0.45, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.45, 0.45, 0.0);
glEnd();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glDisable(GL_TEXTURE_2D);
If I change the third parameter in glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE) to GL_ADD, I can get a rectangle with the color defined by glColor().
If the third paramter is GL_REPLACE, then I get a black rectangle, the texture does not appear.
Is there any obvious problems with the code above?