【发布时间】:2014-11-19 23:46:21
【问题描述】:
我正在使用 OpenTK,我很难理解 openGL 启用函数的概念。 透视矩阵在 onResize 函数中。
我正在尝试展示纹理。
我的渲染函数:
GL.ClearColor(0.5f, 0.5f, 0.5f, 1.0f);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadIdentity();
GL.Enable(EnableCap.Texture2D);
GL.Enable(EnableCap.DepthTest);
Ground.Draw();
我的 Ground.Draw() 函数(sizeXZ.Z, sizeXZ.Y 是常量):
GL.PushMatrix();
GL.Translate(new Vector3(-sizeXZ.X / 2, -1, sizeXZ.Y / 2));
GL.BindTexture(TextureTarget.Texture2D, Textures.GetTextureId(textureName));
GL.Begin(PrimitiveType.Quads);
GL.Color3(1,1,1);
GL.Normal3(0, 1, 0);
GL.TexCoord2(1f, 1f); GL.Vertex3(0, 0, 0);
GL.TexCoord2(1f, 0f); GL.Vertex3(sizeXZ.X, 0, 0);
GL.TexCoord2(0f, 0f); GL.Vertex3(sizeXZ.X, 0, -sizeXZ.Y);
GL.TexCoord2(0f, 1f); GL.Vertex3(0, 0, -sizeXZ.Y);
GL.End();
GL.PopMatrix();
它显示了一个黑色的无纹理四边形。当我添加一些光线时,纹理会出现,但某些四边形的颜色会消失:
GL.BindTexture(TextureTarget.Texture2D, Textures.GetTextureId(textureName));
GL.Begin(PrimitiveType.Quads);
GL.Normal3(0, 0, 1);
if (true) GL.Color4(0,1,0,1); // it appears to be the background color, not green
if (false) GL.TexCoord2(1f, 0f); GL.Vertex3(0, 0, 0);
if (false) GL.TexCoord2(1f, 1f); GL.Vertex3(3f, 0, 0);
if (false) GL.TexCoord2(0f, 1f); GL.Vertex3(3f, 3f, 0);
if (false) GL.TexCoord2(0f, 0f); GL.Vertex3(0, 3f, 0);
GL.Color4(1, 1, 1, 1);
GL.End();
【问题讨论】:
-
您没有启用照明,所以这无关紧要。我认为您不必指定Normal。由于您看到了四边形,因此坐标或矩阵都不是问题。纹理坐标看起来不错。如果不绑定纹理会发生什么?那么它是否以正确的颜色显示?
-
GL.Color3(1,1,1)- 绘制黑色GL.Color3(Color.Aqua)- 正常绘制