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.Graphics.OpenGL4;
using OpenTK.Mathematics;
using static System.Runtime.InteropServices.JavaScript.JSType; using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Voxel namespace Voxel
@@ -10,7 +11,6 @@ namespace Voxel
private static bool _buffersDirty; private static bool _buffersDirty;
private static Dictionary<(int, int), int> _chunkBufferSizes = new Dictionary<(int, int), int>(); 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 Shader _shader;
private static readonly Texture _texture; private static readonly Texture _texture;
private static World? _world; private static World? _world;
@@ -19,7 +19,7 @@ namespace Voxel
{ {
string vertexPath = "Shaders/shader.vert"; string vertexPath = "Shaders/shader.vert";
string fragmentPath = "Shaders/shader.frag"; string fragmentPath = "Shaders/shader.frag";
string texturePath = "atlas.png"; string texturePath = "atlas.png";
_shader = new Shader(vertexPath, fragmentPath); _shader = new Shader(vertexPath, fragmentPath);
_texture = new Texture(texturePath); _texture = new Texture(texturePath);
@@ -53,6 +53,7 @@ namespace Voxel
} }
RenderWorld(); RenderWorld();
RenderUi();
} }
private static void UpdateAllChunksBuffer() 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() private static void RenderWorld()
{ {
if (_world == null) return; if (_world == null) return;

17
UISprite.cs Normal file
View File

@@ -0,0 +1,17 @@
using OpenTK.Mathematics;
using System.Drawing;
public class UISprite
{
public Vector2 Position; // Screen pixels (not normalized)
public Vector2 Size; // Size in pixels
public Rectangle TextureRegion; // Which part of atlas to use
public Color Tint = Color.White;
public float Rotation = 0f;
public Vector2 Origin = Vector2.Zero; // Rotation/scale origin
public void Draw()
{
// Draw textured quad using TextureRegion coordinates
}
}