2

I am writting a C++ application which works with OpenGL on Mac OS X.

I have tried GLFW and Freeglut for window management.

Both glfw and freeglut have been installed with brew

There is something i do not understand.

Here is my C++ Code for FreeGlut:

int main(int argc, char* argv[]) 
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
    glutInitContextVersion (3, 3);
    glutInitContextFlags (GLUT_CORE_PROFILE | GLUT_DEBUG);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutCreateWindow("Test");

    glewExperimental = GL_TRUE;
    GLenum err = glewInit();
    if (GLEW_OK != err) 
    {
        return -1;
    }

    cout < <"GL_SHADING_LANGUAGE_VERSION: "<< glGetString (GL_SHADING_LANGUAGE_VERSION) << endl;
    ...

There is the output:

GL_SHADING_LANGUAGE_VERSION: 1.20

And here is my C++ code with GLFW:

int main(int argc, const char * argv[])
{
    if (!glfwInit())
    {
        return -1;
    }

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

    glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    window = glfwCreateWindow(640, 480, "Test", NULL, NULL);
    if (window == NULL) {
        return -1;
    }
    glfwMakeContextCurrent(window);

    glewExperimental = true;
    if (glewInit() != GLEW_OK) {
        return -1;
    }

    std::cout << "GL_SHADING_LANGUAGE_VERSION: " << glGetString(GL_SHADING_LANGUAGE_VERSION) << std::endl;

Here is the output:

GL_SHADING_LANGUAGE_VERSION: 4.10

My question is why the GLSL version is not the same ?

Thanks

Bob5421
  • 7,757
  • 14
  • 81
  • 175
  • I never used glut on macOS and I can't test it myself right now, but [OpenGL on OS X](https://pleiades.ucsc.edu/hyades/OpenGL_on_OS_X) and [GLUT on OS X with OpenGL 3.2 Core Profile](https://stackoverflow.com/questions/11259328) indicate hat it has to be `glutInitDisplayMode(GLUT_3_2_CORE_PROFILE | GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)` – t.niese Oct 17 '17 at 20:32

1 Answers1

2

The glut initialization is wrong. GLUT_CORE_PROFILE is not a valid parameter for glutInitContextFlags. The correct code should look like this:

glutInitContextVersion(3, 3);
glutInitContextProfile(GLUT_CORE_PROFILE);
glutInitContextFlags(GLUT_DEBUG);

Source

Also note, that you are not requesting the same profile in both examples. The GLUT examples asks for 3.3 Core with Debug while the glfw example asks for 3.3 Core with Forward Compatibility.

BDL
  • 21,052
  • 22
  • 49
  • 55