Nullable fixes, use Texture2d resource for rendering directly.

This commit is contained in:
2024-01-21 17:34:49 +01:00
parent cfbf46860d
commit 5f4e32e2e0
10 changed files with 105 additions and 74 deletions

View File

@@ -117,35 +117,14 @@ namespace DaggerFramework.Rendering
_rotation = rotation;
}
public override int LoadTexture(Texture2d texture)
public override void DrawTexture(Texture2d texture, Color tint)
{
Image image = new Image();
unsafe
if (texture.Handle == -1)
{
fixed (void* dataPtr = texture.Buffer)
{
image.data = dataPtr;
}
LoadTexture(texture);
}
image.width = texture.Width;
image.height = texture.Height;
image.mipmaps = 1;
image.format = PixelFormat.PIXELFORMAT_UNCOMPRESSED_R8G8B8A8;
Texture2D rayTexture;
rayTexture = Raylib.LoadTextureFromImage(image);
_texturePool.Add(rayTexture);
return _texturePool.Count - 1;
}
public override void DrawTexture(int id, Color tint)
{
Raylib.DrawTextureV(_texturePool[id], _position, DaggerColorToRaylibColor(tint));
Raylib.DrawTextureV(_texturePool[texture.Handle], _position, DaggerColorToRaylibColor(tint));
}
public override void DrawRectangle(Vector2 size, Color color)
@@ -206,12 +185,12 @@ namespace DaggerFramework.Rendering
public override void DrawText(Font font, string text, Color color)
{
if (font.FontHandle == -1)
if (font.Handle == -1)
{
LoadFont(font);
}
var rayFont = _fontPool[font.FontHandle];
var rayFont = _fontPool[font.Handle];
Raylib.DrawTextPro(rayFont, text, _position, Vector2.Zero, _rotation, font.Size, 0.0f, DaggerColorToRaylibColor(color));
}
@@ -255,7 +234,33 @@ namespace DaggerFramework.Rendering
_fontPool.Add(fontRay);
font.FontHandle = _fontPool.Count - 1;
font.Handle = _fontPool.Count - 1;
}
private void LoadTexture(Texture2d texture)
{
Image image = new();
unsafe
{
fixed (void* dataPtr = texture.Buffer)
{
image.data = dataPtr;
}
}
image.width = texture.Width;
image.height = texture.Height;
image.mipmaps = texture.Mipmaps;
image.format = (PixelFormat)texture.Format;
Texture2D rayTexture;
rayTexture = Raylib.LoadTextureFromImage(image);
_texturePool.Add(rayTexture);
texture.Handle = _texturePool.Count - 1;
}