1
我目前的OpenGL應用程序只是一個球體和一層,照明和陰影正常工作。OpenGL紋理映射禁用底紋
通過紅皮書教程加入了2D紋理的地板後:http://fly.cc.fer.hr/~unreal/theredbook/chapter09.html
..我的陰影被禁用。如果我禁用GL_TEXTURE_2D,一切都呈現正確,但紋理顯然不顯示。這是一個已知問題與已知的解決方法?這裏是一個位的代碼以供參考:
#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);
}
然後粗糙的地面繪製函數:
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();
}
,如果你需要查看代碼的任何其他部分,只是讓我知道
Spot on。謝謝! – grep