Code Snippets
What's That?
I am using it actively
I planning to use/learn it
I don't plan to lean/use it
5th option
Home :: Programming :: Code Snippets :: OpenGL :: Check for OGL acceleration

[ Check for OGL acceleration ]

As the title says it, in this snippet I will show you how to check if the user's graphics card is OpenGL accelerated or not. Doing this is not very difficult. If the card is not accelerated you could for example close the application or warn the user that he/she will probably run into problems. It might also be useful while debugging. This function only works under Windows.

I will create a function that checks whether the card is Hardware accelerated or not. The function is called IsCardAccelerated().. very original, eh? The basic idea is the following: we will enumerate all available pixel formats and then we will check if they are GL accelerated and return true if yes, otherwise false. Here's the code:

bool IsCardAccelerated()
   //structure that holds info about a pixel format
   //HW accelerated yes or not
   bool isAccelerated = false;
   //Very important to set this variable.. Windows seems
   //not to be able to do this itself;)
   pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
   //Device Conext of the window you want to draw in
   //must be the same as the one you use to draw GL
   HDC hDC = GetDC(hWnd);
   //number of available pixel formats
   int nFormatCount = DescribePixelFormat(hDC, 1, 0, NULL);
   //Go through all available pixel formats and check..
   for(int i = 1; i <= nFormatCount; i++)
      //Get description of pixel format
      DescribePixelFormat(hDC, i, pfd.nSize, &pfd);
      //Not generic?
      if (!(pfd.dwFlags & PFD_GENERIC_FORMAT))
         //It's HW accelerated!!!!!
         isAccelerated = true;
         //We can stop here, as there is at least one acc. pixel format
   return isAccelerated;

Simply copy this function in your code and you will be able to see whether the user has a good, OpenGL accelerated card or a 7 years-old one with good old EGA graphics :-). As I said before, we simply enumerate all pixel formats of our Device Context and check whether it is accelerated or not. If yes, we immediately return true as the card has at least one accelerated pixel format.

That's all. I hope this function will be useful for you. If you have suggestions, comments or you've found a bug, m@il me. Happy Coding!

 Last edited 2002-12-07 20:16:45 by André Stein - printable version
» copyright by andré stein
» using stCM v1.0
» steinsoft.net revision 5.0