GifLoader done. SDL_Image dependency removed from Windows version. TBD on OSX and Linux
This commit is contained in:
40
jdraw8.cpp
40
jdraw8.cpp
@@ -1,8 +1,7 @@
|
||||
#include "jdraw8.h"
|
||||
#include "SDL_image.h"
|
||||
//#include "SDL_opengl.h"
|
||||
#include "jfile.h"
|
||||
#include <fstream>
|
||||
#include "gif.c"
|
||||
|
||||
JD8_Surface screen = NULL;
|
||||
JD8_Palette main_palette = NULL;
|
||||
@@ -27,7 +26,6 @@ void JD8_Init(const char *title) {
|
||||
sdlWindow = SDL_CreateWindow( title, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, SDL_WINDOW_SHOWN );
|
||||
sdlRenderer = SDL_CreateRenderer(sdlWindow, -1, 0);
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "nearest");
|
||||
SDL_RenderSetLogicalSize(sdlRenderer, 320, 200);
|
||||
|
||||
sdlTexture = SDL_CreateTexture(sdlRenderer, SDL_PIXELFORMAT_ABGR8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
|
||||
}
|
||||
@@ -54,20 +52,20 @@ JD8_Surface JD8_LoadSurface(const char *file) {
|
||||
int filesize = 0;
|
||||
char *buffer = JF_GetBufferFromResource(file, filesize);
|
||||
|
||||
SDL_RWops *rw = SDL_RWFromMem(buffer, filesize);
|
||||
SDL_Surface *temp = IMG_Load_RW(rw, 1);
|
||||
unsigned short w, h;
|
||||
Uint8* pixels = LoadGif((unsigned char*)buffer, &w, &h);
|
||||
|
||||
free(buffer);
|
||||
|
||||
if (temp == NULL) {
|
||||
if (pixels == NULL) {
|
||||
printf("Unable to load bitmap: %s\n", SDL_GetError());
|
||||
exit(1);
|
||||
}
|
||||
|
||||
JD8_Surface image = JD8_NewSurface();
|
||||
memcpy( image, temp->pixels, 64000 );
|
||||
|
||||
SDL_FreeSurface(temp);
|
||||
memcpy(image, pixels, 64000);
|
||||
|
||||
free(pixels);
|
||||
return image;
|
||||
}
|
||||
|
||||
@@ -75,26 +73,8 @@ JD8_Palette JD8_LoadPalette(const char *file) {
|
||||
int filesize = 0;
|
||||
char *buffer = NULL;
|
||||
buffer = JF_GetBufferFromResource(file, filesize);
|
||||
|
||||
SDL_RWops *rw = NULL;
|
||||
rw = SDL_RWFromMem(buffer, filesize);
|
||||
if( rw == NULL ) { printf("ERROR: No s'ha pogut crear el RWops"); exit(1); }
|
||||
|
||||
SDL_Surface *temp = NULL;
|
||||
temp = IMG_Load_RW(rw, 1);
|
||||
if( temp == NULL ) { printf("ERROR! No s'ha pogut crear la SDL_Surface: %s", SDL_GetError()); exit(1); }
|
||||
|
||||
free(buffer);
|
||||
|
||||
JD8_Palette palette = (JD8_Palette)malloc( 768 );
|
||||
|
||||
for( int i = 0; i < 256; i++ ) {
|
||||
palette[i].r = temp->format->palette->colors[i].r;
|
||||
palette[i].g = temp->format->palette->colors[i].g;
|
||||
palette[i].b = temp->format->palette->colors[i].b;
|
||||
}
|
||||
|
||||
SDL_FreeSurface(temp);
|
||||
JD8_Palette palette = (JD8_Palette)LoadPalette((unsigned char*)buffer);
|
||||
|
||||
return palette;
|
||||
}
|
||||
@@ -152,6 +132,8 @@ void JD8_BlitCKToSurface(int x, int y, JD8_Surface surface, int sx, int sy, int
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Rect rect{0, 0, 640, 480};
|
||||
|
||||
void JD8_Flip() {
|
||||
for( int x = 0; x < 320; x++ ) {
|
||||
for( int y = 0; y < 200; y++ ) {
|
||||
@@ -160,7 +142,7 @@ void JD8_Flip() {
|
||||
}
|
||||
}
|
||||
SDL_UpdateTexture(sdlTexture, NULL, pixel_data, 320 * sizeof(Uint32));
|
||||
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
|
||||
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, &rect);
|
||||
SDL_RenderPresent(sdlRenderer);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user