diff --git a/Assets/shaders/loading.frag b/Assets/shaders/loading.frag new file mode 100644 index 0000000..f8658ce --- /dev/null +++ b/Assets/shaders/loading.frag @@ -0,0 +1,3 @@ +#version 330 core +out vec4 FragColor; +void main() { FragColor = vec4(0.10, 0.12, 0.16, 1.0); } diff --git a/Assets/shaders/loading.vert b/Assets/shaders/loading.vert new file mode 100644 index 0000000..789a0db --- /dev/null +++ b/Assets/shaders/loading.vert @@ -0,0 +1,3 @@ +#version 330 core +layout(location = 0) in vec2 aPos; +void main() { gl_Position = vec4(aPos, 0.0, 1.0); } diff --git a/Rendering/LoadingScreen.cs b/Rendering/LoadingScreen.cs new file mode 100644 index 0000000..91c8568 --- /dev/null +++ b/Rendering/LoadingScreen.cs @@ -0,0 +1,52 @@ +using OpenTK.Graphics.OpenGL4; + +namespace VoxelEngine.Rendering; + +public sealed class LoadingScreen : IDisposable +{ + private readonly int _vao; + private readonly int _vbo; + private readonly Shader _shader; + + public LoadingScreen() + { + this._shader = new Shader("Assets/shaders/loading.vert", "Assets/shaders/loading.frag"); + + // Single triangle covering the entire NDC quad. + float[] vertices = + { + -1f, -1f, + 3f, -1f, + -1f, 3f, + }; + + this._vao = GL.GenVertexArray(); + GL.BindVertexArray(this._vao); + + this._vbo = GL.GenBuffer(); + GL.BindBuffer(BufferTarget.ArrayBuffer, this._vbo); + GL.BufferData(BufferTarget.ArrayBuffer, vertices.Length * sizeof(float), vertices, BufferUsageHint.StaticDraw); + + GL.VertexAttribPointer(0, 2, VertexAttribPointerType.Float, false, 2 * sizeof(float), 0); + GL.EnableVertexAttribArray(0); + + GL.BindVertexArray(0); + } + + public void Draw() + { + GL.Disable(EnableCap.DepthTest); + this._shader.Use(); + GL.BindVertexArray(this._vao); + GL.DrawArrays(PrimitiveType.Triangles, 0, 3); + GL.BindVertexArray(0); + GL.Enable(EnableCap.DepthTest); + } + + public void Dispose() + { + GL.DeleteBuffer(this._vbo); + GL.DeleteVertexArray(this._vao); + this._shader.Dispose(); + } +}