started on sprite support

This commit is contained in:
maxwes08
2025-12-09 09:49:10 +01:00
parent 35bc49c0f8
commit 2e72dd564e
2 changed files with 46 additions and 2 deletions

View File

@@ -1,4 +1,5 @@
using OpenTK.Graphics.OpenGL4;
using OpenTK.Mathematics;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Voxel
@@ -10,7 +11,6 @@ namespace Voxel
private static bool _buffersDirty;
private static Dictionary<(int, int), int> _chunkBufferSizes = new Dictionary<(int, int), int>();
private static List<ChunkMesh> _chunkMeshes = new List<ChunkMesh>();
private static Shader _shader;
private static readonly Texture _texture;
private static World? _world;
@@ -19,7 +19,7 @@ namespace Voxel
{
string vertexPath = "Shaders/shader.vert";
string fragmentPath = "Shaders/shader.frag";
string texturePath = "atlas.png";
string texturePath = "atlas.png";
_shader = new Shader(vertexPath, fragmentPath);
_texture = new Texture(texturePath);
@@ -53,6 +53,7 @@ namespace Voxel
}
RenderWorld();
RenderUi();
}
private static void UpdateAllChunksBuffer()
@@ -75,6 +76,32 @@ namespace Voxel
}
}
private static void RenderUi()
{
GL.Disable(EnableCap.DepthTest);
GL.Enable(EnableCap.Blend);
GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha);
//_uiShader.Use();
//Matrix4 projection = Matrix4.CreateOrthographicOffCenter(
// 0, screenWidth, screenHeight, 0, -1, 1);
//_uiShader.SetMatrix4("projection", projection);
// Bind UI texture atlas
//_uiTexture.Bind();
// Draw all UI sprites (batch by texture for efficiency)
foreach (var sprite in _uiSprites)
{
sprite.Draw();
}
// Restore 3D settings
GL.Disable(EnableCap.Blend);
GL.Enable(EnableCap.DepthTest);
}
private static void RenderWorld()
{
if (_world == null) return;