Querying OpenGL: Version and Extensions

OpenGL exists in a variety of versions, and different vendors have created extensions that other vendors don’t support. So how do you tell what verions of OpenGL you have, and what extensions can you use?

OpenGL lets you query its capabilities via the function glGetString(), which returns a string you can examine. Set the argument to the function to determine what OpenGL will tell you. GL_VERSION and GL_EXTENSIONS are the ones we’re interested in right now.

The single line of code NSLog(@"OpenGL Version %s", glGetString(GL_VERSION)); will tell you the version of OpenGL you have. My machine returns OpenGL Version 2.1 NVIDIA-1.6.18, so I’ve got an NVIDIA graphics card.

Here’s the code to develop the list of extensions.

   NSLog(@"Now checking extensions...");
   NSString *extensionString = [NSString 
     stringWithCString:(const char*)glGetString(GL_EXTENSIONS) 
   NSArray *extensions = [extensionString componentsSeparatedByString:@" "];
   NSString *extensionsInHTML;
   extensionsInHTML = [extensions componentsJoinedByString:@"</li>\n<li>"];
   NSLog(@"<ol>\n<li>%@</li>\n</ol>", extensionsInHTML);

Yes, I was in full nerd mode writing code to create HTML markup. My machine has 122 extensions, so I’ll spare you my list: you’re interested in your machine, of course.

This entry was posted in OpenGL. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s