Skip to main content
gamedev.net
🔒 Locked

Some coding problems on GL

Started by rosicky2005 Sep 13, 2006 at 1:54 AM 8 replies 1.4k views
Original Post
rosicky2005
rosicky2005
I would like to ask some function usage What is the usage of the function glActiveTexture(GL_TEXTUREi)? Thanks ~
Thaligar
Thaligar
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
Hydrael
Hydrael
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
rosicky2005
rosicky2005
Then what's the rule setting the variable GL_TEXTUREi ?
Hydrael
Hydrael
There actually is no "rule".

GL_TEXTUREi just identifies the texture stage you wish to work with (GL_TEXTURE0 - GL_TEXTURE7).
rosicky2005
rosicky2005
then what is a texture stage?
Digitalfragment
Digitalfragment
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.
rosicky2005
rosicky2005
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?

rapunzel
rapunzel
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)
swiftcoder
swiftcoder
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]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.