Allow different texture formats.

This commit is contained in:
2025-08-18 22:51:42 -05:00
parent 6f42a6e195
commit 1411c2e96b
6 changed files with 15 additions and 14 deletions

View File

@@ -19,10 +19,6 @@ typedef struct {
} playerentity_t; } playerentity_t;
#define PLAYER_ENTITY_ID (UINT32_MAX-1) #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; extern inventory_t PLAYER_INVENTORY;

View File

@@ -19,7 +19,7 @@
assertTrue(width > 0 && height > 0, "Width & height must be greater than 0"); assertTrue(width > 0 && height > 0, "Width & height must be greater than 0");
memoryZero(framebuffer, sizeof(framebuffer_t)); 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 // Generate the framebuffer object using EXT
glGenFramebuffersEXT(1, &framebuffer->id); glGenFramebuffersEXT(1, &framebuffer->id);

View File

@@ -60,6 +60,7 @@ errorret_t renderInit(void) {
glShadeModel(GL_SMOOTH); // Fixes color on PSP? glShadeModel(GL_SMOOTH); // Fixes color on PSP?
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 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_COLOR_ARRAY);// To confirm: every frame on PSP?
glEnableClientState(GL_TEXTURE_COORD_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY);

View File

@@ -14,6 +14,7 @@ void textureInit(
texture_t *texture, texture_t *texture,
const int32_t width, const int32_t width,
const int32_t height, const int32_t height,
const GLenum format,
const uint8_t *data const uint8_t *data
) { ) {
assertNotNull(texture, "Texture cannot be NULL"); assertNotNull(texture, "Texture cannot be NULL");
@@ -37,8 +38,8 @@ void textureInit(
glGenTextures(1, &texture->id); glGenTextures(1, &texture->id);
glBindTexture(GL_TEXTURE_2D, texture->id); glBindTexture(GL_TEXTURE_2D, texture->id);
glTexImage2D( glTexImage2D(
GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_TEXTURE_2D, 0, format, width, height, 0,
GL_RGBA, GL_UNSIGNED_BYTE, data format, GL_UNSIGNED_BYTE, data
); );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

View File

@@ -20,12 +20,14 @@ typedef struct {
* @param texture The texture to initialize. * @param texture The texture to initialize.
* @param width The width of the texture. * @param width The width of the texture.
* @param height The height 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. * @param data The pixel data for the texture.
*/ */
void textureInit( void textureInit(
texture_t *texture, texture_t *texture,
const int32_t width, const int32_t width,
const int32_t height, const int32_t height,
const GLenum format,
const uint8_t *data const uint8_t *data
); );

View File

@@ -33,7 +33,7 @@ void renderTextInit(void) {
uint8_t *pixels = (uint8_t *)memoryAllocate( uint8_t *pixels = (uint8_t *)memoryAllocate(
outputFontWidth * outputFontHeight * outputFontWidth * outputFontHeight *
4 * sizeof(uint8_t) sizeof(uint8_t)
); );
// Buffer the pixels. // Buffer the pixels.
@@ -45,17 +45,18 @@ void renderTextInit(void) {
for (int y = 0; y < FONT_TILE_HEIGHT; ++y) { for (int y = 0; y < FONT_TILE_HEIGHT; ++y) {
for (int x = 0; x < FONT_TILE_WIDTH; ++x) { for (int x = 0; x < FONT_TILE_WIDTH; ++x) {
const int32_t pixel = (tileY + y) * outputFontWidth + (tileX + 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]; uint8_t value = tile[y * FONT_TILE_WIDTH + x];
pixels[pixelOffset + 0] = value ? 0xFF : 0x00; // Red channel pixels[pixel] = value ? 0xFF : 0x00; // Alpha 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
} }
} }
} }
textureInit(&RENDER_TEXT_TEXTURE, outputFontWidth, outputFontHeight, pixels); textureInit(
&RENDER_TEXT_TEXTURE,
outputFontWidth, outputFontHeight,
GL_ALPHA, pixels
);
memoryFree(pixels); memoryFree(pixels);
} }