changeset 607:f4b37a991dac

using glew to build on Windows
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Apr 2019 16:41:40 +0200
parents d9c0a66304cb
children 357e744c56cc
files Framework/OpenGL/OpenGLIncludes.h Resources/CMake/SdlConfiguration.cmake Samples/Sdl/BasicScene.cpp
diffstat 3 files changed, 24 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/OpenGL/OpenGLIncludes.h	Mon Apr 29 15:29:53 2019 +0200
+++ b/Framework/OpenGL/OpenGLIncludes.h	Mon Apr 29 16:41:40 2019 +0200
@@ -33,12 +33,8 @@
 #  include <OpenGL/gl.h>
 #  include <OpenGL/glext.h>
 #elif defined(_WIN32)
-// On Windows, use the compatibility headers provided by SDL
-#  if ORTHANC_ENABLE_SDL == 1
-#    include <SDL_opengl.h>
-#  else
-#    error Stone cannot be compiled on Windows without SDL
-#  endif
+// On Windows, use the compatibility headers provided by glew
+#  include <GL/glew.h>
 #else
 #  include <GL/gl.h>
 #  include <GL/glext.h>
--- a/Resources/CMake/SdlConfiguration.cmake	Mon Apr 29 15:29:53 2019 +0200
+++ b/Resources/CMake/SdlConfiguration.cmake	Mon Apr 29 16:41:40 2019 +0200
@@ -21,8 +21,15 @@
   SET(SDL_SOURCES_DIR ${CMAKE_BINARY_DIR}/SDL2-2.0.4)
   SET(SDL_URL "http://orthanc.osimis.io/ThirdPartyDownloads/SDL2-2.0.4.tar.gz")
   SET(SDL_MD5 "44fc4a023349933e7f5d7a582f7b886e")
+  DownloadPackage(${SDL_MD5} ${SDL_URL} "${SDL_SOURCES_DIR}")
 
-  DownloadPackage(${SDL_MD5} ${SDL_URL} "${SDL_SOURCES_DIR}")
+  if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
+    SET(GLEW_SOURCES_DIR ${CMAKE_BINARY_DIR}/glew-2.1.0)
+    SET(GLEW_URL "http://orthanc.osimis.io/ThirdPartyDownloads/glew-2.1.0.tgz")
+    SET(GLEW_MD5 "b2ab12331033ddfaa50dc39345343980")
+    DownloadPackage(${GLEW_MD5} ${GLEW_URL} "${GLEW_SOURCES_DIR}")
+  endif()
+  
 
   include_directories(${SDL_SOURCES_DIR}/include)
 
@@ -150,8 +157,12 @@
       ${SDL_SOURCES_DIR}/src/timer/windows/*.c
       ${SDL_SOURCES_DIR}/src/video/windows/*.c
       ${SDL_SOURCES_DIR}/src/windows/dlopen/*.c
+
+      ${GLEW_SOURCES_DIR}/src/glew.c
       )
 
+    include_directories(${GLEW_SOURCES_DIR}/include)
+
     list(APPEND SDL_SOURCES ${TMP})
 
     # NB: OpenGL ES headers are not available in MinGW-W64
@@ -166,6 +177,8 @@
       -DSDL_VIDEO_RENDER_D3D=1
       -DSDL_VIDEO_RENDER_OGL=1
       -DSDL_VIDEO_DRIVER_WINDOWS=1
+
+      -DGLEW_STATIC=1
       )
 
     if (MSVC)
--- a/Samples/Sdl/BasicScene.cpp	Mon Apr 29 15:29:53 2019 +0200
+++ b/Samples/Sdl/BasicScene.cpp	Mon Apr 29 16:41:40 2019 +0200
@@ -348,7 +348,14 @@
 }
 
 
-int main()
+
+
+/**
+ * IMPORTANT: The full arguments to "main()" are needed for SDL on
+ * Windows. Otherwise, one gets the linking error "undefined reference
+ * to `SDL_main'". https://wiki.libsdl.org/FAQWindows
+ **/
+int main(int argc, char* argv[])
 {
   Orthanc::Logging::Initialize();
   OrthancStone::SdlWindow::GlobalInitialize();