Browse Source

Show the detected OpenGL version in the popup dialog when GL2.1 or GLES2 isn't available when the window is created.

Alex Szpakowski 10 years ago
parent
commit
4daa190513
2 changed files with 9 additions and 3 deletions
  1. 8 2
      src/modules/window/sdl/Window.cpp
  2. 1 1
      src/modules/window/sdl/Window.h

+ 8 - 2
src/modules/window/sdl/Window.cpp

@@ -132,7 +132,7 @@ void Window::setGLContextAttributes(const ContextAttribs &attribs)
 	SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, contextflags);
 }
 
-bool Window::checkGLVersion(const ContextAttribs &attribs)
+bool Window::checkGLVersion(const ContextAttribs &attribs, std::string &outversion)
 {
 	typedef unsigned char GLubyte;
 	typedef unsigned int GLenum;
@@ -149,6 +149,8 @@ bool Window::checkGLVersion(const ContextAttribs &attribs)
 	if (!glversion)
 		return false;
 
+	outversion = glversion;
+
 	int glmajor = 0;
 	int glminor = 0;
 
@@ -229,6 +231,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
 	}
 
 	std::string windowerror;
+	std::string glversion;
 
 	// Try each context profile in order.
 	for (ContextAttribs attribs : attribslist)
@@ -320,7 +323,7 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
 		}
 
 		// Make sure the context's version is at least what we requested.
-		if (context && !checkGLVersion(attribs))
+		if (context && !checkGLVersion(attribs, glversion))
 		{
 			SDL_GL_DeleteContext(context);
 			context = nullptr;
@@ -354,6 +357,9 @@ bool Window::createWindowAndContext(int x, int y, int w, int h, Uint32 windowfla
 			std::string title = "Unable to initialize OpenGL";
 			std::string message = "This program requires a graphics card and video drivers which support OpenGL 2.1 or OpenGL ES 2.";
 
+			if (!glversion.empty())
+				message += " \n(Detected OpenGL version: " + glversion + ")";
+
 			std::cerr << title << std::endl << message << std::endl;
 
 			// Display a message box with the error, but only once.

+ 1 - 1
src/modules/window/sdl/Window.h

@@ -118,7 +118,7 @@ private:
 
 	void setGLFramebufferAttributes(int msaa, bool sRGB);
 	void setGLContextAttributes(const ContextAttribs &attribs);
-	bool checkGLVersion(const ContextAttribs &attribs);
+	bool checkGLVersion(const ContextAttribs &attribs, std::string &outversion);
 	bool createWindowAndContext(int x, int y, int w, int h, Uint32 windowflags, int msaa);
 
 	// Update the saved window settings based on the window's actual state.