我正在尝试使用SOIL和GLUT在OpenGL中制作一个简单的纹理矩形。
这是我的显示功能(由glutDisplayFunc(显示)主要执行):
void Display ()
{
GLuint tex_2d;
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glClear (GL_COLOR_BUFFER_BIT);
glClearColor (1.0,1.0,1.0,1.0);
gluLookAt (eyex,eyey,eyez,centerx,centery,centerz,0,1,0);
glEnable(GL_TEXTURE_2D);
tex_2d = SOIL_load_OGL_texture
(
"img.png",
SOIL_LOAD_AUTO,
SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
);
if( 0 == tex_2d )
{
printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
exit(1);
}
glBindTexture(GL_TEXTURE_2D, tex_2d);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR);
glColor3f (0.0,0.0,0.0);
glBegin(GL_POLYGON);
glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
glFlush ();
glutSwapBuffers();
}
这只是看到没有任何纹理的黑色矩形。我想用这个做几个小时。请提前帮助,谢谢。
答案 0 :(得分:3)
是否可以在绘制矩形之前将颜色设置为黑色?这条线
glColor3f (0.0,0.0,0.0);
尝试使用白色......
glColor3f (1.0,1.0,1.0);