Browse Source

Add CMake integration for SDL2 sample w/SDL-renderer

Michael Ragazzon 4 years ago
parent
commit
f1eba192ca

+ 17 - 1
CMake/Modules/FindSDL2.cmake

@@ -160,6 +160,22 @@ IF(SDL2_LIBRARY_TEMP)
   SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
   SET(SDL2_LIBRARY_TEMP "${SDL2_LIBRARY_TEMP}" CACHE INTERNAL "")
 ENDIF(SDL2_LIBRARY_TEMP)
 ENDIF(SDL2_LIBRARY_TEMP)
 
 
+if(SDL2_INCLUDE_DIR AND EXISTS "${SDL2_INCLUDE_DIR}/SDL_version.h")
+  file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MAJOR_LINE REGEX "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+[0-9]+$")
+  file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_MINOR_LINE REGEX "^#define[ \t]+SDL_MINOR_VERSION[ \t]+[0-9]+$")
+  file(STRINGS "${SDL2_INCLUDE_DIR}/SDL_version.h" SDL2_VERSION_PATCH_LINE REGEX "^#define[ \t]+SDL_PATCHLEVEL[ \t]+[0-9]+$")
+  string(REGEX REPLACE "^#define[ \t]+SDL_MAJOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MAJOR "${SDL2_VERSION_MAJOR_LINE}")
+  string(REGEX REPLACE "^#define[ \t]+SDL_MINOR_VERSION[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_MINOR "${SDL2_VERSION_MINOR_LINE}")
+  string(REGEX REPLACE "^#define[ \t]+SDL_PATCHLEVEL[ \t]+([0-9]+)$" "\\1" SDL2_VERSION_PATCH "${SDL2_VERSION_PATCH_LINE}")
+  set(SDL2_VERSION ${SDL2_VERSION_MAJOR}.${SDL2_VERSION_MINOR}.${SDL2_VERSION_PATCH})
+  unset(SDL2_VERSION_MAJOR_LINE)
+  unset(SDL2_VERSION_MINOR_LINE)
+  unset(SDL2_VERSION_PATCH_LINE)
+  unset(SDL2_VERSION_MAJOR)
+  unset(SDL2_VERSION_MINOR)
+  unset(SDL2_VERSION_PATCH)
+endif()
+
 INCLUDE(FindPackageHandleStandardArgs)
 INCLUDE(FindPackageHandleStandardArgs)
 
 
-FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR)
+FIND_PACKAGE_HANDLE_STANDARD_ARGS(SDL2 REQUIRED_VARS SDL2_LIBRARY SDL2_INCLUDE_DIR VERSION_VAR SDL2_VERSION)

+ 11 - 0
CMake/SampleFileList.cmake

@@ -126,6 +126,17 @@ set(sdl2_SRC_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2/src/SystemInterfaceSDL2.cpp
     ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2/src/SystemInterfaceSDL2.cpp
 )
 )
 
 
+set(sdl2_sdlrenderer_HDR_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2_sdlrenderer/src/RenderInterfaceSDL2.h
+    ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2_sdlrenderer/src/SystemInterfaceSDL2.h
+)
+
+set(sdl2_sdlrenderer_SRC_FILES
+    ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2_sdlrenderer/src/main.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2_sdlrenderer/src/RenderInterfaceSDL2.cpp
+    ${PROJECT_SOURCE_DIR}/Samples/basic/sdl2_sdlrenderer/src/SystemInterfaceSDL2.cpp
+)
+
 set(sfml2_HDR_FILES
 set(sfml2_HDR_FILES
     ${PROJECT_SOURCE_DIR}/Samples/basic/sfml2/src/RenderInterfaceSFML.h
     ${PROJECT_SOURCE_DIR}/Samples/basic/sfml2/src/RenderInterfaceSFML.h
     ${PROJECT_SOURCE_DIR}/Samples/basic/sfml2/src/SystemInterfaceSFML.h
     ${PROJECT_SOURCE_DIR}/Samples/basic/sfml2/src/SystemInterfaceSFML.h

+ 1 - 1
CMake/gen_samplelists.sh

@@ -8,7 +8,7 @@ srcdir='${PROJECT_SOURCE_DIR}'
 srcpath=Samples
 srcpath=Samples
 samples=( 'shell'
 samples=( 'shell'
 	'basic/animation' 'basic/benchmark' 'basic/bitmapfont' 'basic/customlog' 'basic/databinding' 'basic/demo' 'basic/drag' 'basic/loaddocument' 'basic/treeview' 'basic/transform'
 	'basic/animation' 'basic/benchmark' 'basic/bitmapfont' 'basic/customlog' 'basic/databinding' 'basic/demo' 'basic/drag' 'basic/loaddocument' 'basic/treeview' 'basic/transform'
-	'basic/lottie' 'basic/svg' 'basic/sdl2' 'basic/sfml2'
+	'basic/lottie' 'basic/svg' 'basic/sdl2' 'basic/sdl2_sdlrenderer' 'basic/sfml2'
 	'tutorial/template' 'tutorial/datagrid' 'tutorial/datagrid_tree' 'tutorial/drag'
 	'tutorial/template' 'tutorial/datagrid' 'tutorial/datagrid_tree' 'tutorial/drag'
 	'invaders' 'luainvaders'
 	'invaders' 'luainvaders'
 )
 )

+ 33 - 19
CMakeLists.txt

@@ -701,31 +701,45 @@ if(BUILD_SAMPLES)
 			BUNDLE DESTINATION ${SAMPLES_DIR})
 			BUNDLE DESTINATION ${SAMPLES_DIR})
 	endforeach()
 	endforeach()
 	
 	
-	message("-- Can SDL2 sample be built")
+	message("-- Can SDL2 samples be built")
 	find_package(SDL2)
 	find_package(SDL2)
 	if(SDL2_FOUND)
 	if(SDL2_FOUND)
-	find_package(SDL2_image)
-	if(SDL2_IMAGE_FOUND)
-		find_package(GLEW)
-		if(GLEW_FOUND)
-			message("-- Can SDL2 sample be built - yes")
-			include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
+		find_package(SDL2_image)
+		if(SDL2_IMAGE_FOUND)
+			find_package(GLEW)
+			if(GLEW_FOUND)
+				message("-- Can SDL2 sample w/OpenGL renderer be built - yes")
+				include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR} ${GLEW_INCLUDE_DIR})
+
+				bl_sample(sdl2 ${sample_LIBRARIES}  ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${GLEW_LIBRARIES})
+			
+				# The samples always set this as their current working directory
+				install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/sdl2)
+				install(TARGETS sdl2
+					RUNTIME DESTINATION ${SAMPLES_DIR}/sdl2
+					BUNDLE DESTINATION ${SAMPLES_DIR})
+			else()
+					message("-- Can SDL2 sample w/OpenGL renderer be built - no - GLEW not found")
+			endif()
+			
+			if("${SDL2_VERSION}" VERSION_GREATER_EQUAL "2.0.18")
+				message("-- Can SDL2 sample w/SDL-renderer be built - yes")
+				include_directories(${SDL2_INCLUDE_DIR} ${SDL2_IMAGE_INCLUDE_DIR})
 
 
-			bl_sample(sdl2 ${sample_LIBRARIES}  ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY} ${GLEW_LIBRARIES})
-		
-			# The samples always set this as their current working directory
-			install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/sdl2)
-			install(TARGETS sdl2
-				RUNTIME DESTINATION ${SAMPLES_DIR}/sdl2
-				BUNDLE DESTINATION ${SAMPLES_DIR})
+				bl_sample(sdl2_sdlrenderer ${sample_LIBRARIES} ${SDL2_LIBRARY} ${SDL2_IMAGE_LIBRARY})
+			
+				install(DIRECTORY DESTINATION ${SAMPLES_DIR}/basic/sdl2_sdlrenderer)
+				install(TARGETS sdl2_sdlrenderer
+					RUNTIME DESTINATION ${SAMPLES_DIR}/sdl2_sdlrenderer
+					BUNDLE DESTINATION ${SAMPLES_DIR})
+			else()
+				message("-- Can SDL2 sample w/SDL-renderer be built - no - requires SDL 2.0.18 (found ${SDL2_VERSION})")
+			endif()
 		else()
 		else()
-		        message("-- Can SDL2 sample be built - GLEW not found")
+				message("-- Can SDL2 samples be built - SDL2_image not found")
 		endif()
 		endif()
 	else()
 	else()
-	        message("-- Can SDL2 sample be built - SDL2_image not found")
-	endif()
-	else()
-		message("-- Can SDL2 sample be built - SDL2 not found")
+		message("-- Can SDL2 samples be built - SDL2 not found")
 	endif()
 	endif()
 
 
 
 

+ 2 - 2
Samples/basic/sdl2_sdlrenderer/src/RenderInterfaceSDL2.cpp

@@ -50,8 +50,8 @@ void RmlUiSDL2Renderer::RenderGeometry(Rml::Vertex* vertices, int num_vertices,
     SDL_Texture *sdl_texture = (SDL_Texture *) texture;
     SDL_Texture *sdl_texture = (SDL_Texture *) texture;
 
 
     SDL_Rect r;
     SDL_Rect r;
-    r.x = translation.x;
-    r.y = translation.y;
+    r.x = (int)translation.x;
+    r.y = (int)translation.y;
     r.w = mRenderer_w - r.x;
     r.w = mRenderer_w - r.x;
     r.h = mRenderer_h - r.y;
     r.h = mRenderer_h - r.y;
     
     

+ 7 - 6
Samples/readme.md

@@ -11,7 +11,7 @@ This directory contains the assets shared by all the sample applications.
 #### `basic`
 #### `basic`
 
 
 This directory contains basic applications that demonstrate initialisation, usage, shutdown and installation of custom interfaces.
 This directory contains basic applications that demonstrate initialisation, usage, shutdown and installation of custom interfaces.
- 
+
 -  `animation` animations and transitions
 -  `animation` animations and transitions
 -  `benchmark` a benchmark to measure performance
 -  `benchmark` a benchmark to measure performance
 -  `bitmapfont` using a custom font engine
 -  `bitmapfont` using a custom font engine
@@ -21,24 +21,25 @@ This directory contains basic applications that demonstrate initialisation, usag
 -  `drag` dragging elements between containers
 -  `drag` dragging elements between containers
 -  `loaddocument` loading your first document
 -  `loaddocument` loading your first document
 -  `lottie` playing Lottie animations, only enabled with the [Lottie plugin](https://mikke89.github.io/RmlUiDoc/pages/cpp_manual/lottie.html)
 -  `lottie` playing Lottie animations, only enabled with the [Lottie plugin](https://mikke89.github.io/RmlUiDoc/pages/cpp_manual/lottie.html)
--  `sdl2` integrating with SDL2
+-  `sdl2` integrating with SDL2 using an OpenGL-renderer
+-  `sdl2_sdlrenderer` integrating with SDL2 using a native SDL-renderer
 -  `sfml2` integrating with SFML2
 -  `sfml2` integrating with SFML2
 -  `svg` render SVG images, only enabled with the [SVG plugin](https://mikke89.github.io/RmlUiDoc/pages/cpp_manual/svg.html)
 -  `svg` render SVG images, only enabled with the [SVG plugin](https://mikke89.github.io/RmlUiDoc/pages/cpp_manual/svg.html)
 -  `transform` demonstration of transforms
 -  `transform` demonstration of transforms
 -  `treeview` using data bindings to create a file browser
 -  `treeview` using data bindings to create a file browser
-               
+
 #### `invaders`
 #### `invaders`
 
 
 A full implementation of the 1970s classic Space Invaders using the RmlUi interface.
 A full implementation of the 1970s classic Space Invaders using the RmlUi interface.
-               
+
 #### `luainvaders`
 #### `luainvaders`
 
 
 Lua version of the invaders sample. Only installed with the Lua plugin.
 Lua version of the invaders sample. Only installed with the Lua plugin.
-               
+
 #### `shell`
 #### `shell`
 
 
 Common platform specific code used by all the samples for open windows, processing input and access files. Supports Windows, macOS and Linux.
 Common platform specific code used by all the samples for open windows, processing input and access files. Supports Windows, macOS and Linux.
-               
+
 #### `tutorial`
 #### `tutorial`
 
 
 Tutorial code that should be used in conjunction with the tutorials in the [RmlUi documentation](https://mikke89.github.io/RmlUiDoc/).
 Tutorial code that should be used in conjunction with the tutorials in the [RmlUi documentation](https://mikke89.github.io/RmlUiDoc/).