OpenGL中的纹理显示为单色

时间:2015-06-29 12:07:28

标签: c# opengl textures opentk

我在OpenTK的帮助下摆弄OpenGL但我无法显示简单的纹理。

我的主要问题是我的矩形不显示纹理,而是显示颜色。

这是我的显示循环:

// render graphics
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);

GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
GL.Ortho(-1.0, 1.0, -1.0, 1.0, 0.0, 4.0);


GL.Enable(EnableCap.Texture2D);
GL.BindTexture(TextureTarget.Texture2D, textureId);

GL.Begin(PrimitiveType.Quads);
GL.Vertex2(-1.0f, 1.0f);
GL.Vertex2(1.0f, 1.0f);
GL.Vertex2(1.0f, -1.0f);
GL.Vertex2(-1.0f,-1.0f);
GL.End();

GL.Disable(EnableCap.Texture2D);

game.SwapBuffers();

1 个答案:

答案 0 :(得分:2)

你需要一些纹理坐标。现在它只使用默认的(0, 0) texcoord。

这样的事情:

GL.Begin(PrimitiveType.Quads);
GL.TexCoord2(0.0f, 0.0f);
GL.Vertex2(-1.0f, 1.0f);
GL.TexCoord2(1.0f, 0.0f);
GL.Vertex2(1.0f, 1.0f);
GL.TexCoord2(1.0f, 1.0f);
GL.Vertex2(1.0f, -1.0f);
GL.TexCoord2(0.0f, 1.0f);
GL.Vertex2(-1.0f,-1.0f);
GL.End();
相关问题