diff --git a/SampleGame/src/Player.bf b/SampleGame/src/Player.bf index 99342ad..63ea746 100644 --- a/SampleGame/src/Player.bf +++ b/SampleGame/src/Player.bf @@ -12,7 +12,7 @@ namespace Strawberry.Sample public this(Point pos) : base(pos) { - Hitbox = Rect(-4, -8, 8, 8); + Hitbox = Rect(-4, -8, 16, 16); Add(tJumpGrace = new Timer()); Add(tVarJump = new Timer()); @@ -102,8 +102,8 @@ namespace Strawberry.Sample { base.Draw(); - DrawHitbox(.Green); - //Game.Batcher.Tex(Assets.Textures["test"], X - 4, Y - 8); + DrawHitboxOutline(.Green); + Game.Batcher.Tex(Assets.Textures["test"], X - 4, Y - 8); } } } diff --git a/SampleGame/src/Program.bf b/SampleGame/src/Program.bf index 1f7c2c3..7e68b51 100644 --- a/SampleGame/src/Program.bf +++ b/SampleGame/src/Program.bf @@ -8,6 +8,7 @@ namespace Strawberry.Sample static public int Main(String[] args) { let sdl = scope SDL2PlatformLayer(); + sdl.TexturesEnableEdgeClamping = true; let game = scope SampleGame(sdl); game.Run(); diff --git a/src/Assets/Sprite.bf b/src/Assets/Sprite.bf index e2b61b0..a6bd6e9 100644 --- a/src/Assets/Sprite.bf +++ b/src/Assets/Sprite.bf @@ -560,7 +560,7 @@ namespace Strawberry delete BlendModes; } - private static readonly Blend[] BlendModes = new Blend[] + private static readonly Blend[] BlendModes = new Blend[]( { // 0 - NORMAL new (dest, index, src, opacity) => @@ -596,7 +596,7 @@ namespace Strawberry dest[index + 3] = a; } } - }; + }); [Inline] private static int MUL_UN8(int a, int b) diff --git a/src/Core/Entity.bf b/src/Core/Entity.bf index 8182e46..7a3173a 100644 --- a/src/Core/Entity.bf +++ b/src/Core/Entity.bf @@ -238,6 +238,20 @@ namespace Strawberry } } + public Rect SceneHitboxOutline + { + [Inline] + get + { + Rect hb = Hitbox + Position; + hb.X -= 1; + hb.Y -= 1; + hb.Width += 2; + hb.Height += 2; + return hb; + } + } + public int Left { [Inline] @@ -463,6 +477,11 @@ namespace Strawberry Game.Batcher.Rect(SceneHitbox, color); } + public void DrawHitboxOutline(Color color) + { + Game.Batcher.Rect(SceneHitboxOutline, color); + } + public T SceneAs() where T : Scene { Runtime.Assert(Scene is T, "Scene type mismatch!"); diff --git a/src/PlatformLayer/Batcher.bf b/src/PlatformLayer/Batcher.bf index f40876e..290b6c9 100644 --- a/src/PlatformLayer/Batcher.bf +++ b/src/PlatformLayer/Batcher.bf @@ -69,10 +69,10 @@ namespace Strawberry public void Tex(Texture texture, float x, float y) { PushQuad(.TextureTint, texture, - .Tex(.(x, y), .(0, 1), Color.White), - .Tex(.(x + texture.Width, y), .(1, 1), Color.White), - .Tex(.(x + texture.Width, y + texture.Height), .(1, 0), Color.White), - .Tex(.(x, y + texture.Height), .(0, 0), Color.White)); + .Tex(.(x, y), .(0, 0), Color.White), + .Tex(.(x + texture.Width, y), .(1, 0), Color.White), + .Tex(.(x + texture.Width, y + texture.Height), .(1, 1), Color.White), + .Tex(.(x, y + texture.Height), .(0, 1), Color.White)); } } } diff --git a/src/PlatformLayer/GL.bf b/src/PlatformLayer/GL.bf index 66b1afc..5fecf20 100644 --- a/src/PlatformLayer/GL.bf +++ b/src/PlatformLayer/GL.bf @@ -221,6 +221,7 @@ namespace Strawberry public const uint GL_TEXTURE_DEPTH = 0x8071; public const uint GL_TEXTURE_WRAP_R = 0x8072; public const uint GL_MAX_3D_TEXTURE_SIZE = 0x8073; + public const uint GL_GENERATE_MIPMAP = 0x8191; public const uint GL_UNSIGNED_BYTE_2_3_3_REV = 0x8362; public const uint GL_UNSIGNED_SHORT_5_6_5 = 0x8363; public const uint GL_UNSIGNED_SHORT_5_6_5_REV = 0x8364; diff --git a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf index e88f05d..12e1c52 100644 --- a/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf +++ b/src/PlatformLayer/SDL2/SDL2PlatformLayer.bf @@ -8,6 +8,8 @@ namespace Strawberry.SDL2 { public int TransformMatrixLocation { get; private set; } public int TextureMatrixLocation { get; private set; } + public bool TexturesEnableLinearFilter = false; + public bool TexturesEnableEdgeClamping = false; private SDL.Window* window; private SDL.Surface* screen; @@ -174,7 +176,7 @@ namespace Strawberry.SDL2 Debug.Assert(surface != null, "Could not load from path."); Debug.Assert(surface.format.bytesPerPixel == 4, "Surface format incorrect."); - var tex = new Texture(surface.w, surface.h, (uint8*)surface.pixels); + var tex = new Texture(surface.w, surface.h, (uint8*)surface.pixels, TexturesEnableLinearFilter, TexturesEnableEdgeClamping); SDL.FreeSurface(surface); return tex; diff --git a/src/PlatformLayer/Texture.bf b/src/PlatformLayer/Texture.bf index 2906675..fcc4ff5 100644 --- a/src/PlatformLayer/Texture.bf +++ b/src/PlatformLayer/Texture.bf @@ -6,14 +6,41 @@ namespace Strawberry public int Width { get; private set; } public int Height { get; private set; } - public this(int width, int height, uint8* pixels) + private static int32 OGLMajorV = -1; + + public this(int width, int height, uint8* pixels, bool indLinear, bool indClamp) { Width = width; Height = height; + if (OGLMajorV == -1) + GL.glGetIntegerv(GL.GL_MAJOR_VERSION, &OGLMajorV); + GL.glGenTextures(1, &Handle); GL.glBindTexture(GL.GL_TEXTURE_2D, Handle); + + // (OPTIONAL) Set linear Mipmaps + if (indLinear) { + GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR); + GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_LINEAR); + } + + // (OPTIONAL) Apply edge clamping + if (indClamp) { + GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE); + GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE); + } + + if (OGLMajorV < 3) // OpenGL > 1.4 && < 3.0 + GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_GENERATE_MIPMAP, GL.GL_TRUE); + GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels); + + if (OGLMajorV >= 3) // OpenGL >= 3.0 + GL.glGenerateMipmap(GL.GL_TEXTURE_2D); + + // Clear state + GL.glBindTexture(GL.GL_TEXTURE_2D, 0); } public ~this() diff --git a/src/Static/Console.bf b/src/Static/Console.bf index 70a888e..08fb0ef 100644 --- a/src/Static/Console.bf +++ b/src/Static/Console.bf @@ -229,7 +229,7 @@ namespace Strawberry { let name = scope String(); type.GetName(name); - let error = Calc.StringArgs("{0} type arguments not supported in commands.", scope Object[] { name }); + let error = Calc.StringArgs("{0} type arguments not supported in commands.", scope Object[]({ name })); Runtime.FatalError(error); }