Setting up open gl stuff

This commit is contained in:
Matt Thorson
2020-08-03 22:02:05 -07:00
parent 823656d8e5
commit 1bf3c1a62f
8 changed files with 73 additions and 48 deletions

View File

@ -4,20 +4,19 @@ namespace Strawberry
public abstract class PlatformLayer
{
public abstract void Init();
public abstract uint32 Tick(); // Returns milliseconds since last tick
public abstract bool Closed(); // If the game window has been closed
//Rendering
public abstract void RenderBegin();
public abstract void RenderEnd();
public abstract void UpdateInput();
//Input
public abstract void UpdateInput();
public abstract bool PollKey(Keys key);
public abstract bool CapsLock { get; }
public abstract bool NumLock { get; }
public abstract bool PollGamepadButton(int gamepadID, Buttons button);
public abstract float PollGamepadAxis(int gamepadID, Axes axis);
// Returns milliseconds since last tick
public abstract uint32 Tick();
// If the game window has been closed
public abstract bool Closed();
}
}

View File

@ -6,10 +6,11 @@ namespace Strawberry
{
public class SDL2PlatformLayer : PlatformLayer
{
private SDL.Rect screenRect;
private SDL.Window* window;
private SDL.Surface* screen;
private SDL.Rect screenRect;
private SDL.Renderer* renderer;
private SDL.SDL_GLContext glContext;
private SDL.SDL_GameController*[] gamepads;
private bool* keyboard;
@ -35,19 +36,32 @@ namespace Strawberry
SDL.EventState(.JoyButtonUp, .Disable);
SDL.EventState(.JoyDeviceAdded, .Disable);
SDL.EventState(.JoyDeviceRemoved, .Disable);
window = SDL.CreateWindow(Game.Title, .Centered, .Centered, screenRect.w, screenRect.h, .Shown);
screenRect = SDL.Rect(0, 0, (int32)(Game.Width * Game.WindowScale), (int32)(Game.Height * Game.WindowScale));
renderer = SDL.CreateRenderer(window, -1, .Accelerated);
screen = SDL.GetWindowSurface(window);
SDLImage.Init(.PNG | .JPG);
SDLMixer.OpenAudio(44100, SDLMixer.MIX_DEFAULT_FORMAT, 2, 4096);
SDLTTF.Init();
keyboard = SDL.GetKeyboardState(null);
gamepads = new SDL.SDL_GameController*[Game.GamepadLimit];
for (let i < gamepads.Count)
gamepads[i] = SDL.GameControllerOpen((int32)i);
//Graphics
{
window = SDL.CreateWindow(Game.Title, .Centered, .Centered, screenRect.w, screenRect.h, .Shown);
screenRect = SDL.Rect(0, 0, (int32)(Game.Width * Game.WindowScale), (int32)(Game.Height * Game.WindowScale));
renderer = SDL.CreateRenderer(window, -1, .Accelerated);
screen = SDL.GetWindowSurface(window);
SDLImage.Init(.PNG | .JPG);
SDLTTF.Init();
glContext = SDL.GL_CreateContext(window);
SDL.GL_SetSwapInterval(1);
}
//Audio
{
SDLMixer.OpenAudio(44100, SDLMixer.MIX_DEFAULT_FORMAT, 2, 4096);
}
//Input
{
keyboard = SDL.GetKeyboardState(null);
gamepads = new SDL.SDL_GameController*[Game.GamepadLimit];
for (let i < gamepads.Count)
gamepads[i] = SDL.GameControllerOpen((int32)i);
}
}
public ~this()