<p>OpenGL is a state machine. An OpenGL context holds that state. The state contains information such as which textures are bound to which texture units, which attachments the current FBO has, and things like that.</p>

<p>When you set the current context, you are switching all the state from the old context to the new context. Here's an example:</p>

<pre><code>glfwMakeContextCurrent(window1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture1);

glfwMakeContextCurrent(window2);
</code></pre>

<p>What this does is makes the context of <code>window1</code> current. It then enables the 2D texture unit and binds <code>texture1</code> to it. </p>

<p>Next it makes the context of <code>window2</code> current. If you were to check the enabled state of <code>GL_TEXTURE_2D</code> it would be false (unless you had previously enabled it on the <code>window2</code> context). Likewise, if you check which texture is bound to the 2D texture unit, you would likely find no texture was bound, or some texture other than <code>texture1</code> was bound.</p>

<p>Basically all drawing happens in the current context. If you make a different context current, then all drawing will now happen in that context.</p>

<p>It is common to have a single context per thread in a multi-threaded OpenGL application. That way each thread is drawing into its own context and doesn't mess up the state of contexts on other threads.</p>

CC BY-SA 3.0
2017-01-17T00:26:54.780Z
I have not more than 15 score points so I cannot vote up your awesome answer. Thanks!!!
Adrian
CC BY-SA 3.0
2017-01-17T00:27:52.163Z
No worries. Glad I could help.
user1118321
CC BY-SA 3.0
2018-02-27T22:48:06.533Z
I read this comment so I joined computergraphics and upvoted this answer.
KANJICODER
CC BY-SA 3.0
2017-01-17T00:05:26.303Z
2017-01-17T00:05:26.303Z
user1118321
<p>I am pretty confused about that function. <a href="http://www.glfw.org/docs/latest/group__context.html#ga1c04dc242268f827290fe40aa1c91157" rel="noreferrer">GLFW Context reference</a> says as follow:<br></p>

<blockquote>
  <p>This function makes the OpenGL or OpenGL ES context of the specified
  window current on the calling thread. A context can only be made
  current on a single thread at a time and each thread can have only a
  single current context at a time.</p>
</blockquote>

<p>But it does not help me much.<br />
Can it work like <a href="https://stackoverflow.com/q/9758884/5744858"><code>glBind-</code></a> methods? (glBindBuffer, glBindVertexArray and so on)</p>

<opengl><c++>
What does "makeContextCurrent" do exactly?
Adrian
# What does "makeContextCurrent" do exactly?

(Asked by: username_0 on 2017-01-16)

I am pretty confused about that function. [GLFW Context reference](http://www.glfw.org/docs/latest/group__context.html#ga1c04dc242268f827290fe40aa1c91157) says as follow:

> This function makes the OpenGL or OpenGL ES context of the specified
> window current on the calling thread. A context can only be made
> current on a single thread at a time and each thread can have only a
> single current context at a time.

But it does not help me much.  
Can it work like [`glBind-`](https://stackoverflow.com/q/9758884/5744858) methods? (glBindBuffer, glBindVertexArray and so on)

**Tags:** opengl, c++


---

## 1 answers

### Answer by username_1 on 2017-01-17. Score: 31 | Accepted answer

OpenGL is a state machine. An OpenGL context holds that state. The state contains information such as which textures are bound to which texture units, which attachments the current FBO has, and things like that.

When you set the current context, you are switching all the state from the old context to the new context. Here's an example:

```
glfwMakeContextCurrent(window1);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture1);

glfwMakeContextCurrent(window2);

```

What this does is makes the context of `window1` current. It then enables the 2D texture unit and binds `texture1` to it.

Next it makes the context of `window2` current. If you were to check the enabled state of `GL_TEXTURE_2D` it would be false (unless you had previously enabled it on the `window2` context). Likewise, if you check which texture is bound to the 2D texture unit, you would likely find no texture was bound, or some texture other than `texture1` was bound.

Basically all drawing happens in the current context. If you make a different context current, then all drawing will now happen in that context.

It is common to have a single context per thread in a multi-threaded OpenGL application. That way each thread is drawing into its own context and doesn't mess up the state of contexts on other threads.

> **Comments:**
> **username_0**: I have not more than 15 score points so I cannot vote up your awesome answer. Thanks!!!  
> **username_1**: No worries. Glad I could help.  
> **username_2**: I read this comment so I joined computergraphics and upvoted this answer.  

---

