Fix texures

* Add missing Mipmap generation call
* Add missing state clearing
* Add optional linear Mipmap flag setting
* Add optional edge clamping
* Fix texture orientation in Batcher.bf
* Fix example
This commit is contained in:
Thimo 2020-11-08 14:20:08 +01:00
parent decb8b855d
commit ae8ffdd2e3
4 changed files with 27 additions and 6 deletions

View File

@ -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();

View File

@ -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));
}
}
}

View File

@ -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;

View File

@ -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()