我用纹理映射得到了非常奇怪的结果。
我用 128*128 RGBA bmp 图像做 a 的纹理映射GL_QUADS
,然后我得到了以下奇怪的结果,用其他图像测试是可以的,但是对于这个图像,我得到了非常奇怪的结果。
在这里,我想将叶子图像映射到GL_QUADS
.
以下是我的代码:
void init (void)
{
glClearColor(0.6, 0.6, 0.6, 0.0);
glClearDepth(1.0);
glShadeModel(GL_SMOOTH);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glEnable(GL_TEXTURE_2D);
glutSetCursor(GLUT_CURSOR_CROSSHAIR);
}
void display(){
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
GLuint texture[2];
unsigned int outWidth;
unsigned int outHeight;
unsigned int outDepth;
glGenTextures(1, &texture[0]);
glBindTexture(GL_TEXTURE_2D, texture[0]);
unsigned char * data=loadbmp("leaftest.bmp", outWidth, outHeight, outWidth, true);
gluBuild2DMipmaps(GL_TEXTURE_2D, 4, outWidth, outHeight, GL_BGRA, GL_UNSIGNED_BYTE, data);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_REPLACE);
glTranslatef(0, 0, 2);
glRotatef(90, 1, 0, 0);
glBegin(GL_QUADS);
glTexCoord2f(0.0,0.0);
glVertex3f(0.0,-0.6,-0.3);
glTexCoord2f(0.0,1.0);
glVertex3f(0.0,0.0,-0.3);
glTexCoord2f(1.0,1.0);
glVertex3f(0.0,0.0,0.3);
glTexCoord2f(1.0,0.0);
glVertex3f(0.0,-0.6,0.3);
glEnd();
glutSwapBuffers();
}