我使用SharpGL库进行Visual C#。我想为SharpGL.SceneGraph.Primitives.Polygon添加纹理。
SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
textureImage = new Bitmap(openDialog.FileName);
gl.Enable(OpenGL.GL_TEXTURE_2D);
gl.GenTextures(1, textures);
gl.BindTexture(OpenGL.GL_TEXTURE_2D, textures[0]);
gl.TexImage2D(OpenGL.GL_TEXTURE_2D, 0, 3, textureImage.Width, textureImage.Height, 0, OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, textureImage.LockBits(new Rectangle(0, 0, textureImage.Width, textureImage.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb).Scan0);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MIN_FILTER, OpenGL.GL_LINEAR);
gl.TexParameter(OpenGL.GL_TEXTURE_2D, OpenGL.GL_TEXTURE_MAG_FILTER, OpenGL.GL_LINEAR);
加载图片之前我需要做什么? 我通过
绘制我的模型foreach (Polygon polygon in polygons)
{
polygon.PushObjectSpace(gl);
polygon.Render(gl, SharpGL.SceneGraph.Core.RenderMode.Render);
polygon.PopObjectSpace(gl);
}