mirror of
https://github.com/MaddyThorson/StrawberryBF.git
synced 2025-01-31 07:48:27 +08:00
commit
9ded760c78
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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)
|
||||
|
@ -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<T>() where T : Scene
|
||||
{
|
||||
Runtime.Assert(Scene is T, "Scene type mismatch!");
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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()
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user