OpenGL、SOIL 库和纹理矩形
我正在尝试使用 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();
}
这样只能看到一个没有任何纹理的黑色矩形。 我正在尝试用这几个小时做点什么。 请帮忙,提前致谢。
I'm trying to make a simple textured rectangular in OpenGL using SOIL and GLUT.
This is my Display function (executed in main by glutDisplayFunc(Display)):
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();
}
With this is see only a black rectangular without any texture. I'm trying to do something with this for a few hours. Please help, thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
难道是在绘制矩形之前将颜色设置为黑色吗? 该行
尝试白色代替...
Could it be that you set the color to black just before you draw the rectangle? The line
Try white instead...