--- configure.ac.orig	2015-02-04 23:45:45.210532699 +0200
+++ configure.ac	2015-02-05 00:35:41.849792049 +0200
@@ -780,37 +780,6 @@
   fi
 fi
 
-dnl X, GLX and OpenGL
-if test "x$HAVE_X" = "xno"; then
-  if test "x$NEED_GLX" = "xyes"; then
-    AC_MSG_ERROR([Building the GLX backend without X11 is unsupported])
-  fi
-  if test "x$NEED_X11" = "xyes"; then
-    AC_MSG_ERROR([Could not find X11 development libraries])
-  fi
-else
-  if test "x$NEED_GL" != "xno"; then
-    if test "x$HAVE_GL" = "xno"; then
-      if test "x$NEED_GLX" = "xyes"; then
-        AC_MSG_ERROR([Building the GLX backend without the OpenGL backend is unsupported])
-      fi
-    else dnl HAVE_GL=yes
-      if test "x$HAVE_GLU" = "xno"; then
-        if test "x$NEED_GL" = "xyes"; then
-          AC_MSG_ERROR([GLU is required with OpenGL support])
-        else
-          AC_MSG_WARN([GLU is required with OpenGL support])
-        fi
-      else dnl HAVE_GLU=yes
-        USE_OPENGL=yes
-        if test "x$NEED_GLX" != "xno"; then
-          USE_GLX=yes
-        fi
-      fi
-    fi
-  fi
-fi
-
 dnl check if we can include both GL and GLES2 at the same time
 if test "x$HAVE_GL" = "xyes" -a "x$HAVE_GLES2" = "xyes"; then
   GL_INCLUDES="
@@ -850,7 +819,7 @@
     ]])],[ AC_MSG_RESULT(yes)
     ],[AC_MSG_RESULT(no)
     if test "x$NEED_GLES2" = "xyes"; then
-      if test "x$NEED_OPENGL" = "xyes"; then
+      if test "x$NEED_GL" = "xyes"; then
         AC_MSG_ERROR([Cannot seem to include both GL and GLES2 headers. Try disabling one API])
       fi
       AC_MSG_WARN([Disabling Desktop GL support])
@@ -863,6 +832,37 @@
   CPPFLAGS="$save_CPPFLAGS"
 fi
 
+dnl X, GLX and OpenGL
+if test "x$HAVE_X" = "xno"; then
+  if test "x$NEED_GLX" = "xyes"; then
+    AC_MSG_ERROR([Building the GLX backend without X11 is unsupported])
+  fi
+  if test "x$NEED_X11" = "xyes"; then
+    AC_MSG_ERROR([Could not find X11 development libraries])
+  fi
+else
+  if test "x$NEED_GL" != "xno"; then
+    if test "x$HAVE_GL" = "xno"; then
+      if test "x$NEED_GLX" = "xyes"; then
+        AC_MSG_ERROR([Building the GLX backend without the OpenGL backend is unsupported])
+      fi
+    else dnl HAVE_GL=yes
+      if test "x$HAVE_GLU" = "xno"; then
+        if test "x$NEED_GL" = "xyes"; then
+          AC_MSG_ERROR([GLU is required with OpenGL support])
+        else
+          AC_MSG_WARN([GLU is required with OpenGL support])
+        fi
+      else dnl HAVE_GLU=yes
+        USE_OPENGL=yes
+        if test "x$NEED_GLX" != "xno"; then
+          USE_GLX=yes
+        fi
+      fi
+    fi
+  fi
+fi
+
 #dnl Check for OpenGL, GLU
 echo host is $host
 case $host in
@@ -1060,7 +1060,7 @@
     fi
 
     if test "x$HAVE_GL" = "xyes"; then
-      if test "$NEED_GL" != "xno"; then
+      if test "x$NEED_GL" != "xno"; then
         if test "x$HAVE_WGL" = "xyes"; then
           if test "$NEED_WGL" != "xno"; then
             GL_LIBS="$GL_LIBS -lgdi32 -lopengl32 -lglu32"
