Hello Guest

Setting up a correct context and catch any errors

  • 1 Replies
  • 4326 Views
Setting up a correct context and catch any errors
« on: August 12, 2019, 07:11:25 »
So, I've had this code for quite some time for setting up my context.

Code: [Select]
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL11.GL_TRUE);

And this has worked fine for the most part. However, if the current GPU does not support these settings, I get a runtimeException on:

Code: [Select]
glfwCreateWindow
I would not like to catch this exception, but would like to check that the demands of the app are met prior to the crash and properly notify the user that their graphics card doesn't support my app.

I thought the hints were just hints and attempt to do the above later on when I've created the context.

Code: [Select]
GLCapabilities g = GL.createCapabilities();
if (!g.OpenGL33) {

String m = "Your graphics card is reported to be: " + glGetString(GL_VENDOR) + ", " + glGetString(GL_RENDERER)
+ ". It has no support for opengl 3.3 If you have several GPUz, try and select the powerful one to run the game.";
throw new ErrorHandler.GameError(m);
}

But it turns out this is too late...

To be frank I don't really know what the above does exactly. I tried to read the opengl documentation, but got instant migranes. And it seems like MacOS (like usual) wants some kind of special treatment.

All I want is opengl-stuff up and including 3.3. I'm not using decrepit stuff or anything fansy. How do I handle this cross platform?

Is it a viable option to just leave the hints out, then check if 3.3 is supported? Am I all set by then? Will a mac like this?


*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Re: Setting up a correct context and catch any errors
« Reply #1 on: August 12, 2019, 09:09:14 »
The typical solution is to first create a dummy context without hints (use a hidden GLFW window). Most drivers will create a context at the maximum supported OpenGL version. Based on that, you can then create the real window/context with the appropriate version/profile/etc.

The above is not applicable to macOS. Above OpenGL 2.1, you need to explicitly ask for the version you require and macOS supports, i.e. OpenGL 3.2 or 4.1 with the core profile. If these versions are not supported on the user's system, I guess your only option is to catch the error and fallback to a lower version.