SDL2 port via MultiSpacc

This commit is contained in:
octospacc 2022-08-07 00:40:49 +02:00
parent 8fff7d7a4e
commit 1ca44c833d
4 changed files with 21 additions and 17 deletions

View File

@ -12,7 +12,7 @@ endif
ifdef Target ifdef Target
ifeq ($(Target), PC) ifeq ($(Target), PC)
Defines = -DTarget_PC Defines = -DTarget_PC
MultiSpacc_Target = SDL12 MultiSpacc_Target = SDL20
else ifeq ($(Target), PocketGo) else ifeq ($(Target), PocketGo)
ExeSuffix = .PocketGo.exe ExeSuffix = .PocketGo.exe
PathPrefix = /opt/miyoo/bin/arm-miyoo-linux-uclibcgnueabi PathPrefix = /opt/miyoo/bin/arm-miyoo-linux-uclibcgnueabi

View File

@ -12,7 +12,8 @@
#define AppName "BloccSpacc" #define AppName "BloccSpacc"
SDL_Surface * Screen = NULL; MultiSpacc_Window *Window = NULL;
MultiSpacc_Surface *Screen = NULL;
SDL_Event Event; SDL_Event Event;
#define GameTick 30 #define GameTick 30
@ -66,7 +67,8 @@ bool SysInit() {
printf("[E] Error initializing SDL.\n"); printf("[E] Error initializing SDL.\n");
return false; return false;
} }
Screen = ScreenSet ( ScreenWidth, ScreenHeight, ScreenBits, Screen ); Window = MultiSpacc_SetWindow( ScreenWidth, ScreenHeight, ScreenBits, 0 );
Screen = MultiSpacc_GetWindowSurface( Window );
if ( Screen == NULL ) { if ( Screen == NULL ) {
printf("[E] Error initializing screen.\n"); printf("[E] Error initializing screen.\n");
return false; return false;
@ -75,18 +77,18 @@ bool SysInit() {
printf("[E] Error initializing SDL_TTF.\n"); printf("[E] Error initializing SDL_TTF.\n");
return false; return false;
} }
MultiSpacc_SetAppTitle( Screen, AppName ); MultiSpacc_SetAppTitle( Window, AppName );
MultiSpacc_SetAppIcon( Screen, LoadImage( "Assets/Cursorset.png" ) ); MultiSpacc_SetAppIcon( Window, LoadImage( "Assets/Icon.png", Screen ) );
return true; return true;
} }
bool LoadAssets() { bool LoadAssets() {
bool Error = false; bool Error = false;
Cursorset = LoadImage( "Assets/Cursorset.png" ); Cursorset = LoadImage( "Assets/Cursorset.png", Screen );
if ( Cursorset == NULL ) { if ( Cursorset == NULL ) {
Error = true; Error = true;
} }
BlocksImg = LoadImage( "Assets/Blocks.png" ); BlocksImg = LoadImage( "Assets/Blocks.png", Screen );
if ( BlocksImg == NULL ) { if ( BlocksImg == NULL ) {
Error = true; Error = true;
} }
@ -395,7 +397,7 @@ int main( int argc, char* args[] ) {
if ( InInventory ) { if ( InInventory ) {
DrawInventory(); DrawInventory();
} }
if ( !FlipScreen( Screen ) ) { if ( !FlipScreen( Window ) ) {
return 1; return 1;
} }
Recalc = false; Recalc = false;

View File

@ -3,14 +3,14 @@
//#include "SDL/SDL.h" //#include "SDL/SDL.h"
//#include "SDL/SDL_image.h" //#include "SDL/SDL_image.h"
SDL_Surface * LoadImage ( char * FilePath ) { SDL_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) {
SDL_Surface * a = NULL; SDL_Surface *a = NULL;
SDL_Surface * b = NULL; SDL_Surface *b = NULL;
a = IMG_Load ( FilePath );///* a = IMG_Load ( FilePath );///*
if ( a == NULL ) { if ( a == NULL ) {
printf("[E] Error reading image %s.\n", FilePath); printf("[E] Error reading image %s.\n", FilePath);
} else { } else {
b = SDL_DisplayFormat ( a ); b = SDL_ConvertSurface( a, Screen->format, 0 ); //SDL_DisplayFormat ( a );
SDL_FreeSurface ( a ); SDL_FreeSurface ( a );
if ( b == NULL ) { if ( b == NULL ) {
printf("[E] Error adapting image %s.\n", FilePath); printf("[E] Error adapting image %s.\n", FilePath);
@ -55,6 +55,7 @@ void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B
SDL_FillRect( Dst, &Rect, SDL_MapRGB( Dst->format, R, G, B ) ); SDL_FillRect( Dst, &Rect, SDL_MapRGB( Dst->format, R, G, B ) );
} }
/*
SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen ) { SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen ) {
Screen = SDL_SetVideoMode ( Width, Height, Bits, Screen = SDL_SetVideoMode ( Width, Height, Bits,
#ifdef Target_PocketGo #ifdef Target_PocketGo
@ -69,9 +70,10 @@ SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen
); );
return Screen; return Screen;
} }
*/
bool FlipScreen( SDL_Surface * Screen ) { bool FlipScreen( MultiSpacc_Window * Window ) {
if ( SDL_Flip( Screen ) != 0 ) { if ( MultiSpacc_UpdateWindowSurface( Window ) != 0 ) {
printf("[E] Error updating screen.\n"); printf("[E] Error updating screen.\n");
return false; return false;
} }

View File

@ -2,12 +2,12 @@
#include <stdbool.h> #include <stdbool.h>
#include "LibMultiSpacc/MultiSpacc.h" #include "LibMultiSpacc/MultiSpacc.h"
SDL_Surface * LoadImage ( char * FilePath ); SDL_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen );
void DrawSurf ( int x, int y, SDL_Surface * Src, SDL_Rect * Clip, SDL_Surface * Dst ); void DrawSurf ( int x, int y, SDL_Surface * Src, SDL_Rect * Clip, SDL_Surface * Dst );
void FillSurfRGB ( int R, int G, int B, SDL_Surface * Dst ); void FillSurfRGB ( int R, int G, int B, SDL_Surface * Dst );
void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, SDL_Surface * Dst ); void DrawOutlineRect ( int x, int y, int w, int h, int Size, int R, int G, int B, SDL_Surface * Dst );
SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen ); //SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen );
bool FlipScreen( SDL_Surface * Screen ); bool FlipScreen( MultiSpacc_Window * Window );
struct xyz { struct xyz {
int x, y, z; int x, y, z;