From e781aea77621d66db9f0d69df5417eed71301218 Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 23 Jun 2020 23:53:24 -0500 Subject: [PATCH] MeshBatch now renders with or without textures. General structure clean up as well. --- src/SlatedGameToolkit.Framework/GameEngine.cs | 36 ++-------- .../Graphics/Render/Camera.cs | 7 ++ .../{Meshes/IMeshable.cs => Render/IMesh.cs} | 6 +- .../Graphics/Render/ITexture.cs | 8 +++ .../Graphics/Render/MeshBatch.cs | 65 ++++++++++--------- .../{Meshes => Render}/RectangleMesh.cs | 27 ++++++-- .../Graphics/Render/Sprite2D.cs | 28 -------- .../Graphics/Textures/Texture.cs | 5 +- .../Loader/AssetManager.cs | 2 +- .../Loader/CommonLoaders.cs | 2 +- .../Resources/default.frag | 8 ++- .../StateSystem/StateManager.cs | 2 +- .../StateSystem/States/IState.cs | 2 +- .../Utilities/Playground/MainState.cs | 36 +++++++--- 14 files changed, 122 insertions(+), 112 deletions(-) rename src/SlatedGameToolkit.Framework/Graphics/{Meshes/IMeshable.cs => Render/IMesh.cs} (88%) create mode 100644 src/SlatedGameToolkit.Framework/Graphics/Render/ITexture.cs rename src/SlatedGameToolkit.Framework/Graphics/{Meshes => Render}/RectangleMesh.cs (78%) delete mode 100644 src/SlatedGameToolkit.Framework/Graphics/Render/Sprite2D.cs diff --git a/src/SlatedGameToolkit.Framework/GameEngine.cs b/src/SlatedGameToolkit.Framework/GameEngine.cs index 6d60214..b0dd139 100644 --- a/src/SlatedGameToolkit.Framework/GameEngine.cs +++ b/src/SlatedGameToolkit.Framework/GameEngine.cs @@ -7,7 +7,6 @@ using Serilog.Core; using SlatedGameToolkit.Framework.Exceptions; using SlatedGameToolkit.Framework.Graphics.Textures; using SlatedGameToolkit.Framework.Graphics.Window; -using SlatedGameToolkit.Framework.Input; using SlatedGameToolkit.Framework.Input.Devices; using SlatedGameToolkit.Framework.StateSystem; using SlatedGameToolkit.Framework.StateSystem.States; @@ -19,7 +18,6 @@ namespace SlatedGameToolkit.Framework { /// public static class GameEngine { private const int GL_MAJOR_VER = 3, GL_MINOR_VER = 3; - public static TextureData FillerTextureData {get; private set;} public static bool Debugging { get; set; } public static Logger Logger { get; private set; } private static readonly object ignitionLock = new object(); @@ -33,8 +31,8 @@ namespace SlatedGameToolkit.Framework { /// The amount of updates per second. /// /// If greater than 0, game loop updates will be fixed (time steps). - /// More specifically, it will figure out how many updates to perform per frame to allow for physics steps - /// to be calculated based on a constant time step. + /// More specifically, the amount of updates performed per frame to allow for physics calculations + /// to be calculated based on a constant time step will be calculated automatically. /// /// If set to 0 or less, updates will be as fast as possible. /// @@ -164,7 +162,7 @@ namespace SlatedGameToolkit.Framework { timePassedFromLastUpdate += difference; while (timePassedFromLastUpdate > updateDeltaTime) { //Updates. - manager.update(updateDeltaTime.TotalMilliseconds <= 0 ? timePassedFromLastUpdate.TotalSeconds : updateDeltaTime.TotalSeconds); + manager.update(updateDeltaTime.TotalSeconds <= 0 ? timePassedFromLastUpdate.TotalSeconds : updateDeltaTime.TotalSeconds); timePassedFromLastUpdate -= updateDeltaTime; if (updateDeltaTime.TotalSeconds <= 0) break; } @@ -172,7 +170,7 @@ namespace SlatedGameToolkit.Framework { timePassedFromLastRender += difference; if (timePassedFromLastRender > frameDeltaTime) { //Draw calls. - manager.render(timePassedFromLastUpdate.TotalSeconds); + manager.render(updateDeltaTime.TotalSeconds <= 0 ? updateDeltaTime.TotalSeconds : (timePassedFromLastUpdate / updateDeltaTime)); timePassedFromLastRender = TimeSpan.Zero; } } @@ -242,8 +240,6 @@ namespace SlatedGameToolkit.Framework { SDL.SDL_GL_SetAttribute(SDL.SDL_GLattr.SDL_GL_CONTEXT_PROFILE_MASK, SDL.SDL_GLprofile.SDL_GL_CONTEXT_PROFILE_CORE) < 0) throw new FrameworkSDLException(string.Format("Unable to load correct OpenGL version {0}.{1}.0 Core.", GL_MINOR_VER, GL_MAJOR_VER)); - LoadEngineAssets(); - thread = new Thread(Loop); thread.Name = "SGTK-Engine"; thread.Priority = ThreadPriority.AboveNormal; @@ -252,30 +248,6 @@ namespace SlatedGameToolkit.Framework { } } - private unsafe static void LoadEngineAssets() { - byte[] buffer = EmbeddedResourceUtils.ReadEmbeddedResourceData("filler.png"); - fixed (void* ptr = &buffer[0]) { - IntPtr rwOps = SDL.SDL_RWFromConstMem(new IntPtr(ptr), buffer.Length * sizeof(byte)); - IntPtr surfacePtr = SDL_image.IMG_Load_RW(rwOps, 1); - SDL.SDL_Surface surface = Marshal.PtrToStructure(surfacePtr); - - SDL.SDL_PixelFormat pixelFormat = Marshal.PtrToStructure(surface.format); - if (pixelFormat.format != SDL.SDL_PIXELFORMAT_RGBA8888) { - IntPtr convertedPtr = SDL.SDL_ConvertSurfaceFormat(surfacePtr, SDL.SDL_PIXELFORMAT_RGBA8888, 0); - if (convertedPtr == null) throw new OptionalSDLException(); - SDL.SDL_FreeSurface(surfacePtr); - surfacePtr = convertedPtr; - surface = Marshal.PtrToStructure(surfacePtr); - } - byte[] data = new byte[surface.pitch * surface.h]; - - Marshal.Copy(surface.pixels, data, 0, data.Length); - FillerTextureData = new TextureData(surface.w, surface.h, data); - - SDL.SDL_FreeSurface(surfacePtr); - } - } - public static bool IsRunning() { return !stopped; } diff --git a/src/SlatedGameToolkit.Framework/Graphics/Render/Camera.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/Camera.cs index 016418d..aae59f1 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Render/Camera.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/Camera.cs @@ -12,6 +12,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Render private float width, height; private Matrix4x4 lookAtMatrix = Matrix4x4.Identity; private Matrix4x4 view = Matrix4x4.Identity, projection; + + public event EventHandler projectionUpdateEvent; + public bool Orthographic { get { return orthographic; @@ -125,5 +128,9 @@ namespace SlatedGameToolkit.Framework.Graphics.Render this.Position = new Vector3(0, 0, 3); this.CameraFront = -Vector3.UnitZ; } + + private void OnProjectionUpdated() { + projectionUpdateEvent?.Invoke(this, new EventArgs()); + } } } \ No newline at end of file diff --git a/src/SlatedGameToolkit.Framework/Graphics/Meshes/IMeshable.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/IMesh.cs similarity index 88% rename from src/SlatedGameToolkit.Framework/Graphics/Meshes/IMeshable.cs rename to src/SlatedGameToolkit.Framework/Graphics/Render/IMesh.cs index 2e36811..2e2c51b 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Meshes/IMeshable.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/IMesh.cs @@ -4,9 +4,9 @@ using System.Drawing; using System.Numerics; using SlatedGameToolkit.Framework.Graphics.Textures; -namespace SlatedGameToolkit.Framework.Graphics.Meshes +namespace SlatedGameToolkit.Framework.Graphics.Render { - public interface IMeshable + public interface IMesh { /// @@ -25,7 +25,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes /// The texture for this mesh. /// /// Texture for this mesh. - Texture Texture { get; } + ITexture Texture { get; } /// /// The blended color of this mesh. diff --git a/src/SlatedGameToolkit.Framework/Graphics/Render/ITexture.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/ITexture.cs new file mode 100644 index 0000000..d62f2b3 --- /dev/null +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/ITexture.cs @@ -0,0 +1,8 @@ +namespace SlatedGameToolkit.Framework.Graphics.Render +{ + public interface ITexture + { + uint Handle {get;} + void Use(); + } +} \ No newline at end of file diff --git a/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs index 43951c6..2541d6f 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/MeshBatch.cs @@ -1,7 +1,6 @@ using System; using System.Drawing; using System.Numerics; -using SlatedGameToolkit.Framework.Graphics.Meshes; using SlatedGameToolkit.Framework.Graphics.OpenGL; using SlatedGameToolkit.Framework.Graphics.Render.Programs; using SlatedGameToolkit.Framework.Graphics.Render.Shaders; @@ -14,11 +13,10 @@ namespace SlatedGameToolkit.Framework.Graphics.Render public class MeshBatch : IDisposable { public GLContext GLContext {get; private set; } private const int VERTEX_LENGTH = 9; - private int projLoc, viewLoc, modelLoc; + private int projALoc, viewALoc, modelALoc, texturedALoc; private Camera camera; private RenderProgram renderProgram; - private Texture texture; - private Texture fillerTexture; + private ITexture texture; private bool disposed; private VertexArrayBuffers vertexBuffers; public bool Batching { get; private set; } @@ -39,7 +37,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Render } this.renderProgram = renderProgram; this.GLContext = renderProgram.GLContext; - this.camera = camera; + this.camera = camera ?? throw new ArgumentNullException("camera"); indices = new uint[BatchVertexSize]; lengths = new int[BatchVertexSize]; indiceOffsets = new int[BatchVertexSize]; @@ -51,12 +49,14 @@ namespace SlatedGameToolkit.Framework.Graphics.Render definitions[1] = new VertexAttributeDefinition((uint)GLContext.GetAttribLocation(renderProgram.Handle, "aColor"), 4); definitions[2] = new VertexAttributeDefinition((uint)GLContext.GetAttribLocation(renderProgram.Handle, "aTexCoord"), 2); renderProgram.Use(); - modelLoc = GLContext.GetUniformLocation(renderProgram.Handle, "models"); - viewLoc = GLContext.GetUniformLocation(renderProgram.Handle, "view"); - projLoc = GLContext.GetUniformLocation(renderProgram.Handle, "projection"); + modelALoc = GLContext.GetUniformLocation(renderProgram.Handle, "models"); + viewALoc = GLContext.GetUniformLocation(renderProgram.Handle, "view"); + projALoc = GLContext.GetUniformLocation(renderProgram.Handle, "projection"); + texturedALoc = GLContext.GetUniformLocation(renderProgram.Handle, "textured"); vertexBuffers.defineVertexAttributes(definitions: definitions); - fillerTexture = new Texture(GameEngine.FillerTextureData); + camera.projectionUpdateEvent += ProjectionMatrixChanged; + GLContext.UniformMatrix4fv(projALoc, 1, false, camera.ProjectionMatrix.ToColumnMajorArray()); } public virtual void Begin(Matrix4x4 modelsMatrix) { @@ -65,15 +65,18 @@ namespace SlatedGameToolkit.Framework.Graphics.Render this.modelsMatrix = modelsMatrix; } - public virtual void Draw(IMeshable meshable) { - if (meshable.Texture != this.texture) { - if (this.texture != null) { - Flush(); - } - this.texture = meshable.Texture ?? fillerTexture; + /// + /// Draws the given mesh. + /// + /// Draws the given mesh. + public virtual void Draw(IMesh mesh) { + if (mesh.Texture?.Handle != this.texture?.Handle) { + Flush(); + this.texture = mesh.Texture; + GLContext.Uniform1i(texturedALoc, texture == null ? 0 : 1); } - ValueTuple[] vertices = meshable.Vertices; - uint[] indices = meshable.Elements; + ValueTuple[] vertices = mesh.Vertices; + uint[] indices = mesh.Elements; if (vertices.Length * VERTEX_LENGTH + dataIndex >= data.Length || indices.Length + indicesIndex >= this.indices.Length) Flush(); for (int i = 0; i < vertices.Length; i++) { @@ -84,13 +87,13 @@ namespace SlatedGameToolkit.Framework.Graphics.Render data[dataIndex] = vertices[i].Item1.Z; dataIndex++; - data[dataIndex] = meshable.Color.RedAsFloat(); + data[dataIndex] = mesh.Color.RedAsFloat(); dataIndex++; - data[dataIndex] = meshable.Color.GreenAsFloat(); + data[dataIndex] = mesh.Color.GreenAsFloat(); dataIndex++; - data[dataIndex] = meshable.Color.BlueAsFloat(); + data[dataIndex] = mesh.Color.BlueAsFloat(); dataIndex++; - data[dataIndex] = meshable.Color.AlphaAsFloat(); + data[dataIndex] = mesh.Color.AlphaAsFloat(); dataIndex++; data[dataIndex] = vertices[i].Item2.X; @@ -116,22 +119,22 @@ namespace SlatedGameToolkit.Framework.Graphics.Render } protected virtual void Flush() { - texture.Use(); + texture?.Use(); renderProgram.Use(); vertexBuffers.BufferVertices(data, true); vertexBuffers.BufferIndices(indices, true); - GLContext.UniformMatrix4fv(modelLoc, 1, false, modelsMatrix.ToColumnMajorArray()); - GLContext.UniformMatrix4fv(viewLoc, 1, false, camera.ViewMatrix.ToColumnMajorArray()); - GLContext.UniformMatrix4fv(projLoc, 1, false, camera.ProjectionMatrix.ToColumnMajorArray()); - // GLContext.UniformMatrix4fv(modelLoc, 1, false, Matrix4x4.Identity.ToColumnMajorArray()); - // GLContext.UniformMatrix4fv(viewLoc, 1, false, Matrix4x4.Identity.ToColumnMajorArray()); - // GLContext.UniformMatrix4fv(projLoc, 1, false, Matrix4x4.Identity.ToColumnMajorArray()); + GLContext.UniformMatrix4fv(modelALoc, 1, false, modelsMatrix.ToColumnMajorArray()); + GLContext.UniformMatrix4fv(viewALoc, 1, false, camera.ViewMatrix.ToColumnMajorArray()); GLContext.MultiDrawElementsBaseVertex(PrimitiveType.Triangles, lengths, DrawElementsType.UnsignedInt, indiceOffsets, offsetIndex, verticeOffsets); dataIndex = 0; indicesIndex = 0; offsetIndex = 0; } + private void ProjectionMatrixChanged(object sender, EventArgs args) { + GLContext.UniformMatrix4fv(projALoc, 1, false, camera.ProjectionMatrix.ToColumnMajorArray()); + } + protected virtual void Dispose(bool disposing) { if (!disposed) @@ -144,22 +147,22 @@ namespace SlatedGameToolkit.Framework.Graphics.Render disposed = true; vertexBuffers.Dispose(); renderProgram.Dispose(); - fillerTexture.Dispose(); data = null; indices = null; lengths = null; verticeOffsets = null; + camera.projectionUpdateEvent -= ProjectionMatrixChanged; } } ~MeshBatch() { - Dispose(disposing: false); + Dispose(false); } public void Dispose() { - Dispose(disposing: true); + Dispose(true); GC.SuppressFinalize(this); } } diff --git a/src/SlatedGameToolkit.Framework/Graphics/Meshes/RectangleMesh.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/RectangleMesh.cs similarity index 78% rename from src/SlatedGameToolkit.Framework/Graphics/Meshes/RectangleMesh.cs rename to src/SlatedGameToolkit.Framework/Graphics/Render/RectangleMesh.cs index 23385f9..3e9d767 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Meshes/RectangleMesh.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Render/RectangleMesh.cs @@ -3,9 +3,9 @@ using System.Drawing; using System.Numerics; using SlatedGameToolkit.Framework.Graphics.Textures; -namespace SlatedGameToolkit.Framework.Graphics.Meshes +namespace SlatedGameToolkit.Framework.Graphics.Render { - public class RectangleMesh : IMeshable + public class RectangleMesh : IMesh { private Matrix4x4 matRot = Matrix4x4.Identity; private bool changed; @@ -95,10 +95,29 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes } } - public Texture Texture { get; set; } + public ITexture Texture { get; set; } public Color Color { get; set; } + public RectangleMesh(ITexture texture, Color color) + { + this.Texture = texture; + this.Color = color; + + this.textureCoords[0].X = 0; + this.textureCoords[0].Y = 1; + + this.textureCoords[1].X = 1; + this.textureCoords[1].Y = 1; + + this.textureCoords[2].X = 1; + this.textureCoords[2].Y = 0; + + this.textureCoords[3].X = 0; + this.textureCoords[3].Y = 0; + } + + private void CalculateVertices() { if (!changed) return; Vector3[] baseVerts = new Vector3[4]; @@ -109,7 +128,7 @@ namespace SlatedGameToolkit.Framework.Graphics.Meshes for (int i = 0; i < vertices.Length; i++) { - vertices[i] = new ValueTuple(Vector3.Transform(baseVerts[i], matRot), textureCoords[i]); + vertices[i] = (Vector3.Transform(baseVerts[i], matRot), textureCoords[i]); } changed = false; } diff --git a/src/SlatedGameToolkit.Framework/Graphics/Render/Sprite2D.cs b/src/SlatedGameToolkit.Framework/Graphics/Render/Sprite2D.cs deleted file mode 100644 index 1625018..0000000 --- a/src/SlatedGameToolkit.Framework/Graphics/Render/Sprite2D.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Drawing; -using SlatedGameToolkit.Framework.Graphics.Meshes; -using SlatedGameToolkit.Framework.Graphics.Textures; - -namespace SlatedGameToolkit.Framework.Graphics.Render -{ - public class Sprite2D : RectangleMesh - { - public Sprite2D(Texture texture, Color color) { - this.Texture = texture; - this.textureCoords[0].X = 0; - this.textureCoords[0].Y = 1; - - this.textureCoords[1].X = 1; - this.textureCoords[1].Y = 1; - - this.textureCoords[2].X = 1; - this.textureCoords[2].Y = 0; - - this.textureCoords[3].X = 0; - this.textureCoords[3].Y = 0; - - this.Color = color; - this.Width = 1f; - this.Height = 1f; - } - } -} \ No newline at end of file diff --git a/src/SlatedGameToolkit.Framework/Graphics/Textures/Texture.cs b/src/SlatedGameToolkit.Framework/Graphics/Textures/Texture.cs index e3f5f1d..72c77a8 100644 --- a/src/SlatedGameToolkit.Framework/Graphics/Textures/Texture.cs +++ b/src/SlatedGameToolkit.Framework/Graphics/Textures/Texture.cs @@ -1,16 +1,19 @@ using System; using SlatedGameToolkit.Framework.Graphics.OpenGL; +using SlatedGameToolkit.Framework.Graphics.Render; using SlatedGameToolkit.Framework.Graphics.Window; using SlatedGameToolkit.Framework.Loader; namespace SlatedGameToolkit.Framework.Graphics.Textures { - public class Texture : IAssetUseable { + public class Texture : IAssetUseable, ITexture { public readonly int width, height; private bool disposed; private GLContext glContext; private uint handle; + public uint Handle {get { return handle; }} + /// /// Creates an OpenGL Texture2D in the given GL Context. /// diff --git a/src/SlatedGameToolkit.Framework/Loader/AssetManager.cs b/src/SlatedGameToolkit.Framework/Loader/AssetManager.cs index 786b324..6c2be15 100644 --- a/src/SlatedGameToolkit.Framework/Loader/AssetManager.cs +++ b/src/SlatedGameToolkit.Framework/Loader/AssetManager.cs @@ -18,7 +18,7 @@ namespace SlatedGameToolkit.Framework.Loader { /// A delegate that performs the loading of the specific asset. /// /// The path of the asset. - /// The context to be used. May be null if called by user. + /// The context to be used. /// The type of the resulting asset. /// A loaded, useable asset. public delegate T LoadAsset(string path, GLContext glContext) where T : IAssetUseable; diff --git a/src/SlatedGameToolkit.Framework/Loader/CommonLoaders.cs b/src/SlatedGameToolkit.Framework/Loader/CommonLoaders.cs index 1ecdb0a..9702526 100644 --- a/src/SlatedGameToolkit.Framework/Loader/CommonLoaders.cs +++ b/src/SlatedGameToolkit.Framework/Loader/CommonLoaders.cs @@ -16,7 +16,7 @@ namespace SlatedGameToolkit.Framework.Loader /// Therefore, technically, this function should be able to laod any format SDL2 Image can load. /// /// The path of the texture to load. - /// The OpenGL context the texture is to be associated with. + /// The OpenGL context the texture is to be associated with. May be null. /// An OpenGL Texture associated with the given context. public static Texture LoadTexture(string path, GLContext glContext) { diff --git a/src/SlatedGameToolkit.Framework/Resources/default.frag b/src/SlatedGameToolkit.Framework/Resources/default.frag index 4ac67a2..da9e2f1 100644 --- a/src/SlatedGameToolkit.Framework/Resources/default.frag +++ b/src/SlatedGameToolkit.Framework/Resources/default.frag @@ -3,9 +3,15 @@ out vec4 outputColor; in vec2 texCoord; in vec4 color; + +uniform bool textured; uniform sampler2D texture0; void main() { - outputColor = texture(texture0, texCoord) * color; + if (textured) { + outputColor = texture(texture0, texCoord) * color; + } else { + outputColor = color; + } } \ No newline at end of file diff --git a/src/SlatedGameToolkit.Framework/StateSystem/StateManager.cs b/src/SlatedGameToolkit.Framework/StateSystem/StateManager.cs index f5ace6e..cd4605e 100644 --- a/src/SlatedGameToolkit.Framework/StateSystem/StateManager.cs +++ b/src/SlatedGameToolkit.Framework/StateSystem/StateManager.cs @@ -46,7 +46,7 @@ namespace SlatedGameToolkit.Framework.StateSystem } currentState.Update(delta); } - + internal void render(double delta) { WindowContext windowContext = WindowContextsManager.CurrentWindowContext; windowContext.Context.ClearColor(backgroundColour.RedAsFloat(), backgroundColour.GreenAsFloat(), backgroundColour.BlueAsFloat(), 1f); diff --git a/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs b/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs index 0727d37..15719d4 100644 --- a/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs +++ b/src/SlatedGameToolkit.Framework/StateSystem/States/IState.cs @@ -36,7 +36,7 @@ namespace SlatedGameToolkit.Framework.StateSystem.States /// Called in intervals dependent on game loop chose for every render cycle. /// Only called on if this state is the active state, indicated on the last status method called on this implementation (acitvate, and deactivate). /// - /// The time in seconds that has passed since the last update cycle. + /// If in time-step mode, normalized value representing the time until the next update. Otherwise, the time passed since the last update. void Render(double delta); /// diff --git a/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs b/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs index 48d8922..5fcd573 100644 --- a/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs +++ b/src/SlatedGameToolkit.Tools/Utilities/Playground/MainState.cs @@ -2,6 +2,7 @@ using System; using System.Drawing; using System.Numerics; using SDL2; +using SlatedGameToolkit.Framework; using SlatedGameToolkit.Framework.Graphics.Render; using SlatedGameToolkit.Framework.Graphics.Render.Programs; using SlatedGameToolkit.Framework.Graphics.Textures; @@ -19,8 +20,8 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground private WindowContext window; private Camera2D camera; private MeshBatch renderer; - private Texture texture; - private Sprite2D sprite; + private Texture logoTexture, fillerTexture; + private RectangleMesh logo, textureTester, untextured; public WindowContext CurrentWindow { get { return window;}} @@ -36,7 +37,8 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground public void Deinitialize() { - texture.Dispose(); + logoTexture.Dispose(); + fillerTexture.Dispose(); renderer.Dispose(); window.Dispose(); } @@ -51,16 +53,34 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground window = new WindowContext("SlatedGameToolkit Playground"); camera = new Camera2D(2, 2); renderer = new MeshBatch(camera); - texture = CommonLoaders.LoadTexture("Resources/Playground/yhdnbgnc.png", null); - sprite = new Sprite2D(texture, Color.White); - sprite.X = -0.5f; - sprite.Y = -0.5f; + + logoTexture = CommonLoaders.LoadTexture("Resources/Playground/yhdnbgnc.png", null); + logo = new RectangleMesh(logoTexture, Color.White); + logo.Width = 0.5f; + logo.Height = 0.5f; + logo.X = -0.25f; + logo.Y = -0.25f; + + + fillerTexture = CommonLoaders.LoadTexture("Resources/Playground/filler.png", null); + textureTester = new RectangleMesh(fillerTexture, Color.White); + textureTester.Width = 0.15f; + textureTester.Height = 0.15f; + textureTester.X = 0.25f; + + untextured = new RectangleMesh(null, Color.Red); + untextured.Width = 0.15f; + untextured.Height = 0.1f; + untextured.X = 0.25f; + untextured.Y = - 0.15f; } public void Render(double delta) { renderer.Begin(Matrix4x4.Identity); - renderer.Draw(sprite); + renderer.Draw(logo); + renderer.Draw(textureTester); + renderer.Draw(untextured); renderer.End(); }