From 1411c2e96b294f032080bc6b83efe2b639b861a6 Mon Sep 17 00:00:00 2001 From: Dominic Masters Date: Mon, 18 Aug 2025 22:51:42 -0500 Subject: [PATCH] Allow different texture formats. --- src/dusk/entity/player.h | 4 ---- src/dusksdl2/display/framebuffer/framebuffer.c | 2 +- src/dusksdl2/display/render.c | 1 + src/dusksdl2/display/texture/texture.c | 5 +++-- src/dusksdl2/display/texture/texture.h | 2 ++ src/dusksdl2/display/ui/rendertext.c | 15 ++++++++------- 6 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/dusk/entity/player.h b/src/dusk/entity/player.h index 570f423..0780cbb 100644 --- a/src/dusk/entity/player.h +++ b/src/dusk/entity/player.h @@ -19,10 +19,6 @@ typedef struct { } playerentity_t; #define PLAYER_ENTITY_ID (UINT32_MAX-1) -// #define PLAYER_MOVE_SPEED 1.5f -// #define PLAYER_MOVE_SPEED_XY (PLAYER_MOVE_SPEED * 1.4142f) -#define PLAYER_INTERACT_RANGE (TILE_WIDTH_HEIGHT + (TILE_WIDTH_HEIGHT / 3)) -// #define PLAYER_INTERACT_ANGLE 0.68359375f extern inventory_t PLAYER_INVENTORY; diff --git a/src/dusksdl2/display/framebuffer/framebuffer.c b/src/dusksdl2/display/framebuffer/framebuffer.c index b99f71b..cdd9e5a 100644 --- a/src/dusksdl2/display/framebuffer/framebuffer.c +++ b/src/dusksdl2/display/framebuffer/framebuffer.c @@ -19,7 +19,7 @@ assertTrue(width > 0 && height > 0, "Width & height must be greater than 0"); memoryZero(framebuffer, sizeof(framebuffer_t)); - textureInit(&framebuffer->texture, width, height, NULL); + textureInit(&framebuffer->texture, width, height, GL_RGBA, NULL); // Generate the framebuffer object using EXT glGenFramebuffersEXT(1, &framebuffer->id); diff --git a/src/dusksdl2/display/render.c b/src/dusksdl2/display/render.c index 5853717..1fdbaa7 100644 --- a/src/dusksdl2/display/render.c +++ b/src/dusksdl2/display/render.c @@ -60,6 +60,7 @@ errorret_t renderInit(void) { glShadeModel(GL_SMOOTH); // Fixes color on PSP? glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glEnableClientState(GL_COLOR_ARRAY);// To confirm: every frame on PSP? glEnableClientState(GL_TEXTURE_COORD_ARRAY); diff --git a/src/dusksdl2/display/texture/texture.c b/src/dusksdl2/display/texture/texture.c index f40528f..a169431 100644 --- a/src/dusksdl2/display/texture/texture.c +++ b/src/dusksdl2/display/texture/texture.c @@ -14,6 +14,7 @@ void textureInit( texture_t *texture, const int32_t width, const int32_t height, + const GLenum format, const uint8_t *data ) { assertNotNull(texture, "Texture cannot be NULL"); @@ -37,8 +38,8 @@ void textureInit( glGenTextures(1, &texture->id); glBindTexture(GL_TEXTURE_2D, texture->id); glTexImage2D( - GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, - GL_RGBA, GL_UNSIGNED_BYTE, data + GL_TEXTURE_2D, 0, format, width, height, 0, + format, GL_UNSIGNED_BYTE, data ); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); diff --git a/src/dusksdl2/display/texture/texture.h b/src/dusksdl2/display/texture/texture.h index 713b370..afec530 100644 --- a/src/dusksdl2/display/texture/texture.h +++ b/src/dusksdl2/display/texture/texture.h @@ -20,12 +20,14 @@ typedef struct { * @param texture The texture to initialize. * @param width The width of the texture. * @param height The height of the texture. + * @param format The format of the texture (e.g., GL_RGBA, GL_ALPHA). * @param data The pixel data for the texture. */ void textureInit( texture_t *texture, const int32_t width, const int32_t height, + const GLenum format, const uint8_t *data ); diff --git a/src/dusksdl2/display/ui/rendertext.c b/src/dusksdl2/display/ui/rendertext.c index f9050ae..b14105a 100644 --- a/src/dusksdl2/display/ui/rendertext.c +++ b/src/dusksdl2/display/ui/rendertext.c @@ -33,7 +33,7 @@ void renderTextInit(void) { uint8_t *pixels = (uint8_t *)memoryAllocate( outputFontWidth * outputFontHeight * - 4 * sizeof(uint8_t) + sizeof(uint8_t) ); // Buffer the pixels. @@ -45,17 +45,18 @@ void renderTextInit(void) { for (int y = 0; y < FONT_TILE_HEIGHT; ++y) { for (int x = 0; x < FONT_TILE_WIDTH; ++x) { const int32_t pixel = (tileY + y) * outputFontWidth + (tileX + x); - const int32_t pixelOffset = pixel * 4; + const int32_t pixelOffset = pixel; uint8_t value = tile[y * FONT_TILE_WIDTH + x]; - pixels[pixelOffset + 0] = value ? 0xFF : 0x00; // Red channel - pixels[pixelOffset + 1] = value ? 0xFF : 0x00; // Green channel - pixels[pixelOffset + 2] = value ? 0xFF : 0x00; // Blue channel - pixels[pixelOffset + 3] = value ? 0xFF : 0x00; // Alpha channel + pixels[pixel] = value ? 0xFF : 0x00; // Alpha channel } } } - textureInit(&RENDER_TEXT_TEXTURE, outputFontWidth, outputFontHeight, pixels); + textureInit( + &RENDER_TEXT_TEXTURE, + outputFontWidth, outputFontHeight, + GL_ALPHA, pixels + ); memoryFree(pixels); }