P.Brian.Mackey
P.Brian.Mackey

Reputation: 44275

How to read windows specific extensions

In OpenGL superbible the example says I can read Windows specific extensions via:

//Type defined in the book as char, but that is not what glGetString returns...
const GLubyte *extensions = glGetString(GL_EXTENSIONS);
if(strstr(extensions, "WGL_EXT_swap_control") != NULL)
{
    wglSwapIntervalEXT = (PFNWGLSWAPINTERVALEXTPROC)wglGetProcAddress("wglSwapIntervalEXT");
    if(wglSwapIntervalEXT != NULL)
        wglSwapIntervalEXT(1);
}

strstr does not take GLubyte. How can make this work?

Upvotes: 2

Views: 1695

Answers (2)

song
song

Reputation: 154

glGetString(GL_EXTENSIONS) will return most extensions (separated by spaces) that are supported by the video card. But windows specific WGL_ extensions (for OpenGL version 3.0+) are NOT included with this call. You also need to call wglGetExtensionsString(HDC) to get the rest of WGL extensions supported by the card.

Here is a code snippet (you may remove ARB suffix) :

#include <windows.h>
#include <iostream>
#include <GL/gl.h>

// function ptr: WGL specific extensions for v3.0+
typedef const char* (WINAPI * PFNWGLGETEXTENSIONSSTRINGARBPROC)(HDC hdc);
PFNWGLGETEXTENSIONSSTRINGARBPROC  pwglGetExtensionsStringARB = 0;
#define wglGetExtensionsStringARB pwglGetExtensionsStringARB
...

// get WGL specific extensions for v3.0+
wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
if(wglGetExtensionsStringARB)
{
    const char* str = wglGetExtensionsStringARB(hdc);
    if(str)
    {
        std::cout << str << std::endl;
    }
}

Note that wglGetExtensionsString() requires HDC (Handle to Device Context) of the current window display as a parameter. you can get the HDC from the window handle, (HWND);

HDC hdc = ::GetDC(hwnd);

Upvotes: 4

user786653
user786653

Reputation: 30460

You can just cast the return value of glGetString to a const char pointer and use your favorite string handling functions.

But really I'd recommend using a library, e.g. GLEW, for managing extensions.

Upvotes: 4

Related Questions