View Full Version : Detecting the graphic card

Ehsan Kamrani
02-03-2007, 06:13 AM
Hi there
This question doesn't actually refer to the OpenGL. Our testers has detected that the following code finds the graphic card incorrectly. As an example, when using the nvidia graphic card, It reports that the user is using the ATI graphic card:

bool GRAPHICCARD::detect()
char renderer[256] = "";
if( glGetString( GL_VENDOR ) == NULL )
MessageBox( NULL, "Couldn't detect the Graphic Card. \nThe implementation is undefined .", "Persian Engine Error", MB_OK | MB_ICONINFORMATION );
strcpy( renderer, (char*)glGetString( GL_VENDOR ) );
strupr( renderer );
if( strstr( renderer, "MICROSOFT" ) != NULL )
MessageBox( NULL, "The Graphic Card was not installed.", "Persian Engine Error", MB_OK | MB_ICONINFORMATION );

if( strstr( renderer, "NVIDIA" ) != NULL )
MessageBox( NULL, "You are using the NVIDIA graphic card.\nNow we run the installshield software \nto setup your graphic card", "Persian Engine Report", MB_OK | MB_ICONINFORMATION );
//Execute NVIDIA driver here
ShellExecute(NULL, NULL, "Drivers\\NVIDIA\\93.71_forceware_winxp2k_english_w hql.exe" ,NULL, NULL, SW_SHOWNORMAL );
else if( strstr( renderer, "ATI" ) != NULL )
MessageBox( NULL, "You are using the ATI graphic card.\nNow we run the installshield software \nto setup your graphic card", "Persian engine Report", MB_OK | MB_ICONINFORMATION );
//Execute ATI driver here
ShellExecute(NULL, NULL, "Drivers\\ATI\\6-11-pre-r300_xp-2k_dd_ccc_wdm_38185.exe" ,NULL, NULL, SW_SHOWNORMAL);
MessageBox( NULL, "For more information about the graphic card\n take a look at the text file loacated\n in the CD-ROM", "Persian Engine Error", MB_OK | MB_ICONINFORMATION );

return false;

return true;
}What's the problem?

02-03-2007, 07:03 AM
on my card the vendor string is "NVIDIA Corporation", which also contains "ati". it is lowercase, so strstr should return NULL, but you never know...have you displayed and checked the complete string?

02-03-2007, 08:09 AM
Try to convert the string to all uppercases or lowercases with toupper() or tolower() before searching.

02-03-2007, 11:53 AM
And what is going to happen when "ATI" changes to "AMD"?

02-03-2007, 12:34 PM
That's why it is a good idea not to hard code things like this into your application.
strstr just looks for a substring. It might be safer to use strcmp, but again, not a great idea.

Good luck with that!

02-03-2007, 02:34 PM
Hey, this is something related

How can i satart conding openGL on Solaris. Sun delivers an implementation but is just for sparc. is there any implmentation for x86? let`s say amd athlon 64 bits

02-04-2007, 01:34 AM
The thing is that you test "NVIDIA" before "ATI" so maybe some nVIDIA cards are not referenced as "nvidia" but something else with the substring "ati", like "nv corporation" or something like that.

Debug or dump the output under this condition.

RGHP can you explain ?

02-04-2007, 02:23 AM
I have to think about games like Chronicles of Riddick, that fail to accept OpenGL 2.0 as version higher then 1.5 :-/ Such recognition code is bad and will break. On windows, you cold use something like this http://www.developer.nvidia.com/object/device_ids.html

I guess ATI also has it's ID

02-04-2007, 04:32 AM
I'm not sure this is the way to do. This will lead to a problem just like you mention: newer card won't be detected until the game is patched. And uncommon cards will likely not be detected at all.

02-04-2007, 08:34 AM
Well, if each vendor has his own registered ID (not the device ID, but vendor's ID), then at least the vendor recognition should be reliable. Of course, newer cards won't be detected but I don't see any solution to that problem :-)

02-04-2007, 09:46 AM
Jide, from the Zengar page :

NVIDIA's vendor ID is 0x10DESo it does not change on each model :)

02-04-2007, 10:19 AM
I've seen only the second link and gives the id for each card not the vendor. If other links (not looked at them yet) give the vendor id, then it can be a good solution right !