53 lines
1.4 KiB
C#
53 lines
1.4 KiB
C#
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();
|
|
}
|
|
}
|