OpenGL上下文存储在哪里?

时间:2022-09-12 20:03:59

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.

我是OpenGL的新手,并且一直使用GLFW和GLEW来创建和显示OpenGL上下文。以下代码片段显示了如何创建窗口并将其用于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?

glewInit如何能够获取窗口/上下文并使用它进行初始化而无需自己传递任何其他参数?

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.

我只能想象当我们调用glfwMakeContextCurrent函数时,它以某种方式将上下文存储在我的进程中的某个地方以供以后使用,但没有文档显示这一点。

1 个解决方案

#1


3  

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.

当前的OpenGL上下文是各种各样的全局(或更多点到点,thread_local)“变量”。所有OpenGL函数都会作用于当前线程中活动的任何上下文。

This includes the OpenGL calls that GLEW makes.

这包括GLEW制作的OpenGL调用。

#1


3  

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.

当前的OpenGL上下文是各种各样的全局(或更多点到点,thread_local)“变量”。所有OpenGL函数都会作用于当前线程中活动的任何上下文。

This includes the OpenGL calls that GLEW makes.

这包括GLEW制作的OpenGL调用。