How to test for OpenGL?

I’m enabling an OpenGL context for my component, but on some computers it just gives a black window. Any ideas on how to detect this?

Comment says:

// some stupidly old drivers are missing this function, so try to at least avoid a crash here,
// but if you hit this assertion you may want to have your own version check before using the
// component rendering stuff on such old drivers.
jassert (context.extensions.glActiveTexture != nullptr);

If I test just after openGLContext.attachTo() I get 0xcdcdcdcd meaning the variable hasn’t been initialized yet, so I can’t test here. If I call context.extensions.initialise() and then test, I get nullptr even if the system has OpenGL. So I can’t do that.

Only thing I’ve found that works is starting a timer, and then checking glActiveTexture. This way I still get the assert, but at least I know OpenGL isn’t working and can fall back to software rendering.

But this seems dangerous since the thread that starts up OpenGL might be slow and happen after my timer fires.

Is there any fool proof way to know if OpenGL works or not?

An approach I’ve used is to:

  • Create a test component with 1x1 px size, positioned in the corner of the window. This component should hold an OpenGLContext.
  • Give the OpenGLContext a custom renderer. This renderer will simply check some of the context’s extension function pointers in the first paint callback, and then use MessageManager::callAsync to report back whether or not the context supports all the features that are required.
  • When the callback is fired, the owner of the test component can delete the test component, and then either create a real OpenGL context, or fall back to a software renderer.
1 Like

Bumping this thread, ran into the issue and am honestly a bit lost as to how to perform the steps mentioned in this reply. Does anyone have any sample code?

Also, how to even test this? Do I need to disable OpenGL (somehow) on my machine?

I’ve found OpenGL doesn’t work over a remote desktop connection, so if you have a second machine, you can test that way.

1 Like

Oh wow alright, there’s an angle - will try! Tanks