<blockquote>
<p>But I find that if I comment out the first line, that it appears to have absolutely no effect on my program.</p>
</blockquote>
<p>That's because <code>TEXTURE0</code> happens to be the initial value. It might have an effect if you had previously set a different value.</p>
<p>But more generally, the point of multiple texture units is to be able to use multiple textures simultaneously when drawing (the specific way they are used being determined by your shaders). In that case, you would need to bind each texture with a different active texture unit to be able to use them simultaneously.</p>

CC BY-SA 4.0
2022-10-12T06:40:18.050Z
Can you explain what you mean by "simultaneously"? I've found that so long as I call `glBindTexture()` before `glDrawArrays()`, and put those two things in a loop, that I draw a scene with many different textures just fine. But I'm new at this, and I'm likely making a stupid error or two.
Adam Smith
CC BY-SA 4.0
2022-10-12T14:47:11.877Z
@AdamSmith "Simultaneously" like two different textures both contribute to one pixel's color. For an example of a rendering technique that does that in an obvious visual way, look up "triplanar mapping". Another example might be having multiple textures for multiple material properties, like diffuse versus specular reflectivity, or normal mapping.
Kevin Reid
CC BY-SA 4.0
2022-10-12T15:00:51.477Z
@AdamSmith: Remember: textures are not pictures. They are multidimensional lookup tables used to represent values that contribute to the lighting equation. A texture can mean *anything* to a particular shader; it *could* represent a color, or the roughness of a surface at that position, or a normal, or any number of things. It all depends on how the texture is used. As such, a shader is not restricted to using only one lookup table at a time.
Nicol Bolas
CC BY-SA 4.0
2022-10-12T05:40:55.977Z
2022-10-12T05:40:55.977Z
Kevin Reid
<p>I'm using OpenGL 4.30 with JOGL (in Java). I'm playing with basic texturing, trying to learn how it's done.</p>
<p>The textbook I'm using has the following code:</p>
<pre><code>gl.glActiveTexture(GL_TEXTURE0); // is this line necessary?
gl.glBindTexture(GL_TEXTURE_2D, textureID);
gl.glDrawArrays(GL_TRIANGLES, 0, 3);
</code></pre>
<p>This works well enough. But I find that if I comment out the first line, that it appears to have absolutely no effect on my program. So what is its point? Can the GPU only hold a limited number of textures at once, and I'm using #0 to hold the texture referred to by <code>textureID</code>? If I keep reusing the same constant <code>GL_TEXTURE0</code> for all of my textures, does that mean that I'm slowing everything down? Or is this just to support legacy code, and I don't need to call this function at all? I'm very confused as to why this line is needed, and what it's doing.</p>

<opengl><texture><java>
Is glActiveTexture() still needed?
Adam Smith
# Is glActiveTexture() still needed?

(Asked by: username_0 on 2022-10-12)

I'm using OpenGL 4.30 with JOGL (in Java). I'm playing with basic texturing, trying to learn how it's done.

The textbook I'm using has the following code:

```
gl.glActiveTexture(GL_TEXTURE0); // is this line necessary?
gl.glBindTexture(GL_TEXTURE_2D, textureID);
gl.glDrawArrays(GL_TRIANGLES, 0, 3);

```

This works well enough. But I find that if I comment out the first line, that it appears to have absolutely no effect on my program. So what is its point? Can the GPU only hold a limited number of textures at once, and I'm using #0 to hold the texture referred to by `textureID`? If I keep reusing the same constant `GL_TEXTURE0` for all of my textures, does that mean that I'm slowing everything down? Or is this just to support legacy code, and I don't need to call this function at all? I'm very confused as to why this line is needed, and what it's doing.

**Tags:** opengl, texture, java


---

## 1 answers

### Answer by username_1 on 2022-10-12. Score: 1 | Accepted answer

> But I find that if I comment out the first line, that it appears to have absolutely no effect on my program.

That's because `TEXTURE0` happens to be the initial value. It might have an effect if you had previously set a different value.

But more generally, the point of multiple texture units is to be able to use multiple textures simultaneously when drawing (the specific way they are used being determined by your shaders). In that case, you would need to bind each texture with a different active texture unit to be able to use them simultaneously.

> **Comments:**
> **username_0**: Can you explain what you mean by "simultaneously"? I've found that so long as I call `glBindTexture()` before `glDrawArrays()`, and put those two things in a loop, that I draw a scene with many different textures just fine. But I'm new at this, and I'm likely making a stupid error or two.  
> **username_1**: @username_0 "Simultaneously" like two different textures both contribute to one pixel's color. For an example of a rendering technique that does that in an obvious visual way, look up "triplanar mapping". Another example might be having multiple textures for multiple material properties, like diffuse versus specular reflectivity, or normal mapping.  
> **username_2**: @username_0: Remember: textures are not pictures. They are multidimensional lookup tables used to represent values that contribute to the lighting equation. A texture can mean *anything* to a particular shader; it *could* represent a color, or the roughness of a surface at that position, or a normal, or any number of things. It all depends on how the texture is used. As such, a shader is not restricted to using only one lookup table at a time.  

---

