1

There is something strange happening with gl3w's isSupported function. When I call isSupported(4, 0) it returns false, meaning OpenGL 4.0 isn't supported. However, when I call glGetString(GL_VERSION) it says OpenGL version 4.0. Does this mean I can use OpenGL 4.0 functions?

I'm using gl3w in C++ and Visual Studio 2017

#include <GL/gl3w.h>
#include <GLFW/glfw3.h>

int main(int argc, char** argv){



    if(!glfwInit()) {
        FATAL_ERROR("Failed to initialise GLFW");
    }

    glfwSetErrorCallback(glfwErrorCallback);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);

    GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGL", nullptr, nullptr);

    //If i put glfwMakeContextCurrent here gl3wInit fails
    //glfwMakeContextCurrent(window);

    if (!window) {
        glfwTerminate();
        FATAL_ERROR("Window creation failed");
    }

    if(!gl3wInit()) {} // handle that

    glfwMakeContextCurrent(window);

    bool support = gl3wIsSupported(4, 0);  // returns false

    const char* version = glGetString(GL_VERSION); // return "4.0.0"
}
Ripi2
  • 7,031
  • 1
  • 17
  • 33
obwan02
  • 113
  • 10

3 Answers3

3

You have to make a GL context current before you call gl3wInit() or regular OpenGL functions otherwise they won't do anything useful.

genpfault
  • 51,148
  • 11
  • 85
  • 139
3

In the OpenGL wiki you can read:

The GL3W library focuses on the core profile of OpenGL 3 and 4. It only loads the core entrypoints for these OpenGL versions. It supports Windows, Mac OS X, Linux, and FreeBSD.

Note: GL3W loads core OpenGL only by default. All OpenGL extensions will be loaded if the --ext flag is specified to gl3w_gen.py.

And this is confirmed looking inside the code:

int gl3wIsSupported(int major, int minor)
{
    if (major < 3) // <<<<=========== SEE THIS
        return 0;
    if (version.major == major)
        return version.minor >= minor;
    return version.major >= major;
}

You are asking with glfwWindowHint for an old 2.0 version. Thus, gl3wIsSupported will return false and gl3wInit will return GL3W_ERROR_OPENGL_VERSION.


For glGetString(GL_VERSION) returning "4.0" means that, yes, you can use that 4.0 version. Ask for it with glfwWindowHint.

Ripi2
  • 7,031
  • 1
  • 17
  • 33
1

I fixed it by switching over to glad instead

if (!glfwInit()) {
    FATAL_ERROR("Failed to initialise GLFW");
}

glfwSetErrorCallback(glfwErrorCallback);

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);

GLFWwindow* window = glfwCreateWindow(640, 480, "OpenGL", nullptr, nullptr);


if (!window) {
    glfwTerminate();
    FATAL_ERROR("Window creation failed");
}

glfwMakeContextCurrent(window);
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
    glfwDestroyWindow(window);
    glfwTerminate();
    FATAL_ERROR("Failed to initialise OpenGL context");
}


PRINT("OpenGL Version: " << GLVersion.major << "." << GLVersion.minor);
obwan02
  • 113
  • 10