Basic rendering with camera controls are functional.
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Numerics;
|
||||
using SlatedGameToolkit.Framework.Exceptions;
|
||||
using SlatedGameToolkit.Framework.Graphics.Programs;
|
||||
using SDL2;
|
||||
using SlatedGameToolkit.Framework.Graphics.Render;
|
||||
using SlatedGameToolkit.Framework.Graphics.Shaders;
|
||||
using SlatedGameToolkit.Framework.Graphics.Render.Programs;
|
||||
using SlatedGameToolkit.Framework.Graphics.Textures;
|
||||
using SlatedGameToolkit.Framework.Graphics.Window;
|
||||
using SlatedGameToolkit.Framework.Input;
|
||||
using SlatedGameToolkit.Framework.Input.Devices;
|
||||
using SlatedGameToolkit.Framework.Loader;
|
||||
using SlatedGameToolkit.Framework.StateSystem;
|
||||
using SlatedGameToolkit.Framework.StateSystem.States;
|
||||
@@ -16,9 +17,8 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
|
||||
public class MainState : IState
|
||||
{
|
||||
private WindowContext window;
|
||||
private GLShaderProgram program;
|
||||
private Camera2D camera;
|
||||
private Renderer renderer;
|
||||
private MeshBatch renderer;
|
||||
private Texture texture;
|
||||
private Sprite2D sprite;
|
||||
|
||||
@@ -36,10 +36,9 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
|
||||
|
||||
public void Deinitialize()
|
||||
{
|
||||
window.Dispose();
|
||||
program.Dispose();
|
||||
texture.Dispose();
|
||||
renderer.Dispose();
|
||||
window.Dispose();
|
||||
}
|
||||
|
||||
public string getName()
|
||||
@@ -50,25 +49,35 @@ namespace SlatedGameToolkit.Tools.Utilities.Playground
|
||||
public void Initialize(StateManager manager)
|
||||
{
|
||||
window = new WindowContext("SlatedGameToolkit Playground");
|
||||
camera = new Camera2D();
|
||||
camera.Width = window.WindowBoundaries.Width;
|
||||
camera.Height = window.WindowBoundaries.Height;
|
||||
camera.Position = new Vector2(camera.Width / 2, camera.Height / 2);
|
||||
program = new GLShaderProgram(new NormalVertexShader(), new NormalFragmentShader());
|
||||
renderer = new Renderer(camera, program);
|
||||
texture = new TextureLoader("Resources/Playground/yhdnbgnc.png").Load();
|
||||
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;
|
||||
}
|
||||
|
||||
public void Render(double delta)
|
||||
{
|
||||
OpenGLErrorException.CheckGLErrorStatus();
|
||||
renderer.Queue(sprite, Matrix4x4.Identity);
|
||||
renderer.Render();
|
||||
renderer.Begin(Matrix4x4.Identity);
|
||||
renderer.Draw(sprite);
|
||||
renderer.End();
|
||||
}
|
||||
|
||||
public void Update(double delta)
|
||||
{
|
||||
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_DOWN)) {
|
||||
camera.Position += new Vector2(0, (float)(-0.5f * delta));
|
||||
}
|
||||
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_UP)) {
|
||||
camera.Position += new Vector2(0, (float)(0.5f * delta));
|
||||
}
|
||||
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_LEFT)) {
|
||||
camera.Position += new Vector2((float)(-0.5f * delta), 0);
|
||||
}
|
||||
if (Keyboard.IsKeyPressed(SDL.SDL_Keycode.SDLK_RIGHT)) {
|
||||
camera.Position += new Vector2((float)(0.5f * delta), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user