mirror of
https://gitlab.com/octospacc/MultiSpaccSDK
synced 2025-04-24 07:37:18 +02:00
New features; First Hello World example with Makefile
This commit is contained in:
parent
293bf55b7d
commit
280db9a8d5
44
LibMultiSpacc/Examples/Common.mk
Normal file
44
LibMultiSpacc/Examples/Common.mk
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
AppName = $(notdir ${CURDIR})
|
||||||
|
Sources = $(wildcard *.c ../../LibMultiSpacc/*.c)
|
||||||
|
CFlags = -O2
|
||||||
|
CC = gcc $(Defines)
|
||||||
|
|
||||||
|
ifndef Target
|
||||||
|
Target = PC
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifdef Target
|
||||||
|
ifeq ($(Target), PC)
|
||||||
|
ExeSuffix = .run
|
||||||
|
Defines = -DTarget_PC
|
||||||
|
MultiSpacc_Target = SDL20
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
ifeq ($(MultiSpacc_Target), SDL12)
|
||||||
|
Defines += -DMultiSpacc_Target_SDL12
|
||||||
|
LdFlags += -lSDL -lSDL_image -lSDL_mixer -lSDL_ttf
|
||||||
|
Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL12/*.c)
|
||||||
|
else ifeq ($(MultiSpacc_Target), SDL20)
|
||||||
|
Defines += -DMultiSpacc_Target_SDL20
|
||||||
|
LdFlags += -lSDL2 -lSDL2_image -lSDL2_mixer -lSDL2_ttf
|
||||||
|
Sources += $(wildcard ../../LibMultiSpacc/SDLCom/*.c ../../LibMultiSpacc/SDL20/*.c)
|
||||||
|
endif
|
||||||
|
|
||||||
|
Objects = $(Sources:.c=.o)
|
||||||
|
|
||||||
|
All: $(AppName)
|
||||||
|
|
||||||
|
$(AppName): $(Objects)
|
||||||
|
$(CC) $^ $(CFlags) $(LdFlags) -o $(AppName)$(ExeSuffix)
|
||||||
|
|
||||||
|
Run: All
|
||||||
|
./$(AppName)$(ExeSuffix)
|
||||||
|
|
||||||
|
Clean:
|
||||||
|
find -L . -name "*.o" -type f -delete
|
||||||
|
rm -f $(AppName)$(ExeSuffix) $(AppName).*$(ExeSuffix)
|
||||||
|
|
||||||
|
all: All
|
||||||
|
run: Run
|
||||||
|
clean: Clean
|
46
LibMultiSpacc/Examples/HelloWorld/HelloWorld.c
Normal file
46
LibMultiSpacc/Examples/HelloWorld/HelloWorld.c
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include "../../LibMultiSpacc/MultiSpacc.h"
|
||||||
|
|
||||||
|
#define AppName "Hello World"
|
||||||
|
#define ScreenWidth 320
|
||||||
|
#define ScreenHeight 240
|
||||||
|
#define ScreenBits 16
|
||||||
|
|
||||||
|
int main( int argc, char *args[] )
|
||||||
|
{
|
||||||
|
MultiSpacc_Window *Window = MultiSpacc_SetWindow( ScreenWidth, ScreenHeight, ScreenBits, 0 );
|
||||||
|
MultiSpacc_Surface *Screen = MultiSpacc_GetWindowSurface( Window );
|
||||||
|
|
||||||
|
if( Screen == NULL )
|
||||||
|
{
|
||||||
|
printf("[E] Error initializing Video System.\n");
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
|
||||||
|
MultiSpacc_SetAppTitle( Window, AppName );
|
||||||
|
|
||||||
|
// Bitmap font borrowed from: <https://github.com/nesdoug/01_Hello/blob/master/Alpha.chr>
|
||||||
|
// Copyright (c) 2018 Doug Fraker www.nesdoug.com (MIT)
|
||||||
|
MultiSpacc_Surface *TilesImg = MultiSpacc_LoadImage( "Tiles.png", Screen, NULL );
|
||||||
|
|
||||||
|
const char Text[] = "Hello, World!";
|
||||||
|
for(int i = 0; i < sizeof(Text); i++){
|
||||||
|
SDL_Rect Offset = {
|
||||||
|
.x = (8 * i) + (ScreenWidth / sizeof(Text)),
|
||||||
|
.y = ScreenHeight / 3,
|
||||||
|
};
|
||||||
|
SDL_Rect Clip = {
|
||||||
|
.x = 8 * ((int)Text[i] % 16),
|
||||||
|
.y = 8 * ((int)Text[i] / 16),
|
||||||
|
.w = 8,
|
||||||
|
.h = 8,
|
||||||
|
};
|
||||||
|
SDL_BlitSurface( TilesImg, &Clip, Screen, &Offset );
|
||||||
|
};
|
||||||
|
|
||||||
|
if( MultiSpacc_UpdateWindowSurface( Window ) != 0 ) {
|
||||||
|
printf("[E] Error updating Screen.\n");
|
||||||
|
};
|
||||||
|
|
||||||
|
MultiSpacc_Sleep( 3000 );
|
||||||
|
return 0;
|
||||||
|
};
|
BIN
LibMultiSpacc/Examples/HelloWorld/HelloWorld.run
Executable file
BIN
LibMultiSpacc/Examples/HelloWorld/HelloWorld.run
Executable file
Binary file not shown.
1
LibMultiSpacc/Examples/HelloWorld/Makefile
Normal file
1
LibMultiSpacc/Examples/HelloWorld/Makefile
Normal file
@ -0,0 +1 @@
|
|||||||
|
include ../Common.mk
|
BIN
LibMultiSpacc/Examples/HelloWorld/Tiles.png
Normal file
BIN
LibMultiSpacc/Examples/HelloWorld/Tiles.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
@ -4,16 +4,21 @@
|
|||||||
|
|
||||||
#ifdef MultiSpacc_Target_SDL12
|
#ifdef MultiSpacc_Target_SDL12
|
||||||
#include "SDL12/SDL.h"
|
#include "SDL12/SDL.h"
|
||||||
|
#include "SDLCom/SDL.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MultiSpacc_Target_SDL20
|
#ifdef MultiSpacc_Target_SDL20
|
||||||
#include "SDL20/SDL.h"
|
#include "SDL20/SDL.h"
|
||||||
|
#include "SDLCom/SDL.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags );
|
MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags );
|
||||||
MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window );
|
MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window );
|
||||||
|
|
||||||
void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char *Title );
|
void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] );
|
||||||
void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon );
|
void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon );
|
||||||
|
|
||||||
|
MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey );
|
||||||
int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key );
|
int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key );
|
||||||
|
|
||||||
|
int MultiSpacc_PollEvent( MultiSpacc_Event *Event );
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "SDL/SDL_image.h"
|
#include "SDL/SDL_image.h"
|
||||||
#include "SDL/SDL_mixer.h"
|
#include "SDL/SDL_mixer.h"
|
||||||
#include "SDL/SDL_ttf.h"
|
#include "SDL/SDL_ttf.h"
|
||||||
|
#include "../SDLCom/SDL.h"
|
||||||
|
|
||||||
MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags ) {
|
MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags ) {
|
||||||
return SDL_SetVideoMode( Width, Height, Bits, Flags );
|
return SDL_SetVideoMode( Width, Height, Bits, Flags );
|
||||||
@ -19,10 +20,8 @@ void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon
|
|||||||
}
|
}
|
||||||
|
|
||||||
int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) {
|
int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) {
|
||||||
if ( Flag ) {
|
if( Flag )
|
||||||
return SDL_SetColorKey( Surface, SDL_SRCCOLORKEY, Key );
|
return SDL_SetColorKey( Surface, SDL_SRCCOLORKEY, Key );
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
return SDL_SetColorKey( Surface, 0, Key );
|
return SDL_SetColorKey( Surface, 0, Key );
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
#include "SDL/SDL_ttf.h"
|
#include "SDL/SDL_ttf.h"
|
||||||
|
|
||||||
#define MultiSpacc_Window SDL_Surface
|
#define MultiSpacc_Window SDL_Surface
|
||||||
#define MultiSpacc_Surface SDL_Surface
|
|
||||||
|
|
||||||
#define MultiSpacc_UpdateWindowSurface SDL_Flip
|
#define MultiSpacc_UpdateWindowSurface SDL_Flip
|
||||||
|
|
||||||
|
typedef struct MultiSpacc_Event {
|
||||||
|
Uint32 Type;
|
||||||
|
SDLKey Key;
|
||||||
|
} MultiSpacc_Event;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "SDL2/SDL_image.h"
|
#include "SDL2/SDL_image.h"
|
||||||
#include "SDL2/SDL_mixer.h"
|
#include "SDL2/SDL_mixer.h"
|
||||||
#include "SDL2/SDL_ttf.h"
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
#include "../SDLCom/SDL.h"
|
||||||
|
|
||||||
MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags ) {
|
MultiSpacc_Window *MultiSpacc_SetWindow( int Width, int Height, int Bits, Uint32 Flags ) {
|
||||||
return SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Width, Height, Flags);
|
return SDL_CreateWindow(NULL, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Width, Height, Flags);
|
||||||
@ -11,7 +12,7 @@ MultiSpacc_Surface *MultiSpacc_GetWindowSurface( MultiSpacc_Window *Window ) {
|
|||||||
return SDL_GetWindowSurface( Window );
|
return SDL_GetWindowSurface( Window );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char *Title ) {
|
void MultiSpacc_SetAppTitle( MultiSpacc_Window *Window, const char Title[] ) {
|
||||||
SDL_SetWindowTitle( Window, Title );
|
SDL_SetWindowTitle( Window, Title );
|
||||||
}
|
}
|
||||||
void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon ) {
|
void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon ) {
|
||||||
@ -19,10 +20,8 @@ void MultiSpacc_SetAppIcon( MultiSpacc_Window *Window, MultiSpacc_Surface *Icon
|
|||||||
}
|
}
|
||||||
|
|
||||||
int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) {
|
int MultiSpacc_SetColorKey( MultiSpacc_Surface *Surface, bool Flag, Uint32 Key ) {
|
||||||
if ( Flag ) {
|
if ( Flag )
|
||||||
return SDL_SetColorKey( Surface, SDL_TRUE, Key );
|
return SDL_SetColorKey( Surface, SDL_TRUE, Key );
|
||||||
}
|
else
|
||||||
else {
|
|
||||||
return SDL_SetColorKey( Surface, SDL_FALSE, Key );
|
return SDL_SetColorKey( Surface, SDL_FALSE, Key );
|
||||||
}
|
};
|
||||||
}
|
|
||||||
|
@ -11,6 +11,9 @@
|
|||||||
#include "SDL2/SDL_ttf.h"
|
#include "SDL2/SDL_ttf.h"
|
||||||
|
|
||||||
#define MultiSpacc_Window SDL_Window
|
#define MultiSpacc_Window SDL_Window
|
||||||
#define MultiSpacc_Surface SDL_Surface
|
|
||||||
|
|
||||||
#define MultiSpacc_UpdateWindowSurface SDL_UpdateWindowSurface
|
#define MultiSpacc_UpdateWindowSurface SDL_UpdateWindowSurface
|
||||||
|
|
||||||
|
typedef struct MultiSpacc_Event {
|
||||||
|
Uint32 Type;
|
||||||
|
SDL_Keycode Key;
|
||||||
|
} MultiSpacc_Event;
|
||||||
|
33
LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c
Normal file
33
LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.c
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#include "../MultiSpacc.h"
|
||||||
|
|
||||||
|
int MultiSpacc_PollEvent( MultiSpacc_Event *Event )
|
||||||
|
{
|
||||||
|
SDL_Event FromEvent;
|
||||||
|
int Result = SDL_PollEvent( &FromEvent );
|
||||||
|
*Event = (MultiSpacc_Event) {
|
||||||
|
.Type = FromEvent.type,
|
||||||
|
.Key = FromEvent.key.keysym.sym,
|
||||||
|
};
|
||||||
|
return Result;
|
||||||
|
};
|
||||||
|
|
||||||
|
MultiSpacc_Surface *MultiSpacc_LoadImage( char FilePath[], MultiSpacc_Surface *Screen, Uint32 *ColorKey )
|
||||||
|
{
|
||||||
|
MultiSpacc_Surface *Final = NULL;
|
||||||
|
MultiSpacc_Surface *Raw = IMG_Load( FilePath );
|
||||||
|
if( Raw == NULL ) {
|
||||||
|
printf("[E] Error reading image %s.\n", FilePath);
|
||||||
|
} else {
|
||||||
|
Final = SDL_ConvertSurface( Raw, Screen->format, 0 );
|
||||||
|
SDL_FreeSurface( Raw );
|
||||||
|
if( Final == NULL ) {
|
||||||
|
printf("[E] Error adapting image %s.\n", FilePath);
|
||||||
|
} else {
|
||||||
|
Uint32 FinalColorKey = SDL_MapRGB( Final->format, 0xFF, 0x00, 0xFF ); // Magenta
|
||||||
|
if( ColorKey != NULL )
|
||||||
|
FinalColorKey = *ColorKey;
|
||||||
|
MultiSpacc_SetColorKey( Final, true, FinalColorKey );
|
||||||
|
};
|
||||||
|
};
|
||||||
|
return Final;
|
||||||
|
};
|
8
LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.h
Normal file
8
LibMultiSpacc/LibMultiSpacc/SDLCom/SDL.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../MultiSpacc.h"
|
||||||
|
|
||||||
|
#define MultiSpacc_Init SDL_Init
|
||||||
|
#define MultiSpacc_Surface SDL_Surface
|
||||||
|
#define MultiSpacc_GetTicks SDL_GetTicks
|
||||||
|
#define MultiSpacc_Sleep SDL_Delay
|
@ -7,9 +7,11 @@ The idea is simple: to build an universal abstraction layer on top of other exis
|
|||||||
The list of supported (or planned) backend libraries follows:
|
The list of supported (or planned) backend libraries follows:
|
||||||
|
|
||||||
- SDL 1.2 (WIP)
|
- SDL 1.2 (WIP)
|
||||||
- SDL 2.0 (WIP)
|
- SDL 2.0/3.0 (WIP)[^1]
|
||||||
- NDS
|
- NDS (Planned)
|
||||||
- GBA
|
- GBA (Planned)
|
||||||
- NES
|
- NES (Planned)
|
||||||
|
|
||||||
Example programs (and makefiles) will come soon.
|
Example programs (and makefiles) will come soon.
|
||||||
|
|
||||||
|
[^1]: I just discovered that SDL 3.0 exists, I'm so tired, why would they make a new major, now I have to support 3 versions... or just drop 2.0 and only support 1.2 + 3.0.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user