My current openGL application is just a sphere and a floor, with lighting and shading working properly.
After adding a 2d texture to the floor via the redbook tutorial: http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html
.. my shading becomes disabled. If I disable GL_TEXTURE_2D, everything renders correctly, but the texture obviously does not show up. Is this a known issue with with a known workaround? Here is a bit of the code for reference:
#define checkImageWidth 64
#define checkImageHeight 64
GLubyte checkImage[checkImageWidth][checkImageHeight][3];
void makeCheckImage(void)
{
int i, j, c;
for (i = 0; i < checkImageWidth; i++) {
for (j = 0; j < checkImageHeight; j++) {
c = ((((i&0x8)==0)^(((j&0x8))==0)))*255;
checkImage[i][j][0] = (GLubyte) c;
checkImage[i][j][1] = (GLubyte) c;
checkImage[i][j][2] = (GLubyte) c;
}
}
}
void initImage() {
makeCheckImage();
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D(GL_TEXTURE_2D, 0, 3, checkImageWidth,
checkImageHeight, 0, GL_RGB, GL_UNSIGNED_BYTE,
&checkImage[0][0][0]);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
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_DECAL);
}
And then of coarse the ground draw function:
void makeGround() {
GLfloat mat_specular[] = { 0.5, 0.5, 0.5, 0.5 };
GLfloat mat_diffuse[] = { 0.3, 0.3, 0.3, 0.3 };
GLfloat mat_shininess[] = { 25.0 };
glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
glColor3f(0.2, 0.2, 0.2);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(-100.0f, -1.0f, -100.0f);
glTexCoord2f(0.0, 1.0); glVertex3f(-100.0f, -1.0f, 100.0f);
glTexCoord2f(1.0, 1.0); glVertex3f( 100.0f, -1.0f, 100.0f);
glTexCoord2f(1.0, 0.0); glVertex3f( 100.0f, -1.0f, -100.0f);
glEnd();
glFlush();
}
if you need to see any additional portions of the code, just let me know