Не удается отобразить треугольник, SharpGL
Я пытаюсь отобразить треугольник, используя SharpGL. Результат - черный экран. Что я делаю не так?
XAML:
<Window x:Class="OpenGL_VAO_VBO.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:OpenGL_VAO_VBO"
xmlns:openGL="clr-namespace:SharpGL.WPF;assembly=SharpGL.WPF"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<openGL:OpenGLControl x:Name="Scene" OpenGLInitialized="OpenGLControl_OpenGLInitialized" Resized="OpenGLControl_Resized" OpenGLDraw="Scene_OpenGLDraw" RenderContextType="FBO" DrawFPS="True"/>
</Grid>
Code Behind
public MainWindow()
{
InitializeComponent();
Verticies = new float [9]
{
-1.0f, -1.0f, 0.0f,
1.0f, -1.0f, 0.0f,
0.0f, 1.0f, 0.0f,
};
}
private void OpenGLControl_OpenGLInitialized(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
{
OpenGL gl = args.OpenGL;
gl.Enable(OpenGL.GL_DEPTH_TEST);
gl.GenBuffers(1, vId);
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vId[0]);
gl.BufferData(OpenGL.GL_ARRAY_BUFFER, Verticies, OpenGL.GL_STATIC_DRAW);
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, 0);
}
private void OpenGLControl_Resized(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
{
// Get the OpenGL instance.
OpenGL gl = args.OpenGL;
// Load and clear the projection matrix.
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.LoadIdentity();
// Perform a perspective transformation
gl.Perspective(45.0f, (float)gl.RenderContextProvider.Width /
(float)gl.RenderContextProvider.Height,
0.1f, 100.0f);
// Load the modelview.
gl.MatrixMode(OpenGL.GL_MODELVIEW);
}
private void Button_Click(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
private void Scene_OpenGLDraw(object sender, SharpGL.SceneGraph.OpenGLEventArgs args)
{
OpenGL gl = args.OpenGL;
gl.Clear(OpenGL.GL_COLOR_BUFFER_BIT | OpenGL.GL_DEPTH_BUFFER_BIT);
gl.LoadIdentity();
gl.EnableClientState(OpenGL.GL_VERTEX_ARRAY);
gl.BindBuffer(OpenGL.GL_ARRAY_BUFFER, vId[0]);
gl.VertexPointer(3, OpenGL.GL_FLOAT, 0, IntPtr.Zero);
gl.DrawArrays(OpenGL.GL_TRIANGLES, 0, Verticies.Length);
gl.DisableClientState(OpenGL.GL_VERTEX_ARRAY);
}
}
}