I am trying to draw a simple 3D object on a window using C# and Open TK. I have defined the GameWindowSettings and the NativeWindowSettings and passed them to the constructor of the GameWindow constructor. I have attached event handlers for the OnLoad and OnRenderFrame events of the game window and pasted code inside both of them that should draw a simple 3D cube on the window but its not working, can anyone help me make my code draw the desired object in the game window.
What I have tried:
namespace MyVideoGame
{
internal static class Program
{
[STAThread]
static void Main(string[] args) {
var windowsettigs = new GameWindowSettings
{
RenderFrequency = 60,
UpdateFrequency = 60
};
var nativeSettings = new NativeWindowSettings
{
Size = new Vector2i(900, 600),
Title = "Rotating Bridge",
};
var mygame = new GameWindow(windowsettigs, nativeSettings);
mygame.Load += Mygame_Load;
mygame.RenderFrame += Mygame_RenderFrame;
mygame.Run();
}
private static void Mygame_RenderFrame(OpenTK.Windowing.Common.FrameEventArgs obj)
{
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
Matrix4 modelview = Matrix4.LookAt(new Vector3(0, 0, 3), Vector3.Zero, Vector3.UnitY);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref modelview);
GL.Color3(Color.Green);
GL.Begin(PrimitiveType.Quads);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
GL.Vertex3(1.0f, -1.0f, 1.0f);
GL.Vertex3(1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(1.0f, -1.0f, -1.0f);
GL.Vertex3(1.0f, 1.0f, -1.0f);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3(-1.0f, 1.0f, 1.0f);
GL.Vertex3(-1.0f, 1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, -1.0f);
GL.Vertex3(-1.0f, -1.0f, 1.0f);
}
private static void Mygame_Load()
{
GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
}
}