How to read custom extensions for Windows

OpenGL superbible in this example says that I can read custom Windows extensions through:

//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);
}

strstrdoes not accept GLubyte. How to do it?

+2
source share
2 answers

You can simply return the return value glGetStringto a const char pointer and use your favorite string processing functions.

But in fact, I would recommend using a library, for example. GLEW , for managing extensions.

+4
source

glGetString(GL_EXTENSIONS) ( ), . WGL _ Windows ( OpenGL 3.0+). wglGetExtensionsString(HDC), WGL, .

( ARB):

#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;
    }
}

, wglGetExtensionsString() HDC ( Handle to Device) . HDC (HWND);

HDC hdc = ::GetDC(hwnd);
+4

All Articles