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) encoding:NSASCIIStringEncoding]; 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.