Skip to content

Commit

Permalink
SDL2 port.
Browse files Browse the repository at this point in the history
Signed-off-by: Steffen Pankratz <[email protected]>
  • Loading branch information
kratz00 committed Feb 7, 2023
1 parent 9817c0b commit 6bc1435
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 2,370 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ jobs:
run: |
sudo apt-get update
sudo apt-get install \
libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl1.2-dev ninja-build
libsdl2-image-dev libsdl2-mixer-dev libsdl2-dev ninja-build
- name: Setup macOS dependencies
if: runner.os == 'macOS'
run: |
brew install \
sdl_image sdl_mixer sdl12-compat ninja
sdl2_image sdl2_mixer sdl2 ninja
- name: Set up Windows dependencies
if: matrix.platform.shell == 'msys2 {0}'
Expand All @@ -48,9 +48,9 @@ jobs:
${{ matrix.platform.msys-env }}-gcc
${{ matrix.platform.msys-env }}-cmake
${{ matrix.platform.msys-env }}-ninja
${{ matrix.platform.msys-env }}-SDL_image
${{ matrix.platform.msys-env }}-SDL_mixer
${{ matrix.platform.msys-env }}-SDL
${{ matrix.platform.msys-env }}-SDL2_image
${{ matrix.platform.msys-env }}-SDL2_mixer
${{ matrix.platform.msys-env }}-SDL2
- name: Configure CMake
run: cmake -B build -G Ninja
Expand Down
60 changes: 40 additions & 20 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,34 @@ if (("${CMAKE_CXX_COMPILER_ID}" MATCHES "GNU") OR ("${CMAKE_CXX_COMPILER_ID}" MA
add_compile_options(-Wall -Wextra -pedantic -Werror)
endif()

find_package(OpenGL REQUIRED)
find_package(SDL REQUIRED)
find_package(SDL_image REQUIRED)
find_package(SDL_mixer REQUIRED)
find_package(SDL2 REQUIRED)
find_package(SDL2_image QUIET)
find_package(SDL2_mixer QUIET)

if(NOT SDL2_image_FOUND OR NOT SDL2_mixer_FOUND)
find_package(PkgConfig QUIET)
if(PkgConfig_FOUND AND NOT SDL2_image_FOUND)
pkg_check_modules(SDL2_image IMPORTED_TARGET SDL2_image)
endif()
if(PkgConfig_FOUND AND NOT SDL2_mixer_FOUND)
pkg_check_modules(SDL2_mixer IMPORTED_TARGET SDL2_mixer)
endif()
endif()

if(NOT SDL2_image_FOUND)
message(FATAL_ERROR "SDL2_image not found")
endif()

if(NOT SDL2_mixer_FOUND)
message(FATAL_ERROR "SDL2_mixer not found")
endif()

if(APPLE)
find_library(FRAMEWORK_FOUNDATION Foundation)
endif()

set(C_FILES
audio.c
glSDL.c
menu.c
menuitems.c
preferences.c
Expand Down Expand Up @@ -55,30 +75,30 @@ set_property(TARGET flobopuyo PROPERTY CXX_EXTENSIONS OFF)

target_compile_definitions(flobopuyo
PRIVATE USE_AUDIO
PRIVATE HAVE_OPENGL
PRIVATE DATADIR=\"${CMAKE_SOURCE_DIR}/data\"
)

if(APPLE)
target_compile_definitions(flobopuyo
PRIVATE GL_SILENCE_DEPRECATION
)
endif()

target_include_directories(flobopuyo
PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}
)

target_include_directories(flobopuyo
SYSTEM
PRIVATE ${SDL_INCLUDE_DIRS}
PRIVATE ${SDL_IMAGE_INCLUDE_DIRS}
PRIVATE ${SDL_MIXER_INCLUDE_DIRS}
PRIVATE ${SDL2_INCLUDE_DIRS}
PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS}
PRIVATE ${SDL2_MIXER_INCLUDE_DIRS}
)

target_link_libraries(flobopuyo
${OPENGL_LIBRARIES}
${SDL_LIBRARIES}
${SDL_IMAGE_LIBRARIES}
${SDL_MIXER_LIBRARIES}
target_link_libraries(flobopuyo PRIVATE
$<$<BOOL:${MINGW}>:mingw32>
$<$<BOOL:${APPLE}>:${FRAMEWORK_FOUNDATION}>
SDL2::SDL2main
SDL2::SDL2
#SDL2_image::SDL2_image
#PkgConfig::SDL2_image
#$<IF:$<BOOL:${PkgConfig_FOUND}>,PkgConfig::SDL2_image, PkgConfig::SDL2_image>
$<TARGET_NAME_IF_EXISTS:PkgConfig::SDL2_image>
$<TARGET_NAME_IF_EXISTS:SDL2_image::SDL2_image>
$<TARGET_NAME_IF_EXISTS:PkgConfig::SDL2_mixer>
$<TARGET_NAME_IF_EXISTS:SDL2_mixer::SDL2_mixer>
)
40 changes: 20 additions & 20 deletions InputManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,16 @@ static const SdlKeyName sdlKeyDictionnary[] = {
{ SDLK_ESCAPE, "Escape" },
{ SDLK_SPACE, "Space" },
{ SDLK_DELETE, "Delete" },
{ SDLK_KP0, "KP 0" },
{ SDLK_KP1, "KP 1" },
{ SDLK_KP2, "KP 2" },
{ SDLK_KP3, "KP 3" },
{ SDLK_KP4, "KP 4" },
{ SDLK_KP5, "KP 5" },
{ SDLK_KP6, "KP 6" },
{ SDLK_KP7, "KP 7" },
{ SDLK_KP8, "KP 8" },
{ SDLK_KP9, "KP 9" },
{ SDLK_KP_0, "KP 0" },
{ SDLK_KP_1, "KP 1" },
{ SDLK_KP_2, "KP 2" },
{ SDLK_KP_3, "KP 3" },
{ SDLK_KP_4, "KP 4" },
{ SDLK_KP_5, "KP 5" },
{ SDLK_KP_6, "KP 6" },
{ SDLK_KP_7, "KP 7" },
{ SDLK_KP_8, "KP 8" },
{ SDLK_KP_9, "KP 9" },
{ SDLK_UP, "Up Arrow" },
{ SDLK_DOWN, "Down Arrow" },
{ SDLK_LEFT, "Left Arrow" },
Expand All @@ -50,27 +50,27 @@ static const SdlKeyName sdlKeyDictionnary[] = {
{ SDLK_F13, "F13" },
{ SDLK_F14, "F14" },
{ SDLK_F15, "F15" },
{ SDLK_NUMLOCK, "Num Lock" },
{ SDLK_NUMLOCKCLEAR, "Num Lock" },
{ SDLK_CAPSLOCK, "Caps Lock" },
{ SDLK_SCROLLOCK, "Scroll Lock"},
{ SDLK_SCROLLLOCK, "Scroll Lock"},
{ SDLK_RSHIFT, "Right Shift"},
{ SDLK_LSHIFT, "Left Shift" },
{ SDLK_RCTRL, "Right Ctrl" },
{ SDLK_LCTRL, "Left Ctrl" },
{ SDLK_RALT, "Right Alt" },
{ SDLK_LALT, "Left Alt" },
{ SDLK_RMETA, "Right Meta" },
{ SDLK_LMETA, "Left Meta" },
{ SDLK_RSUPER, "Right Windows" },
{ SDLK_LSUPER, "Left Windows" },
//{ SDLK_RMETA, "Right Meta" },
//{ SDLK_LMETA, "Left Meta" },
{ SDLK_RGUI, "Right Windows" },
{ SDLK_LGUI, "Left Windows" },
{ SDLK_MODE, "Mode Shift" },
{ SDLK_HELP, "Help" },
{ SDLK_PRINT, "Print Screen" },
{ SDLK_PRINTSCREEN, "Print Screen" },
{ SDLK_SYSREQ, "Sys Rq" },
{ SDLK_BREAK, "Break" },
{ SDLK_PAUSE, "Break" },
{ SDLK_MENU, "Menu" },
{ SDLK_POWER, "Power" },
{ SDLK_EURO, "Euro" }
{ SDLK_POWER, "Power" }//,
//{ SDLK_EURO, "Euro" }
};

static const int sdlKeyDictionnarySize = sizeof(sdlKeyDictionnary) / sizeof(SdlKeyName);
Expand Down
2 changes: 1 addition & 1 deletion InputManager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _INPUT_SW_MAN_H
#define _INPUT_SW_MAN_H

#include <SDL_events.h>
#include <SDL2/SDL.h>
#include <cstring>

const int JOYSTICK_THRESHOLD = 25000;
Expand Down
74 changes: 25 additions & 49 deletions IosImgProcess.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "IosImgProcess.h"
#include <SDL_image.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include <cmath>
#include <cstdlib>
#include <cstdio>
Expand All @@ -18,31 +19,29 @@ int imgListSize = 0;
IIM_Surface * IIM_Load_DisplayFormat (const char *fname)
{
char path[1024];
SDL_Surface *tmpsurf, *retsurf;
SDL_Surface *retsurf;
snprintf(path, 1024, "%s/gfx/%s", dataFolder, fname);
tmpsurf = IMG_Load (path);
if (tmpsurf==0) {
retsurf = IMG_Load (path);
if (retsurf==0) {
fprintf(stderr,"Could not load %s\n", path);
exit(1);
}
retsurf = SDL_DisplayFormat (tmpsurf);
SDL_FreeSurface (tmpsurf);
return IIM_RegisterImg(retsurf, false);
}

IIM_Surface * IIM_Load_DisplayFormatAlpha (const char *fname)
{
char path[1024];
SDL_Surface *tmpsurf, *retsurf;
SDL_Surface *retsurf;
snprintf(path, 1024, "%s/gfx/%s", dataFolder, fname);
tmpsurf = IMG_Load (path);
if (tmpsurf==0) {
retsurf = IMG_Load (path);
if (retsurf==0) {
fprintf(stderr,"Could not load %s\n", path);
exit(1);
}
retsurf = SDL_DisplayFormatAlpha (tmpsurf);
SDL_SetAlpha (retsurf, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
SDL_FreeSurface (tmpsurf);
//retsurf = SDL_DisplayFormatAlpha (tmpsurf);
//SDL_SetAlpha (retsurf, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
//SDL_FreeSurface (tmpsurf);
return IIM_RegisterImg(retsurf, true);
}

Expand All @@ -68,29 +67,6 @@ IIM_Surface * IIM_RegisterImg(SDL_Surface *img, bool isAlpha)
return &(imgList[imgListSize++]);
}

void IIM_ReConvertAll(void)
{
for (int i=0; i<imgListSize; ++i)
{
if (imgList[i].surf)
{
if (imgList[i].isAlpha)
{
SDL_Surface *retsurf = SDL_DisplayFormat(imgList[i].surf);
SDL_SetAlpha (retsurf, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
SDL_FreeSurface(imgList[i].surf);
imgList[i].surf = retsurf;
}
else
{
SDL_Surface *retsurf = SDL_DisplayFormat(imgList[i].surf);
SDL_FreeSurface(imgList[i].surf);
imgList[i].surf = retsurf;
}
}
}
}

/** Image processing */

static int max3(int i1, int i2, int i3)
Expand Down Expand Up @@ -342,14 +318,14 @@ IIM_Surface *iim_surface_shift_hue(IIM_Surface *isrc, float hue_offset)
}
SDL_UnlockSurface(ret);
SDL_UnlockSurface(src);
SDL_Surface *ret2 = SDL_DisplayFormatAlpha(ret);
SDL_SetAlpha(ret2, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
SDL_FreeSurface(ret);
ret = isrc->surf;
isrc->surf = SDL_DisplayFormatAlpha(ret);
SDL_SetAlpha(isrc->surf, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
SDL_FreeSurface(ret);
return IIM_RegisterImg(ret2, true);
//SDL_Surface *ret2 = SDL_DisplayFormatAlpha(ret);
//SDL_SetAlpha(ret2, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
//SDL_FreeSurface(ret);
//ret = isrc->surf;
//isrc->surf = SDL_DisplayFormatAlpha(ret);
//SDL_SetAlpha(isrc->surf, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
//SDL_FreeSurface(ret);
return IIM_RegisterImg(ret, true);
}

IIM_Surface *iim_surface_set_value(IIM_Surface *isrc, float value)
Expand All @@ -376,10 +352,10 @@ IIM_Surface *iim_surface_set_value(IIM_Surface *isrc, float value)
}
SDL_UnlockSurface(src);
SDL_UnlockSurface(ret);
SDL_Surface *ret2 = SDL_DisplayFormatAlpha(ret);
SDL_SetAlpha(ret2, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
SDL_FreeSurface(ret);
return IIM_RegisterImg(ret2, true);
//SDL_Surface *ret2 = SDL_DisplayFormatAlpha(ret);
//SDL_SetAlpha(ret2, SDL_SRCALPHA | (useGL?0:SDL_RLEACCEL), SDL_ALPHA_OPAQUE);
//SDL_FreeSurface(ret);
return IIM_RegisterImg(ret, true);
}

void iim_surface_convert_to_gray(IIM_Surface *isrc)
Expand All @@ -397,6 +373,6 @@ void iim_surface_convert_to_gray(IIM_Surface *isrc)
}
}
SDL_UnlockSurface(src);
isrc->surf = SDL_DisplayFormat(src);
SDL_FreeSurface(src);
//isrc->surf = SDL_DisplayFormat(src);
//SDL_FreeSurface(src);
}
4 changes: 1 addition & 3 deletions IosImgProcess.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@ extern "C" {
#include <stdbool.h>
#endif

#include <SDL_stdinc.h>
#include <SDL_video.h>
#include <SDL2/SDL.h>

typedef struct _RGBA {
Uint8 red;
Expand Down Expand Up @@ -63,7 +62,6 @@ IIM_Surface * IIM_Load_DisplayFormat (const char *path);
IIM_Surface * IIM_Load_DisplayFormatAlpha (const char *path);
void IIM_Free(IIM_Surface *img);
IIM_Surface * IIM_RegisterImg(SDL_Surface *img, bool isAlpha);
void IIM_ReConvertAll(void);

#ifdef __cplusplus
}
Expand Down
Loading

0 comments on commit 6bc1435

Please sign in to comment.