I started studying SharpGL on WPF, and I wanted to learn how to output a picture, I found a tutorial where it was shown how to output a picture, but after rewriting the code to myself, the picture is not output, but output a red image, what could be wrong? Wpf screen
Texture texture = new Texture();
private void openGLControl1_OpenGLInitialized(object sender, EventArgs e)
{
// Get the OpenGL object, for quick access.
SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
// Get the OpenGL object, for quick access.
// A bit of extra initialisation here, we have to enable textures.
gl.Enable(OpenGL.GL_TEXTURE_2D);
// Create our texture object from a file. This creates the texture for OpenGL.
texture.Create(gl, @"C:\Users\user\Desktop\Crate.bmp");
}
private void OpenGLControl_OpenGLDraw(object sender, OpenGLRoutedEventArgs args)
{
// System.Threading.Thread.Sleep(1000);
SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
texture.Bind(gl);
gl.LoadIdentity();
gl.Translate(0, 0, -1f);
gl.Begin(OpenGL.GL_QUADS);
var startX = 0 - 0 / 2;
var startY = 0 - 0 / 2;
float width = 100;
float height = 100;
gl.TexCoord(0, 1); gl.Vertex(new[] { startX, startY });
gl.TexCoord(1, 1); gl.Vertex(new[] { startX + width, startY });
gl.TexCoord(1, 0); gl.Vertex(new[] { startX + width, startY + height });
gl.TexCoord(0, 0); gl.Vertex(new[] { startX, startY + height });
gl.End();
gl.Flush();
}
private void OpenGLControl_Resized(object sender, OpenGLRoutedEventArgs args)
{
SharpGL.OpenGL gl = this.openGLControl1.OpenGL;
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.LoadIdentity();
float w = 450;
float h = w * 0.5625f;
gl.Viewport(0, 0, (int)w, (int)h);
gl.MatrixMode(OpenGL.GL_MODELVIEW);
}