Some coding problems on GL

Started by
8 comments, last by swiftcoder 17 years, 7 months ago
I would like to ask some function usage What is the usage of the function glActiveTexture(GL_TEXTUREi)? Thanks ~
Advertisement
with glActiveTexture(GL_TEXTUREi) you activate a specific texture slot, every following texture related function will work on the activated texture slot,

example:

glActiveTexture(GL_TEXTURE2);
glBindTexture(TextureID);

with this you'll bind TextureID to texture slot 2,

greets,
tgar
If you want to use multitexturing, glActiveTexture is one of the functions you will need.
It tells, what texture stage (0-7) you want to use for enabling/disabling texturing, or binding textures.

You could look at this neighbour thread for a practical example
Then what's the rule setting the variable GL_TEXTUREi ?
There actually is no "rule".

GL_TEXTUREi just identifies the texture stage you wish to work with (GL_TEXTURE0 - GL_TEXTURE7).
then what is a texture stage?
texture stage is another way of describing the texture unit.

In multitexturing, this is referring to any one of the textures that may be simultaneously loaded and used at once. These are indicated by the enumerations GL_TEXTURE0, GL_TEXTURE1 ... GL_TEXTUREi.
Is that means if I have to call glActiveTexture() twice,

I can do: glActiveTexture(GL_TEXTURE1);
glActiveTexture(GL_TEXTURE0);

or :glActiveTexture(GL_TEXTURE2);
glActiveTexture(GL_TEXTURE4);

which I can use which GL_TEXTUREi not yet used as I like in any time?

You can call glActiveTexture() as often as you want, but just switching between the texture units doesn't make any sense unless you do something with the texture unit you just activated. What you do with glActiveTexture() ist telling OpenGL that from now texture operations like glBindTexture() work on the unit you just activated. So what you basicly do for multitexturing is activate your the first texture unit you want to use, prepare the texture for it, then activate the next unit, prepare it's texture and so on ... And then when you are drawing you just tell every vertex wich are their tex coords for each texture unit you wanna use via glMultiTexCoord2i(GL_TEXTUREi, u, v)
And, of course, you either have to set up texture combining state, or use a shader, to get anything other than the first texture unit to do anything.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement