Texture pixel format change

This commit is contained in:
Matt Thorson 2020-05-27 20:46:28 -07:00
parent 6bfc6c7721
commit d2ce347caa
2 changed files with 12 additions and 13 deletions

View File

@ -450,7 +450,7 @@ namespace Strawberry
public this(int w, int h) public this(int w, int h)
{ {
Texture = SDL.CreateTexture(Game.Renderer, (uint32)SDL.PIXELFORMAT_ARGB8888, (int32)SDL.TextureAccess.Static, (int32)w, (int32)h); Texture = SDL.CreateTexture(Game.Renderer, (uint32)SDL.PIXELFORMAT_RGBA8888, (int32)SDL.TextureAccess.Static, (int32)w, (int32)h);
void* ptr; void* ptr;
SDL.LockTexture(Texture, null, out ptr, out PixelsLength); SDL.LockTexture(Texture, null, out ptr, out PixelsLength);
@ -577,12 +577,12 @@ namespace Strawberry
{ {
if (src.A != 0) if (src.A != 0)
{ {
int a = dest[index]; int r = dest[index];
int r = dest[index + 1]; int g = dest[index + 1];
int g = dest[index + 2]; int b = dest[index + 2];
int b = dest[index + 3]; int a = dest[index + 3];
if (dest[index] == 0) if (a == 0)
{ {
a = src.A; a = src.A;
r = src.R; r = src.R;
@ -594,16 +594,16 @@ namespace Strawberry
int sa = MUL_UN8(src.A, opacity); int sa = MUL_UN8(src.A, opacity);
int ra = a + sa - MUL_UN8(a, sa); int ra = a + sa - MUL_UN8(a, sa);
a = ra;
r = (r + (src.R - r) * sa / ra); r = (r + (src.R - r) * sa / ra);
g = (g + (src.G - g) * sa / ra); g = (g + (src.G - g) * sa / ra);
b = (b + (src.B - b) * sa / ra); b = (b + (src.B - b) * sa / ra);
a = ra;
} }
dest[index] = (uint8)a; dest[index] = (uint8)r;
dest[index + 1] = (uint8)r; dest[index + 1] = (uint8)g;
dest[index + 2] = (uint8)g; dest[index + 2] = (uint8)b;
dest[index + 3] = (uint8)b; dest[index + 3] = (uint8)a;
} }
} }
}; };

View File

@ -40,8 +40,7 @@ namespace Strawberry
static public void Sprite(Sprite sprite, int frame, Point position) static public void Sprite(Sprite sprite, int frame, Point position)
{ {
SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height); SDL.Rect src = Strawberry.Rect(0, 0, sprite.Width, sprite.Height);
SDL.Rect dst = Strawberry.Rect(position.X, position.Y, sprite.Width, sprite.Height); SDL.Rect dst = Strawberry.Rect(position.X - Camera.X, position.Y - Camera.Y, sprite.Width, sprite.Height);
SDL.RenderCopy(Game.Renderer, sprite[frame].Texture, &src, &dst); SDL.RenderCopy(Game.Renderer, sprite[frame].Texture, &src, &dst);
} }
} }