GLFW Context Profile Error

Im trying to start using opengl I’m running into some problems.

After running this code

#include "glad/glad.h"
#include <GLFW/glfw3.h>
#include <iostream>

static void glfwError(int id, const char* description) {
  std::cout << description << std::endl;
}

int main() {
  glfwSetErrorCallback(&glfwError);
  glfwInit();
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

  
  GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGl", NULL, NULL );  
  if (window == NULL) {
    glfwTerminate();
    return -1;
  }

  glfwMakeContextCurrent(window);
  
  if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
    std::cout << "Failed to initialize GLAD" << std::endl;
    return -1;
  }

  glViewport(0, 0, 800, 600);


  while (!glfwWindowShouldClose(window)) {
    glfwSwapBuffers(window);
    glfwPollEvents();
  }

  glfwTerminate();
  
  return 0;
}

compiling with
g++ hello_window.cpp glad.c -o prova -lGL -lglfw3

I get this output launching the executable:
Context profiles are only defined for OpenGL version 3.2 and above

It seems to mean that I don’t have access to OpenGl 3.2 and above but running
inxi -b | grep API
results in the output
API: OpenGL v: 4.6.0 vendor: nvidia v: 565.77

Thanks to anyone that can help me.

When debugging any programming issue it is often useful to compare the information that the system provides about the problem with expectations about what it was supposed to do. In this case: the system tells you Context profiles are only defined for OpenGL version 3.2 and above, but presumably you wanted to to get a OpenGL 3.3 context in the first place. That suggest carefully looking at where you specify the context version to create:

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

… and there’s your typo, one of those line should probably read:

glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
1 Like

Oh my god I can’t believe it.

I was so sure to have done that properly…

Welp, three days for nothing I guess.

Thank you so much for your kind response given to such a dumb individual.

Have a good day.