mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2024-11-25 16:18:56 +08:00
Setting up open gl stuff
This commit is contained in:
parent
823656d8e5
commit
1bf3c1a62f
|
@ -6,3 +6,7 @@ Name = "SampleGame"
|
|||
TargetType = "BeefGUIApplication"
|
||||
StartupObject = "Strawberry.Sample.Program"
|
||||
DefaultNamespace = "Strawberry.Sample"
|
||||
|
||||
[[Project.DistinctOptions]]
|
||||
Filter = ""
|
||||
ReflectAlwaysInclude = "IncludeAll"
|
||||
|
|
|
@ -3,3 +3,9 @@ Projects = {SampleGame = {Path = "."}, Strawberry = {Path = ".."}, SDL2 = "*"}
|
|||
|
||||
[Workspace]
|
||||
StartupProject = "SampleGame"
|
||||
|
||||
[[Workspace.DistinctOptions]]
|
||||
Filter = ""
|
||||
|
||||
[Configs.Debug.Win64]
|
||||
Toolset = "LLVM"
|
||||
|
|
|
@ -6,8 +6,9 @@ namespace Strawberry.Sample
|
|||
{
|
||||
static public int Main(String[] args)
|
||||
{
|
||||
SDL2PlatformLayer sdl = scope SDL2PlatformLayer();
|
||||
let sdl = scope SDL2PlatformLayer();
|
||||
let game = scope SampleGame(sdl);
|
||||
|
||||
game.Run();
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ namespace Strawberry
|
|||
|
||||
public this(int w, int h)
|
||||
{
|
||||
Texture = SDL.CreateTexture(Game.Renderer, (uint32)SDL.PIXELFORMAT_RGBA8888, (int32)SDL.TextureAccess.Streaming, (int32)w, (int32)h);
|
||||
//Texture = SDL.CreateTexture(Game.Renderer, (uint32)SDL.PIXELFORMAT_RGBA8888, (int32)SDL.TextureAccess.Streaming, (int32)w, (int32)h);
|
||||
Width = w;
|
||||
Height = h;
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace Strawberry
|
|||
: base()
|
||||
{
|
||||
Game = this;
|
||||
PlatformLayer = platformLayer;
|
||||
|
||||
Title = windowTitle;
|
||||
Width = width;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -27,9 +27,9 @@ namespace Strawberry
|
|||
|
||||
static public void Rect(int x, int y, int w, int h, Color color)
|
||||
{
|
||||
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
SDL.RenderFillRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
|
||||
//SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
//SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
//SDL.RenderFillRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
|
||||
}
|
||||
|
||||
static public void Rect(Rect rect, Color color)
|
||||
|
@ -39,9 +39,9 @@ namespace Strawberry
|
|||
|
||||
static public void HollowRect(int x, int y, int w, int h, Color color)
|
||||
{
|
||||
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
SDL.RenderDrawRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
|
||||
//SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
//SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
//SDL.RenderDrawRect(Game.Renderer, &SDL.Rect((int32)(x - Camera.X), (int32)(y - Camera.Y), (int32)w, (int32)h));
|
||||
}
|
||||
|
||||
static public void HollowRect(Rect rect, Color color)
|
||||
|
@ -54,9 +54,9 @@ namespace Strawberry
|
|||
let fromn = (Point)(from - Camera);
|
||||
let ton = (Point)(to - Camera);
|
||||
|
||||
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
SDL.RenderDrawLine(Game.Renderer, (int32)fromn.X, (int32)fromn.Y, (int32)ton.X, (int32)ton.Y);
|
||||
//SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
//SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
//SDL.RenderDrawLine(Game.Renderer, (int32)fromn.X, (int32)fromn.Y, (int32)ton.X, (int32)ton.Y);
|
||||
}
|
||||
|
||||
static public void Circle(Point at, float radius, Color color, int steps = 16)
|
||||
|
@ -76,9 +76,9 @@ namespace Strawberry
|
|||
);
|
||||
}
|
||||
|
||||
SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
SDL.RenderDrawLines(Game.Renderer, &points[0], (int32)steps + 1);
|
||||
//SDL.SetRenderDrawBlendMode(Game.Renderer, .Blend);
|
||||
//SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
//SDL.RenderDrawLines(Game.Renderer, &points[0], (int32)steps + 1);
|
||||
}
|
||||
|
||||
static public void Sprite(Sprite sprite, int frame, Point position)
|
||||
|
@ -86,8 +86,8 @@ namespace Strawberry
|
|||
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
|
||||
SDL.Rect dst = Strawberry.Rect(position.X - Camera.X, position.Y - Camera.Y, sprite.Width, sprite.Height);
|
||||
|
||||
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
SDL.RenderCopy(Game.Renderer, sprite[frame].Texture, &src, &dst);
|
||||
//SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
//SDL.RenderCopy(Game.Renderer, sprite[frame].Texture, &src, &dst);
|
||||
}
|
||||
|
||||
static public void Sprite(Sprite sprite, int frame, Point position, Point origin)
|
||||
|
@ -96,8 +96,8 @@ namespace Strawberry
|
|||
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
|
||||
SDL.Rect dst = Strawberry.Rect(position.X - origin.X - Camera.X, position.Y - origin.Y - Camera.Y, sprite.Width, sprite.Height);
|
||||
|
||||
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, 0, &cnt, .None);
|
||||
//SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
//SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, 0, &cnt, .None);
|
||||
}
|
||||
|
||||
static public void Sprite(Sprite sprite, int frame, Point position, Point origin, float rotation)
|
||||
|
@ -106,8 +106,8 @@ namespace Strawberry
|
|||
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
|
||||
SDL.Rect dst = Strawberry.Rect(position.X - origin.X - Camera.X, position.Y - origin.Y - Camera.Y, sprite.Width, sprite.Height);
|
||||
|
||||
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, rotation, &cnt, .None);
|
||||
//SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
//SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, rotation, &cnt, .None);
|
||||
}
|
||||
|
||||
static public void SpriteCentered(Sprite sprite, int frame, Point position)
|
||||
|
@ -117,8 +117,8 @@ namespace Strawberry
|
|||
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
|
||||
SDL.Rect dst = Strawberry.Rect(position.X - origin.X - Camera.X, position.Y - origin.Y - Camera.Y, sprite.Width, sprite.Height);
|
||||
|
||||
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, 0, &cnt, .None);
|
||||
//SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
//SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, 0, &cnt, .None);
|
||||
}
|
||||
|
||||
static public void SpriteCentered(Sprite sprite, int frame, Point position, Color color)
|
||||
|
@ -131,7 +131,7 @@ namespace Strawberry
|
|||
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
SDL.SetTextureColorMod(sprite[frame].Texture, color.R, color.G, color.B);
|
||||
SDL.SetTextureAlphaMod(sprite[frame].Texture, color.A);
|
||||
SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, 0, &cnt, .None);
|
||||
//SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, 0, &cnt, .None);
|
||||
}
|
||||
|
||||
static public void SpriteCentered(Sprite sprite, int frame, Point position, float rotation)
|
||||
|
@ -142,20 +142,20 @@ namespace Strawberry
|
|||
SDL.Rect dst = Strawberry.Rect(position.X - origin.X - Camera.X, position.Y - origin.Y - Camera.Y, sprite.Width, sprite.Height);
|
||||
|
||||
SDL.SetTextureBlendMode(sprite[frame].Texture, .Blend);
|
||||
SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, rotation, &cnt, .None);
|
||||
//SDL.RenderCopyEx(Game.Renderer, sprite[frame].Texture, &src, &dst, rotation, &cnt, .None);
|
||||
}
|
||||
|
||||
static public void Text(SDL2.SDLTTF.Font* font, String text, Point position, Color color)
|
||||
{
|
||||
SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
//SDL.SetRenderDrawColor(Game.Renderer, color.R, color.G, color.B, color.A);
|
||||
let surface = SDLTTF.RenderUTF8_Solid(font, text, color);
|
||||
let texture = SDL.CreateTextureFromSurface(Game.Renderer, surface);
|
||||
//let texture = SDL.CreateTextureFromSurface(Game.Renderer, surface);
|
||||
|
||||
SDL.Rect srcRect = .(0, 0, surface.w, surface.h);
|
||||
SDL.Rect destRect = .((int32)position.X, (int32)position.Y, surface.w, surface.h);
|
||||
SDL.RenderCopy(Game.Renderer, texture, &srcRect, &destRect);
|
||||
//SDL.RenderCopy(Game.Renderer, texture, &srcRect, &destRect);
|
||||
SDL.FreeSurface(surface);
|
||||
SDL.DestroyTexture(texture);
|
||||
//SDL.DestroyTexture(texture);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user