Jump to content
  • Advertisement
Sign in to follow this  
BrknPhoenix

OpenGL Find out if the user's hardware can run OpenGL programs?

This topic is 4407 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Basically, I just want to check if whatever video card the user has supports OpenGL, and if it doesn't I'd just pop up a message box saying they need an appropriate card. How would I go about getting that information?

Share this post


Link to post
Share on other sites
Advertisement
Try initializing it and if you get an error pop up the appropriate identifier.

It depends on how you initialize an OpenGL surface though... I use SDL

and for that its:

if( SDL_Init(SDL_INIT_VIDEO) < 0 ){
//Pop up your error message and quit
}

and then for opengl (<OTHERFLAGS> should be replaced actual SDL flags):

if(SDL_SetVideoMode(width, height, 32, SDL_OPENGL|<OTHERFLAGS>)==NULL){
//pop your message
atexit(SDL_Quit);
//quit the program
}

I don't know how you'd test without trying to initialize if that's what you are asking.

Share this post


Link to post
Share on other sites
Here is something I whipped up real quick to show how to test for support and capabilities. This is only an example framework but I hope it helps.


// .h
struct VideoCaps
{
int width;
int height;
int colorBits;
int refreshRate;
};

struct GraphicsCaps
{
int colorBits;
int depthBits;
bool doubleBuffer;
};

class GraphicsInfo
{
public:
std::vector<VideoCaps> videoCaps;
std::vector<GraphicsCaps> graphicsCaps;
bool basicSupport;
int videoRam;
std::string vendor;
std::string renderer;
std::string version;
std::string extensions;

bool CheckVideoCaps(void);
bool CheckBasicSupport(void);
bool CheckGraphicsCaps(void);
bool CheckVideoRam(void);

// Add your own query functions here to find info from the
// collected data you want after you run the other functions
};

// .cpp
bool GraphicsInfo::CheckVideoCaps(void)
{
DEVMODE devmode;
VideoCaps caps;
int n = 0;

memset(&devmode, 0, sizeof(DEVMODE));
devmode.dmSize = sizeof(DEVMODE);

videoCaps.clear();

while(EnumDisplaySettings(NULL, n, &devmode))
{
caps.width = devmode.dmPelsWidth;
caps.height = devmode.dmPelsHeight;
caps.colorBits = devmode.dmBitsPerPel;
caps.refreshRate = devmode.dmDisplayFrequency;
videoCaps.push_back(caps);
n++;
}

if(videoCaps.empty())
{
return false;
}

return true;
}

bool GraphicsInfo::CheckBasicSupport(void)
{
HWND window = NULL;
HDC device = NULL;
HGLRC context = NULL;
int format = 0;

PIXELFORMATDESCRIPTOR pfd;

memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 16;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;

window = CreateWindow("BUTTON", NULL, 0, 0, 0, 800, 600, NULL, NULL, NULL, NULL);

if(window == NULL)
{
GetLastError();

return false;
}

device = GetDC(window);

if(device == NULL)
{
GetLastError();

DestroyWindow(window);

return false;
}

format = ChoosePixelFormat(device, &pfd);

if(format <= 0)
{
GetLastError();

ReleaseDC(NULL, device);
DestroyWindow(window);

return false;
}

if(SetPixelFormat(device, format, &pfd) == FALSE)
{
GetLastError();

ReleaseDC(NULL, device);
DestroyWindow(window);

return false;
}

context = wglCreateContext(device);

if(context == NULL)
{
GetLastError();

ReleaseDC(NULL, device);
DestroyWindow(window);

return false;
}

if(wglMakeCurrent(device, context) == FALSE)
{
GetLastError();

wglDeleteContext(context);
ReleaseDC(NULL, device);
DestroyWindow(window);

return false;
}

vendor.assign((char*)glGetString(GL_VENDOR));
version.assign((char*)glGetString(GL_VERSION));
renderer.assign((char*)glGetString(GL_RENDERER));
extensions.assign((char*)glGetString(GL_EXTENSIONS));

wglMakeCurrent(NULL, NULL);
wglDeleteContext(context);
ReleaseDC(NULL, device);
DestroyWindow(window);

return true;
}

bool GraphicsInfo::CheckGraphicsCaps(void)
{
PIXELFORMATDESCRIPTOR pfd;
HDC device = NULL;
int formats = 0;
int result = 0;

device = GetDC(NULL);

if(device == NULL)
{
GetLastError();

return false;
}

memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

formats = DescribePixelFormat(device, 1, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

ReleaseDC(NULL, device);
device = NULL;

if(formats <= 0)
{
GetLastError();

return false;
}

device = CreateDC("DISPLAY", NULL, NULL, NULL);

if(device == NULL)
{
GetLastError();

return false;
}

graphicsCaps.clear();

for(int i = 1; i < formats + 1; i++)
{
memset(&pfd, 0, sizeof(PIXELFORMATDESCRIPTOR));

result = DescribePixelFormat(device, i, sizeof(PIXELFORMATDESCRIPTOR), &pfd);

if(result <= 0)
{
GetLastError();

continue;
}

if( (pfd.dwFlags & PFD_DRAW_TO_WINDOW) &&
(pfd.dwFlags & PFD_SUPPORT_OPENGL) &&
(pfd.iPixelType == PFD_TYPE_RGBA) )
{
GraphicsCaps caps;

caps.colorBits = pfd.cColorBits;
caps.depthBits = pfd.cDepthBits;
caps.doubleBuffer = (pfd.dwFlags & PFD_DOUBLEBUFFER);
graphicsCaps.push_back(caps);
}
}

DeleteDC(device);

if(graphicsCaps.empty())
{
return false;
}

return true;
}

typedef int (WINAPI *DDPROC)(GUID*, LPDIRECTDRAW*, IUnknown*);

bool GraphicsInfo::CheckVideoRam(void)
{
HINSTANCE ddrawDll = NULL;
int vram = 0;

ddrawDll = LoadLibrary("ddraw.dll");

if(ddrawDll != NULL)
{
DDPROC ddrawCreate = NULL;
LPDIRECTDRAW ddraw = NULL;

ddrawCreate = (DDPROC)GetProcAddress(ddrawDll, "DirectDrawCreate");

if((ddrawCreate != NULL) && !FAILED(ddrawCreate(NULL, &ddraw, NULL)))
{
DDCAPS caps;

memset(&caps, 0, sizeof(DDCAPS));
caps.dwSize = sizeof(DDCAPS);

if(IDirectDraw2_GetCaps(ddraw, &caps, NULL) == S_OK)
{
vram = caps.dwVidMemTotal / (1024 * 1024);
}

IDirectDraw_Release(ddraw);
}

FreeLibrary(ddrawDll);
}

videoRam = vram;

return (vram != 0);
}

// Your functions here




You use the basic functions shown to gather your data on available monitor modes, graphics card capabilities, video memory (you need to include ddraw.h to use this trick), and if it even supports a "basic" opengl mode. After you gather this information you can then add your own functions to go over the collected data to see if the system has the requirements the program needs. Let me know if this is what you needed.

[Edited by - Corman on July 27, 2006 2:36:55 PM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!