Skip to content

Instantly share code, notes, and snippets.

@coldtobi
Created October 20, 2014 22:25
Show Gist options
  • Save coldtobi/fb9bbc58799443dc5d12 to your computer and use it in GitHub Desktop.
Save coldtobi/fb9bbc58799443dc5d12 to your computer and use it in GitHub Desktop.
Description: Use system/packaged glew libary
Also, this fixed a bug revealed by the newer glew libary: SDL_GL_* should only
be called after the window created. Also, SDL_GL_MakeCurrent seems necessary.
Author: Tobias Frost <tobi@debian.org>
Forwarded: no
Last-Update: 2014-10-19
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/neo/CMakeLists.txt
+++ b/neo/CMakeLists.txt
@@ -218,6 +218,16 @@
set(JPEG_LIBRARY "" )
endif (JPEG_FOUND)
+# coldtobi: use system glew if available (same logic as for the zlib)
+find_package(GLEW)
+if (GLEW_FOUND)
+ include_directories(${GLEW_INCLUDE_DIRS})
+ set(GLEW_LIBRARY ${GLEW_LIBRARIES})
+else (GLEW_FOUND)
+ include_directories("libs/glew/include")
+ set(GLEW_LIBRARY "" )
+endif (GLEW_FOUND)
+
add_subdirectory(idlib)
file(GLOB AAS_INCLUDES aas/*.h)
@@ -440,17 +450,19 @@
file(GLOB MINIZIP_INCLUDES libs/zlib/minizip/*.h)
file(GLOB MINIZIP_SOURCES libs/zlib/minizip/*.c libs/zlib/minizip/*.cpp)
-set(GLEW_INCLUDES
- libs/glew/include/GL/glew.h)
-
-if(WIN32)
- set(GLEW_INCLUDES ${GLEW_INCLUDES} libs/glew/include/GL/wglew.h)
-else()
- set(GLEW_INCLUDES ${GLEW_INCLUDES} libs/glew/include/GL/glxew.h)
-endif()
-
-set(GLEW_SOURCES
- libs/glew/src/glew.c)
+if (NOT GLEW_FOUND)
+ set(GLEW_INCLUDES libs/glew/include/GL/glew.h)
+ set(GLEW_SOURCES libs/glew/src/glew.c)
+
+ if(WIN32)
+ set(GLEW_INCLUDES ${GLEW_INCLUDES} libs/glew/include/GL/wglew.h)
+ else(WIN32)
+ set(GLEW_INCLUDES ${GLEW_INCLUDES} libs/glew/include/GL/glxew.h)
+ endif(WIN32)
+else (NOT GLEW_FOUND)
+ set(GLEW_INCLUDES "")
+ set(GLEW_SOURCES "")
+endif (NOT GLEW_FOUND)
set(FREETYPE_SOURCES
libs/freetype/src/autofit/autofit.c
@@ -1155,7 +1167,7 @@
add_definitions(-DUSE_DOOMCLASSIC)
add_definitions(-D__DOOM__
- -DGLEW_STATIC
+ #-DGLEW_STATIC
#-DBUILD_FREETYPE
#-DFT2_BUILD_LIBRARY
)
@@ -1187,7 +1199,7 @@
idlib
#libs/curl/include
#libs/openal/include
- libs/glew/include
+ #libs/glew/include
#libs/freetype/include
#libs/zlib
)
@@ -1371,6 +1383,7 @@
${ZLIB_LIBRARY}
${PNG_LIBRARY}
${JPEG_LIBRARY}
+ ${GLEW_LIBRARY}
)
#CMAKE_BINARY_DIR
@@ -1535,6 +1548,7 @@
${ZLIB_LIBRARY}
${PNG_LIBRARY}
${JPEG_LIBRARY}
+ ${GLEW_LIBRARY}
)
endif()
--- a/neo/idlib/precompiled.h
+++ b/neo/idlib/precompiled.h
@@ -86,7 +86,7 @@
// renderer
// RB: replaced QGL with GLEW
-#include "../libs/glew/include/GL/glew.h"
+#include <GL/glew.h>
// RB end
#include "../renderer/Cinematic.h"
#include "../renderer/Material.h"
--- a/neo/sys/sdl/sdl_glimp.cpp
+++ b/neo/sys/sdl/sdl_glimp.cpp
@@ -187,32 +187,6 @@
#if SDL_VERSION_ATLEAST(2, 0, 0)
-#ifdef __APPLE__
- r_useOpenGL32.SetInteger( 2 ); // only core profile is supported on OS X
-#endif
-
- // RB begin
- if( r_useOpenGL32.GetInteger() > 0 )
- {
- glConfig.driverType = GLDRV_OPENGL32_COMPATIBILITY_PROFILE;
-
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 2 );
-
- if( r_debugContext.GetBool() )
- {
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
- }
- }
-
- if( r_useOpenGL32.GetInteger() > 1 )
- {
- glConfig.driverType = GLDRV_OPENGL32_CORE_PROFILE;
-
- SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
- }
- // RB end
-
// DG: set display num for fullscreen
int windowPos = SDL_WINDOWPOS_UNDEFINED;
if( parms.fullScreen > 0 )
@@ -234,23 +208,50 @@
* "do fullscreen, but I don't care on what monitor", at least on my box it's the monitor with
* the mouse cursor.
*/
-
-
+
window = SDL_CreateWindow( GAME_NAME,
windowPos,
windowPos,
parms.width, parms.height, flags );
// DG end
-
+
+ if( !window )
+ {
+ common->DPrintf( "Couldn't set GL mode %d/%d/%d: %s",
+ channelcolorbits, tdepthbits, tstencilbits, SDL_GetError() );
+ continue;
+ }
+
context = SDL_GL_CreateContext( window );
-
- if( !window )
- {
- common->DPrintf( "Couldn't set GL mode %d/%d/%d: %s",
- channelcolorbits, tdepthbits, tstencilbits, SDL_GetError() );
- continue;
- }
-
+ SDL_GL_MakeCurrent(window, context);
+
+#ifdef __APPLE__
+ r_useOpenGL32.SetInteger( 2 ); // only core profile is supported on OS X
+#endif
+
+ // RB begin
+ if( r_useOpenGL32.GetInteger() > 0 )
+ {
+ glConfig.driverType = GLDRV_OPENGL32_COMPATIBILITY_PROFILE;
+
+ SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, 3 );
+ SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, 2 );
+
+ if( r_debugContext.GetBool() )
+ {
+ SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
+ }
+ }
+ // Is a else required here for OPENGL 2.0?
+
+
+ if( r_useOpenGL32.GetInteger() > 1 )
+ {
+ glConfig.driverType = GLDRV_OPENGL32_CORE_PROFILE;
+ SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE );
+ }
+ // RB end
+
if( SDL_GL_SetSwapInterval( r_swapInterval.GetInteger() ) < 0 )
common->Warning( "SDL_GL_SWAP_CONTROL not supported" );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment