
openGL support
Posted Tuesday, 23 March, 2010 - 12:52 by ou7sid3r inHi
I have just started using openTK and am still fairly new to the openGL library as well. I am busy porting over a c++ system into c# but I can't find anything regarding the following problem:
I need to check whether the system on which the application is running supports openGL. If it doesn't, the system must exit. The C++ code looks like this:
if (!QGLFormat::hasOpenGL())
{ qWarning( "This system has no OpenGL support. Exiting.");
return -1;
}
Is it possible with openTK? I've probably not looked in the right places...


Comments
Re: openGL support
OpenTK will throw an exception if an OpenGL context cannot be created for any reason. This is not exactly what you are looking for but we are talking about a truly exceptional condition here: there is no supported platform that does not provide an OpenGL stack.
Moreover, there is no way to check for OpenGL support a-priori. All we can do is attempt to create a temporary OpenGL context (which, I presume, is what Qt does.)
Re: openGL support
Thanks for the quick response.
Where could I catch the exception that openTK would throw - I wouldn't want to wrap my entire application in a try..catch block..?
Otherwise, how could I create a temporary openTK instance within a try..catch block before my main application executes and how efficient would that be?
Re: openGL support
It depends on how and where you create the OpenGL context. For example, if you are using WinForms/GLControl you would have to surround the constructor of the Form that contains the GLControl with a try-catch block. Ditto for GTK#/GLWidget and GameWindow.
You could also try to create a context manually and see if this works:
Note that this should be done before creating any WinForms or GTK# windows on the same thread. The performance hit over the previous method would be in the order of tens of milliseconds in OpenTK 1.0. However, note that very first creation of any GraphicsContext may take up to a second in some cases (this is likely to become better in future versions.)