gpt4 book ai didi

c - OpenGL、SOIL 库和带纹理的矩形

转载 作者:太空宇宙 更新时间:2023-11-04 02:20:24 30 4
gpt4 key购买 nike

我正在尝试使用 SOIL 和 GLUT 在 OpenGL 中制作一个简单的纹理矩形。

这是我的 Display 函数(由 glutDisplayFunc(Display) 在 main 中执行):

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();
}

这样只能看到一个没有任何纹理的黑色矩形。我想用这个做几个小时。请帮忙,提前致谢。

最佳答案

会不会是你在绘制矩形之前将颜色设置为黑色?线路

glColor3f (0.0,0.0,0.0);

试试白色...

glColor3f (1.0,1.0,1.0);

关于c - OpenGL、SOIL 库和带纹理的矩形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/735493/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com