added barebones ui rendering
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using OpenTK.Graphics.OpenGL4;
|
||||
using OpenTK.Mathematics;
|
||||
using Voxel.Core;
|
||||
|
||||
namespace Voxel.Graphics
|
||||
@@ -11,17 +12,25 @@ namespace Voxel.Graphics
|
||||
|
||||
private static Dictionary<(int, int), int> _chunkBufferSizes = new Dictionary<(int, int), int>();
|
||||
private static Shader _shader;
|
||||
private static Shader _uiShader;
|
||||
private static GuiBatcher _guiBatcher;
|
||||
private static readonly Texture _texture;
|
||||
private static readonly Texture _uiTexture;
|
||||
private static World? _world;
|
||||
|
||||
public static int WindowHeight = 1080;
|
||||
public static int WindowWidth = 1920;
|
||||
|
||||
static Renderer()
|
||||
{
|
||||
string vertexPath = "Shaders/shader.vert";
|
||||
string fragmentPath = "Shaders/shader.frag";
|
||||
string texturePath = "Assets/atlas.png";
|
||||
string uiTexturePath = "Assets/ascii.png";
|
||||
|
||||
_shader = new Shader(vertexPath, fragmentPath);
|
||||
_texture = new Texture(texturePath);
|
||||
_uiTexture = new Texture(uiTexturePath);
|
||||
|
||||
_shader.SetInt("uTexture", 0);
|
||||
|
||||
@@ -33,6 +42,10 @@ namespace Voxel.Graphics
|
||||
|
||||
GL.BufferData(BufferTarget.ShaderStorageBuffer, 1024 * 1024 * 128, IntPtr.Zero, BufferUsageHint.DynamicDraw);
|
||||
GL.BindBufferBase(BufferRangeTarget.ShaderStorageBuffer, 0, _ssbo);
|
||||
|
||||
_guiBatcher = new GuiBatcher();
|
||||
_uiShader = new Shader("Shaders/ui.vert", "Shaders/ui.frag");
|
||||
_uiShader.SetInt("uTexture", 1);
|
||||
}
|
||||
|
||||
public static void Render()
|
||||
@@ -44,6 +57,7 @@ namespace Voxel.Graphics
|
||||
_shader.SetMatrix4("view", Camera.view);
|
||||
_shader.SetVector3("cameraPosition", Camera.Position);
|
||||
_shader.SetMatrix4("projection", Camera.projection);
|
||||
_texture.Bind(TextureUnit.Texture0);
|
||||
|
||||
if (_buffersDirty)
|
||||
{
|
||||
@@ -110,7 +124,24 @@ namespace Voxel.Graphics
|
||||
|
||||
private static void RenderUi()
|
||||
{
|
||||
GL.Disable(EnableCap.CullFace);
|
||||
GL.Disable(EnableCap.DepthTest);
|
||||
GL.Enable(EnableCap.Blend);
|
||||
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
|
||||
|
||||
_uiShader.Use();
|
||||
|
||||
Matrix4 projection = Matrix4.CreateOrthographicOffCenter(0, WindowWidth, WindowHeight, 0, -1, 1);
|
||||
_uiShader.SetMatrix4("projection", projection);
|
||||
|
||||
_uiTexture.Bind(TextureUnit.Texture0);
|
||||
_guiBatcher.DrawString("Voxel Engine v0.1", 15, 70, 20, Vector4.One);
|
||||
|
||||
_guiBatcher.Render();
|
||||
|
||||
GL.Disable(EnableCap.Blend);
|
||||
GL.Enable(EnableCap.DepthTest);
|
||||
GL.Enable(EnableCap.CullFace);
|
||||
}
|
||||
|
||||
private static void RenderWorld()
|
||||
|
||||
Reference in New Issue
Block a user