Allow different texture formats.
This commit is contained in:
@@ -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;
|
||||
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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
|
||||
);
|
||||
|
||||
|
@@ -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);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user