started on sprite support
This commit is contained in:
29
Renderer.cs
29
Renderer.cs
@@ -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;
|
||||||
@@ -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
17
UISprite.cs
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user