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/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/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..4c46d7a 100644 --- a/src/PlatformLayer/Texture.bf +++ b/src/PlatformLayer/Texture.bf @@ -6,14 +6,32 @@ namespace Strawberry public int Width { get; private set; } public int Height { get; private set; } - public this(int width, int height, uint8* pixels) + public this(int width, int height, uint8* pixels, bool indLinear, bool indClamp) { Width = width; Height = height; 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); + } + GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGBA, width, height, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixels); + + GL.glGenerateMipmap(GL.GL_TEXTURE_2D); // Unavailable in OpenGL 2.1. + + // Clear state + GL.glBindTexture(GL.GL_TEXTURE_2D, 0); } public ~this()