diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 23adf00a..567d3977 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -22,11 +22,13 @@ endif() if(SFML_BUILD_GRAPHICS) add_subdirectory(opengl) + if (NOT SFML_OS_IOS) add_subdirectory(joystick) add_subdirectory(shader) + add_subdirectory(island) endif() - add_subdirectory(island) + if(SFML_OS_WINDOWS) add_subdirectory(win32) elseif(SFML_OS_LINUX OR SFML_OS_FREEBSD) diff --git a/examples/island/CMakeLists.txt b/examples/island/CMakeLists.txt index 38428e31..3b063fb8 100644 --- a/examples/island/CMakeLists.txt +++ b/examples/island/CMakeLists.txt @@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Island.cpp) # define the island target sfml_add_example(island GUI_APP SOURCES ${SRC} - DEPENDS sfml-graphics sfml-window sfml-system - RESOURCES_DIR resources) \ No newline at end of file + DEPENDS sfml-graphics + RESOURCES_DIR resources) diff --git a/examples/joystick/CMakeLists.txt b/examples/joystick/CMakeLists.txt index f04dc7fc..8d92f03d 100644 --- a/examples/joystick/CMakeLists.txt +++ b/examples/joystick/CMakeLists.txt @@ -7,5 +7,5 @@ set(SRC ${SRCROOT}/Joystick.cpp) # define the joystick target sfml_add_example(joystick GUI_APP SOURCES ${SRC} - DEPENDS sfml-graphics sfml-window sfml-system + DEPENDS sfml-graphics RESOURCES_DIR resources) diff --git a/examples/opengl/CMakeLists.txt b/examples/opengl/CMakeLists.txt index 9b8ad49c..1cdde028 100644 --- a/examples/opengl/CMakeLists.txt +++ b/examples/opengl/CMakeLists.txt @@ -4,8 +4,17 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/opengl) # all source files set(SRC ${SRCROOT}/OpenGL.cpp) +if (SFML_OS_IOS) + set(RESOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/resources/background.jpg + ${CMAKE_CURRENT_SOURCE_DIR}/resources/texture.jpg + ${CMAKE_CURRENT_SOURCE_DIR}/resources/sansation.ttf) + set_source_files_properties(${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) +endif() + # define the opengl target sfml_add_example(opengl GUI_APP SOURCES ${SRC} + BUNDLE_RESOURCES ${RESOURCES} DEPENDS sfml-graphics OpenGL RESOURCES_DIR resources) diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index a1b342f9..bcafba0b 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -18,6 +18,14 @@ #define GL_SRGB8_ALPHA8 0x8C43 #endif +std::string resourcesDir() +{ +#ifdef SFML_SYSTEM_IOS + return ""; +#else + return "resources/"; +#endif +} //////////////////////////////////////////////////////////// /// Entry point of application @@ -44,13 +52,13 @@ int main() // Create a sprite for the background sf::Texture backgroundTexture; backgroundTexture.setSrgb(sRgb); - if (!backgroundTexture.loadFromFile("resources/background.jpg")) + if (!backgroundTexture.loadFromFile(resourcesDir() + "background.jpg")) return EXIT_FAILURE; sf::Sprite background(backgroundTexture); // Create some text to draw on top of our OpenGL object sf::Font font; - if (!font.loadFromFile("resources/sansation.ttf")) + if (!font.loadFromFile(resourcesDir() + "sansation.ttf")) return EXIT_FAILURE; sf::Text text("SFML / OpenGL demo", font); sf::Text sRgbInstructions("Press space to toggle sRGB conversion", font); @@ -64,7 +72,7 @@ int main() // Load a texture to apply to our 3D cube sf::Texture texture; - if (!texture.loadFromFile("resources/texture.jpg")) + if (!texture.loadFromFile(resourcesDir() + "texture.jpg")) return EXIT_FAILURE; // Attempt to generate a mipmap for our cube texture @@ -189,7 +197,7 @@ int main() if (mipmapEnabled) { // We simply reload the texture to disable mipmapping - if (!texture.loadFromFile("resources/texture.jpg")) + if (!texture.loadFromFile(resourcesDir() + "texture.jpg")) return EXIT_FAILURE; mipmapEnabled = false; diff --git a/examples/pong/CMakeLists.txt b/examples/pong/CMakeLists.txt index a20f3b19..54e70c8b 100644 --- a/examples/pong/CMakeLists.txt +++ b/examples/pong/CMakeLists.txt @@ -3,9 +3,16 @@ set(SRCROOT ${PROJECT_SOURCE_DIR}/examples/pong) # all source files set(SRC ${SRCROOT}/Pong.cpp) +if (SFML_OS_IOS) + set(RESOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/resources/ball.wav + ${CMAKE_CURRENT_SOURCE_DIR}/resources/sansation.ttf) + set_source_files_properties(${RESOURCES} PROPERTIES MACOSX_PACKAGE_LOCATION Resources) +endif() # define the pong target sfml_add_example(pong GUI_APP SOURCES ${SRC} + BUNDLE_RESOURCES ${RESOURCES} DEPENDS sfml-audio sfml-graphics RESOURCES_DIR resources) diff --git a/examples/pong/Pong.cpp b/examples/pong/Pong.cpp index 58c9fd71..f643ca4d 100644 --- a/examples/pong/Pong.cpp +++ b/examples/pong/Pong.cpp @@ -8,6 +8,18 @@ #include #include +#ifdef SFML_SYSTEM_IOS +#include +#endif + +std::string resourcesDir() +{ +#ifdef SFML_SYSTEM_IOS + return ""; +#else + return "resources/"; +#endif +} //////////////////////////////////////////////////////////// /// Entry point of application @@ -33,7 +45,7 @@ int main() // Load the sounds used in the game sf::SoundBuffer ballSoundBuffer; - if (!ballSoundBuffer.loadFromFile("resources/ball.wav")) + if (!ballSoundBuffer.loadFromFile(resourcesDir() + "ball.wav")) return EXIT_FAILURE; sf::Sound ballSound(ballSoundBuffer); @@ -63,7 +75,7 @@ int main() // Load the text font sf::Font font; - if (!font.loadFromFile("resources/sansation.ttf")) + if (!font.loadFromFile(resourcesDir() + "sansation.ttf")) return EXIT_FAILURE; // Initialize the pause message