Reputation: 23
I am fairly new to OpenGL and have been using GLFW combined with GLEW to create and display OpenGL contexts. The following code snippet shows how I create a window and use it for OpenGL.
GLFWwindow* window;
if (!glfwInit())
{
return -1;
}
window = glfwCreateWindow(1280, 720, "Hello OpenGL", NULL, NULL);
if (!window)
{
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
GLenum err = glewInit();
if (err != GLEW_OK)
{
glfwTerminate();
return -1;
}
How is glewInit
able to fetch the window/context and use it to initialize without myself having to pass any additional arguments to it?
I can only imagine that when we call the glfwMakeContextCurrent
function it somehow stores the context somewhere within my process for later use, but no documentation shows this.
Upvotes: 2
Views: 527
Reputation: 473272
The current OpenGL context is a global (or more to the point, thread_local
) "variable" of sorts. All OpenGL functions act on whatever context is active in the current thread at the moment.
This includes the OpenGL calls that GLEW makes.
Upvotes: 3