Detecting the graphic card

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. 
The 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.
Now we run the installshield software 
to 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_whql.exe" ,NULL, NULL, SW_SHOWNORMAL );
			else if( strstr( renderer, "ATI" ) != NULL )
				MessageBox( NULL, "You are using the ATI graphic card.
Now we run the installshield software 
to 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
 take a look at the text file loacated
 in the CD-ROM", "Persian Engine Error", MB_OK | MB_ICONINFORMATION  );
			return false;

	return true;

What’s the problem?

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?

Try to convert the string to all uppercases or lowercases with toupper() or tolower() before searching.

And what is going to happen when “ATI” changes to “AMD”?

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!

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

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 ?

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

I guess ATI also has it’s ID

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.

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 :slight_smile:

Jide, from the Zengar page :

NVIDIA’s vendor ID is 0x10DE
So it does not change on each model :slight_smile:

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 !