Why is the search from glGetString (GL_EXTENSIONS) not working correctly?

I am reading this page: http://www.opengl.org/wiki/GlGetString

For example, if the extension GL_EXT_pixel_transform_color_table is listed, making a simple search GL_EXT_pixel_transform will return positive, regardless of whether it is defined or not.

How is this possible since its space is divided? Why don't you just put a space after the keyword you are looking for?

For instance:

char *exts = (char *)glGetString(GL_EXTENSIONS);
if(!strstr(exts, "GL_EXT_pixel_transform ")){ // notice the space!
    // not supported
}

I would like to know why this does not work, because for me it works.

+3
source share
3 answers

What if the last extension is listed last? Then there will be no space behind it.

+3
source

, ( API). . Boost.Tokenizer:

typedef boost::tokenizer< boost::char_separator<char> > tokenizer;

boost::char_separator<char> sep(" ");
tokenizer tok(static_cast<const char*>(glGetString(GL_EXTENSIONS)), sep);

if (std::find(tok.begin(), tok.end(), "GL_EXT_pixel_transform") != tok.end()) {
    // extension found
}
+4

, , , , - . - /, , ( ). , ( ):

bool strstrexact(const char *str, const char *substr, const char *delim, const bool isRecursiveCall = 0)
{
    static int substrLen;

    if (!isRecursiveCall)
        substrLen = strlen(substr);

    if (substrLen <= 0)
        return FALSE;

    const char *occurence = strstr(str, substr);

    if (occurence == NULL)
        return FALSE;

    occurence += substrLen;

    if (*occurence == '\0')
        return TRUE;

    const char *nextDelim;
    nextDelim = strstr(occurence, delim);

    if (nextDelim == NULL)
        return FALSE;

    if (nextDelim == occurence)
        return TRUE;

    return strstrexact(nextDelim, substr, delim, TRUE);
}

TRUE, FALSE, . :

if (strstrexact((const char*) glGetString(GL_EXTENSIONS), "WGL_ARB_pixel_format", " ")) {
    // extension is available
} else {
    // extension isn't available
}
+1

All Articles