Reputation: 91
I'm using OpenTK to create a graphics engine, but it doesn't want to draw anything. Clearing the screen works, also swapping the buffers, but when I try to draw a rectangle using a vertex array or legacy OpenGL it won't work.
I've reproduced the problem in this small test program:
private static GameWindow window;
private static int vao;
private static int vbo;
static void Main(string[] args)
{
window = new GameWindow();
window.Load += Window_Load;
window.RenderFrame += Window_RenderFrame;
window.Run();
}
private static void Window_Load(object sender, EventArgs e)
{
vao = GL.GenVertexArray();
GL.BindVertexArray(vao);
vbo = GL.GenBuffer();
GL.BindBuffer(BufferTarget.ArrayBuffer, vbo);
GL.BufferData(BufferTarget.ArrayBuffer, new IntPtr(3), new float[] {
-0.5f, -0.5f, 0f,
0.5f, -0.5f, 0f,
0.5f, 0.5f, 0f,
0.5f, 0.5f, 0f,
-0.5f, 0.5f, 0f,
-0.5f, -0.5f, 0f
}, BufferUsageHint.StaticDraw);
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0);
}
private static void Window_RenderFrame(object sender, FrameEventArgs e)
{
GL.ClearColor(1, 0, 0, 1);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.DrawArrays(PrimitiveType.Triangles, 0, 6);
window.SwapBuffers();
}
Can anyone give me a hint on what I'm doing wrong?
Upvotes: 0
Views: 1579
Reputation: 1511
A simple rendering pipeline needs some basic information to draw vertices:
Your code doesn't specify any of that except for the vertex locations. There are a number of reasons why your triangles might not be visible:
Upvotes: 0