- Canvis en el format de la paleta i en el volcat a textura de SDL.

This commit is contained in:
2024-02-12 14:23:21 +01:00
parent 19df09dddc
commit e1518cf76f
2 changed files with 17 additions and 14 deletions

View File

@@ -27,15 +27,15 @@ SDL_Renderer* sdlRenderer = NULL;
SDL_Texture* sdlTexture = NULL;
void JD8_Init(const char *title) {
screen = (JD8_Surface)calloc( 1, 64000 );
main_palette = (JD8_Palette)calloc( 1, 768 );
screen = (JD8_Surface)calloc( 1, 320 * 200 );
main_palette = (JD8_Palette)calloc( 1, 256 * sizeof(uint32_t) );
pixel_data = (Uint32*)calloc(1, 320 * 200 * 4); // 1048576 );
sdlWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
}
void JD8_Quit() {
@@ -82,8 +82,15 @@ JD8_Palette JD8_LoadPalette(const char *file) {
char *buffer = NULL;
buffer = JF_GetBufferFromResource(file, filesize);
JD8_Palette palette = (JD8_Palette)LoadPalette((unsigned char*)buffer);
uint8_t *pal = LoadPalette((unsigned char*)buffer);
JD8_Palette palette = (JD8_Palette)malloc(256 * sizeof(uint32_t));
for (int i=0; i<256; ++i) {
palette[i].r = pal[i*3];
palette[i].g = pal[1 + i*3];
palette[i].b = pal[2 + i*3];
//palette[i].hex = 0xff0000;
}
return palette;
}
@@ -173,12 +180,7 @@ void JD8_BlitCKToSurface(int x, int y, JD8_Surface surface, int sx, int sy, int
SDL_Rect rect{0, 0, SCREEN_WIDTH, SCREEN_HEIGHT};
void JD8_Flip() {
for( int x = 0; x < 320; x++ ) {
for( int y = 0; y < 200; y++ ) {
Uint32 color = 0xFF000000 + main_palette[screen[x + ( y * 320 )]].r + ( main_palette[screen[x + ( y * 320 )]].g << 8 ) + ( main_palette[screen[x + ( y * 320 )]].b << 16 );
pixel_data[x + ( y * 320 )] = color;
}
}
for (int i=0; i<64000; ++i) pixel_data[i] = main_palette[screen[i]].hex;
SDL_UpdateTexture(sdlTexture, NULL, pixel_data, 320 * sizeof(Uint32));
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, &rect);
SDL_RenderPresent(sdlRenderer);

View File

@@ -1,10 +1,11 @@
#pragma once
#include <SDL2/SDL.h>
struct Color {
Uint8 r;
Uint8 g;
Uint8 b;
union Color {
struct {
uint8_t b, g, r, a;
};
uint32_t hex;
};
typedef Uint8* JD8_Surface;