opengl 纹理立方体 c++
你好,我创建了一个立方体,并希望在一侧有纹理。
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filterMode);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filterMode);
glBegin(GL_POLYGON); //Vorderseite
glColor4f(1.0f,0.0f,0.0f,1.0f); //ROT
glVertex3f(-fSeitenL/2.0f,-fSeitenL/2.0f,+fSeitenL/2.0f);
glColor4f(1.0f,1.0f,0.0f,1.0f); //GELB
glVertex3f(+fSeitenL/2.0f,-fSeitenL/2.0f,+fSeitenL/2.0f);
glColor4f(1.0f,1.0f,1.0f,1.0f); //WEISS
glVertex3f(+fSeitenL/2.0f,+fSeitenL/2.0f,+fSeitenL/2.0f);
glColor4f(1.0f,0.0f,1.0f,1.0f); //MAGENTA
glVertex3f(-fSeitenL/2.0f,+fSeitenL/2.0f,+fSeitenL/2.0f);
glEnd();
glDisable(GL_TEXTURE_2D);
但我看不到我的纹理,我做错了什么? 谢谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您尚未提供纹理坐标。您需要先调用一次
glTexCoord
(2f
变体是最常用的)来指示矢量映射到的纹理的一部分, 相应的glVertex
调用。否则,OpenGL 不知道如何将纹理粘贴到多边形上。
You haven't supplied texture coordinates. You need to issue one call to
glTexCoord
(the2f
variant being the most commonly-used) that indicates a part of the texture that the vector maps to, before the correspondingglVertex
call.Otherwise, OpenGL has no idea how the texture should be pasted onto the polygons.
首先,这看起来不是一个立方体,而只是一个四边形,一个立方体是由6个不同的四边形组成的..(并且您可以使用
GL_QUADS code> 而不是 GL_POLYGON
第二件事是您正在加载纹理但不将其映射到顶点您需要提供坐标来映射纹理应如何适合四边形。使用的
示例取自 NEHE OpenGL 指南,我真的建议您看一下,因为它解释得很好:http://nehe.gamedev.net
查看有关纹理映射的教程 6:http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06
First of all this doesn't seem a cube but just a quad, a cube is made by 6 different quads.. (and you could use
GL_QUADS
instead thatGL_POLYGON
.Second thing is that you are loading the texture but not mapping it to the vertices. You need to supply coordinates to map how the texture should fit onto the quad. You can do it by using
the example is taken from NEHE OpenGL guide and I really suggest you to take a look since it's quite well explained: http://nehe.gamedev.net
Check tutorial 6 about texture mapping: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=06