feat: add LoadingScreen with full-screen triangle shader
This commit is contained in:
3
Assets/shaders/loading.frag
Normal file
3
Assets/shaders/loading.frag
Normal file
@@ -0,0 +1,3 @@
|
||||
#version 330 core
|
||||
out vec4 FragColor;
|
||||
void main() { FragColor = vec4(0.10, 0.12, 0.16, 1.0); }
|
||||
3
Assets/shaders/loading.vert
Normal file
3
Assets/shaders/loading.vert
Normal file
@@ -0,0 +1,3 @@
|
||||
#version 330 core
|
||||
layout(location = 0) in vec2 aPos;
|
||||
void main() { gl_Position = vec4(aPos, 0.0, 1.0); }
|
||||
52
Rendering/LoadingScreen.cs
Normal file
52
Rendering/LoadingScreen.cs
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user