From 666efd14eeaca1c4685fd4b5666ba17fe16da24a Mon Sep 17 00:00:00 2001 From: Sam Hocevar Date: Tue, 2 Aug 2011 00:27:12 +0000 Subject: [PATCH] gl: use Glew if available. --- configure.ac | 14 ++++++++++++-- src/lolgl.h | 6 ++++-- src/sdlapp.cpp | 10 ++++++++++ src/video.cpp | 2 +- 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 64a1b2f1..4433c9d1 100644 --- a/configure.ac +++ b/configure.ac @@ -104,6 +104,15 @@ if test "${ac_cv_my_have_gl}" = "no"; then AC_MSG_ERROR([[No OpenGL or OpenGL ES implementation found]]) fi +dnl Use Glew? +ac_cv_my_have_glew="no" +PKG_CHECK_MODULES(GLEW, glew, [ac_cv_my_have_glew="yes"], [:]) +if test "${ac_cv_my_have_glew}" != "no"; then + AC_DEFINE(HAVE_GLES_2X, 1, Define to 1 if GLES 2.x is available) + AC_DEFINE(USE_GLEW, 1, Define to 1 to use libglew) +fi +AM_CONDITIONAL(USE_GLEW, test "${ac_cv_my_have_glew}" != "no") + dnl Poor man's GL feature detection. save_LIBS="${LIBS}" LIBS="${LIBS} ${GL_LIBS} ${GLES2_LIBS}" @@ -194,8 +203,9 @@ AM_CONDITIONAL(USE_CPPUNIT, test "$CPPUNIT" = "yes") dnl How to use the Lol Engine inside this tree -LOL_CFLAGS="$LOL_CFLAGS -I \$(top_srcdir)/src $SDL_CFLAGS $EGL_CFLAGS $LIBPNG_CFLAGS" -LOL_LIBS="$LOL_LIBS $SDL_LIBS $EGL_LIBS $LIBPNG_LIBS" +LOL_CFLAGS="$LOL_CFLAGS -I \$(top_srcdir)/src" +LOL_CFLAGS="$LOL_CFLAGS $SDL_CFLAGS $EGL_CFLAGS $GLEW_CFLAGS $LIBPNG_CFLAGS" +LOL_LIBS="$LOL_LIBS $SDL_LIBS $EGL_LIBS $GLEW_LIBS $LIBPNG_LIBS" AC_SUBST(MATH_LIBS) AC_SUBST(LOL_CFLAGS) diff --git a/src/lolgl.h b/src/lolgl.h index 31000bbb..f66181b5 100644 --- a/src/lolgl.h +++ b/src/lolgl.h @@ -24,7 +24,9 @@ #endif /* Include GL */ -#if defined HAVE_GL_2X +#if defined USE_GLEW +# include +#elif defined HAVE_GL_2X # if defined __APPLE__ && defined __MACH__ # include # else @@ -46,8 +48,8 @@ /* Redefine some function names */ #if defined HAVE_GL_2X -# define glClearDepthf glClearDepth #elif defined HAVE_GLES_2X +# define glClearDepth glClearDepthf # define glGenVertexArrays glGenVertexArraysOES # define glDeleteVertexArrays glDeleteVertexArraysOES # define glBindVertexArray glBindVertexArrayOES diff --git a/src/sdlapp.cpp b/src/sdlapp.cpp index 9c6ce404..5f4a40de 100644 --- a/src/sdlapp.cpp +++ b/src/sdlapp.cpp @@ -17,6 +17,7 @@ #endif #include "core.h" +#include "lolgl.h" #include "sdlapp.h" namespace lol @@ -58,6 +59,15 @@ SdlApp::SdlApp(char const *title, vec2i res, float fps) : SDL_Quit(); exit(EXIT_FAILURE); } +#if defined USE_GLEW + GLenum glerr = glewInit(); + if (glerr != GLEW_OK) + { + Log::Error("cannot initialise GLEW: %s\n", glewGetErrorString(glerr)); + SDL_Quit(); + exit(EXIT_FAILURE); + } +#endif SDL_WM_SetCaption(title, NULL); SDL_ShowCursor(0); diff --git a/src/video.cpp b/src/video.cpp index 94592015..c8b3bcf8 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -59,7 +59,7 @@ void Video::Setup(vec2i size) #endif glClearColor(0.1f, 0.2f, 0.3f, 0.0f); - glClearDepthf(1.0); + glClearDepth(1.0); #if defined HAVE_GL_2X glShadeModel(GL_SMOOTH);