Skip to content

Commit 908d288

Browse files
feat: OpenGL support
1 parent dccf11a commit 908d288

2 files changed

Lines changed: 74 additions & 2 deletions

File tree

FreeFrame/Program.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
using OpenTK;
2+
using OpenTK.Mathematics;
23
using OpenTK.Graphics;
4+
using OpenTK.Windowing.Common;
5+
using OpenTK.Windowing.Desktop;
36

47
namespace FreeFrame
58
{
69
class Program
710
{
811
static void Main()
912
{
10-
13+
NativeWindowSettings nativeWindowSettings = new()
14+
{
15+
Size = new Vector2i(600, 600),
16+
Title = "FreeFrame"
17+
};
18+
using Window window = new(GameWindowSettings.Default, nativeWindowSettings);
19+
window.Run();
1120
}
1221
}
13-
}
22+
}

FreeFrame/Window.cs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using OpenTK.Windowing.Common;
2+
using OpenTK.Windowing.Desktop;
3+
using OpenTK.Graphics.OpenGL4;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace FreeFrame
11+
{
12+
class Window : GameWindow
13+
{
14+
int _vertexBuffer;
15+
16+
public readonly float[] _vertices =
17+
{
18+
0.0f, -0.5f, 0.0f, // Top
19+
-0.5f, 0.5f, 0.0f, // Bottom-Left
20+
0.5f, 0.5f, 0.0f // Bottom-Right
21+
};
22+
public Window(GameWindowSettings gameWindowSettings, NativeWindowSettings nativeWindowSettings) : base(gameWindowSettings, nativeWindowSettings) { }
23+
protected override void OnLoad()
24+
{
25+
base.OnLoad();
26+
_vertexBuffer = GL.GenBuffer();
27+
GL.BindBuffer(BufferTarget.ArrayBuffer, _vertexBuffer);
28+
29+
GL.BufferData(BufferTarget.ArrayBuffer, _vertices.Length * sizeof(float), _vertices, BufferUsageHint.StaticDraw);
30+
31+
GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 3 * sizeof(float), 0);
32+
GL.EnableVertexAttribArray(0);
33+
34+
}
35+
protected override void OnResize(ResizeEventArgs e)
36+
{
37+
base.OnResize(e);
38+
// TODO: map the new NDC to the window
39+
}
40+
/// <summary>
41+
/// Triggered at a fixed interval. (Logic, etc.)
42+
/// </summary>
43+
/// <param name="e"></param>
44+
protected override void OnUpdateFrame(FrameEventArgs e)
45+
{
46+
base.OnUpdateFrame(e);
47+
}
48+
/// <summary>
49+
/// Triggered as often as possible (fps). (Drawing, etc.)
50+
/// </summary>
51+
/// <param name="e"></param>
52+
protected override void OnRenderFrame(FrameEventArgs e)
53+
{
54+
base.OnRenderFrame(e);
55+
GL.DrawArrays(PrimitiveType.Triangles, 0, 3);
56+
}
57+
58+
protected override void OnUnload()
59+
{
60+
base.OnUnload();
61+
}
62+
}
63+
}

0 commit comments

Comments
 (0)