Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions about GLFW behavior below GL 3.2

Tags:

opengl

glfw

Following this tutorial starting to learn opengl I have the following source code:

#include <stdio.h>
#include <stdlib.h>
#include <GL/glew.h>
#include <GL/glfw.h>
#include <glm/glm.hpp>

using namespace glm;

int
main(void){
    if(!glfwInit())
    {
        fprintf( stderr, "Failed to initialize GLFW\n" );
        return -1;
    }

    glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.1
    glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 1);
    glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL

    // Open a window and create its OpenGL context
    if(!glfwOpenWindow(1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW))
    {
        int a = glfwOpenWindow(1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW);
          fprintf( stderr, "Failed to open GLFW window\n" );
          glfwTerminate();
          return 1;
    }

}

This always produces the "Failed to open GLFW window" error. I downloaded the source code to see if that would compile and narrowed the difference down to the GLFW_OPENGL_VERSION_MINOR variable.

The program compiles and runs fine if minor is set to 2 or 3 but not if it's set to 1. Is this a bug in GLFW or is there something interesting going on here?

Line 487 of the window.c in glfw source says:

if( wndconfig.glProfile &&
    ( wndconfig.glMajor < 3 || ( wndconfig.glMajor == 3 && wndconfig.glMinor < 2 ) ) )
{
    // Context profiles are only defined for OpenGL version 3.2 and above
    return GL_FALSE;
}

If this is the cause (And it looks like it is) what exactly does this mean and why does it stop the window from being created?

like image 458
J V Avatar asked Nov 28 '25 02:11

J V


1 Answers

Please read the comment message in the source. It says:

Context profiles are only defined for OpenGL version 3.2 and above

The concept of a core profile does not exist in OpenGL 3.1. Therefore, when you ask for version 3.1, you cannot do this:

glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

You're asking for something that simply doesn't exist, so GLFW doesn't let you do it.

If you want a core profile, then ask for GL 3.2 or above. If you ask for a lower GL version, then stop asking for a core profile.

like image 193
Nicol Bolas Avatar answered Dec 01 '25 10:12

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!