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
ifeq ($(Target), PC)
Defines = -DTarget_PC
MultiSpacc_Target = SDL12
MultiSpacc_Target = SDL20
else ifeq ($(Target), PocketGo)
ExeSuffix = .PocketGo.exe
PathPrefix = /opt/miyoo/bin/arm-miyoo-linux-uclibcgnueabi

View File

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

View File

@ -3,14 +3,14 @@
//#include "SDL/SDL.h"
//#include "SDL/SDL_image.h"
SDL_Surface * LoadImage ( char * FilePath ) {
SDL_Surface * a = NULL;
SDL_Surface * b = NULL;
SDL_Surface * LoadImage ( char *FilePath, MultiSpacc_Surface *Screen ) {
SDL_Surface *a = NULL;
SDL_Surface *b = NULL;
a = IMG_Load ( FilePath );///*
if ( a == NULL ) {
printf("[E] Error reading image %s.\n", FilePath);
} else {
b = SDL_DisplayFormat ( a );
b = SDL_ConvertSurface( a, Screen->format, 0 ); //SDL_DisplayFormat ( a );
SDL_FreeSurface ( a );
if ( b == NULL ) {
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_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen ) {
Screen = SDL_SetVideoMode ( Width, Height, Bits,
#ifdef Target_PocketGo
@ -69,9 +70,10 @@ SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen
);
return Screen;
}
*/
bool FlipScreen( SDL_Surface * Screen ) {
if ( SDL_Flip( Screen ) != 0 ) {
bool FlipScreen( MultiSpacc_Window * Window ) {
if ( MultiSpacc_UpdateWindowSurface( Window ) != 0 ) {
printf("[E] Error updating screen.\n");
return false;
}

View File

@ -2,12 +2,12 @@
#include <stdbool.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 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 );
SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen );
bool FlipScreen( SDL_Surface * Screen );
//SDL_Surface * ScreenSet ( int Width, int Height, int Bits, SDL_Surface * Screen );
bool FlipScreen( MultiSpacc_Window * Window );
struct xyz {
int x, y, z;