mirror of
https://gitlab.com/octospacc/MultiSpaccSDK
synced 2025-06-05 22:09:21 +02:00
New features; First Hello World example with Makefile
This commit is contained in:
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 |
Reference in New Issue
Block a user