This commit is contained in:
Max Westerlund
2025-09-02 13:17:15 +02:00
parent b6f9966eb9
commit 71c5f3a3aa
15 changed files with 618 additions and 37 deletions

View File

@@ -1,30 +1,43 @@
using OpenTK.Graphics.OpenGL4;
using OpenTK.Windowing.Common;
using OpenTK.Windowing.Desktop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Voxel
{
public class Window(int width, int height, string title) : GameWindow(GameWindowSettings.Default, new NativeWindowSettings() { Size = (width, height), Title = title })
public class Window(int width, int height, string title) : GameWindow(GameWindowSettings.Default, new NativeWindowSettings() { ClientSize = (width, height), Title = title })
{
private Triangle _triangle;
public readonly int Width = width;
public readonly int Height = height;
public uint frames = 0;
public double timeElapsed = 0;
protected override void OnUpdateFrame(FrameEventArgs args)
protected override void OnUpdateFrame(FrameEventArgs e)
{
base.OnUpdateFrame(args);
base.OnUpdateFrame(e);
if (Input.GetKey(OpenTK.Windowing.GraphicsLibraryFramework.Keys.Escape))
{
Close();
}
}
protected override void OnRenderFrame(FrameEventArgs args)
protected override void OnRenderFrame(FrameEventArgs e)
{
base.OnRenderFrame(args);
base.OnRenderFrame(e);
GL.Clear(ClearBufferMask.ColorBufferBit);
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
_triangle.Draw();
frames++;
timeElapsed += e.Time;
if (timeElapsed >= 1)
{
Console.WriteLine("FPS: " + frames.ToString());
timeElapsed = 0;
frames = 0;
}
Camera.Update((float)e.Time);
Renderer.Render();
SwapBuffers();
}
@@ -40,9 +53,34 @@ namespace Voxel
{
base.OnLoad();
_triangle = new Triangle();
Renderer.OnLoad();
GL.ClearColor(0.5f, 0.5f, 0.5f, 1f);
GL.ClearColor(0.72f, 0.88f, 0.97f, 1f);
GL.Enable(EnableCap.CullFace);
GL.Enable(EnableCap.DepthTest);
CursorState = CursorState.Grabbed;
VSync = VSyncMode.On;
}
protected override void OnMouseMove(MouseMoveEventArgs e)
{
base.OnMouseMove(e);
Camera.UpdateMouse(e.Delta);
}
protected override void OnKeyUp(KeyboardKeyEventArgs e)
{
base.OnKeyUp(e);
Input.SetKey(e.Key, false);
}
protected override void OnKeyDown(KeyboardKeyEventArgs e)
{
base.OnKeyDown(e);
Input.SetKey(e.Key, true);
}
}
}