Skip to main content
gamedev.net
🔒 Locked

Multitexturing with Environment Mapping

Started by howbizarre79 1 reply 700+ views
Original Post
howbizarre79
howbizarre79
Hi, I am using the GL extensions for MultiTexturing and Cubic Environment Mapping. What I want to know is that when using the extensions for MultiTexturing we need to specify the Active Texture number and then do the binding as : glActiveTextureARB(GL_TEXTURE0_ARB); glBindTexture(GL_TEXTURE_2D, TextureID); Now let us assume that the TextureID is the ID of the texture that I want to apply to a box. Now how can I specify that the next texture to be blended with this one is the Environment Map. If I only specify my Active Texture as above and Enable Environment Mapping, then the only texture that appears on the objects is the Environment Map. Regards.
extralongpants
extralongpants
Using glTexEnv() functions, you can change the way the texture units are blended together. Here's an example of what your situation might look like:

glActiveTextureARB(GL_TEXTURE0_ARB); //the first texture unitglBindTexture(GL_TEXTURE_2D, mainTextureID); //bind the main textureglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); //here's an example of glTexEnv()glActiveTextureARB(GL_TEXTURE1_ARB); //the next texture unitglBindTexture(GL_TEXTURE_CUBE_MAP, cubeMapID); //now bind your cube mapglTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); //tell openGL to generate tex coordinates for you (i don't know if this is what you want)glEnable(GL_TEXTURE_GEN_S); // "glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);// "glEnable(GL_TEXTURE_GEN_T);// "//now draw everythingfor(i =0; i <numVerts; ++i){    glMultiTexCoordARB(GL_TEXTURE0, texCoord.s, texCoord.t);    glVertex3f(vertex.x, vertex.y, vertex.z);}//now disable texture coordinate generationglActiveTextureARB(GL_TEXTURE1);glDisable(GL_TEX_GEN_S);glDisable(GL_TEX_GEN_T);//restore the first texture unitglActiveTextureARB(GL_TEXTURE0);


I've never used cubic environment mapping, but it should look something like that. I'm not quite sure if texture coordinate generation only affects the active texture unit, but I hope so. Well, I hope that helps. Good luck.
James Trotter
James Trotter
Quote:
Original post by howbizarre79
If I only specify my Active Texture as above and Enable Environment Mapping, then the only texture that appears on the objects is the Environment Map.


Now, that's exactly what the glActiveTexture() call is for. It changes the texture unit on which all of the subsequent calls relating to textures affect. For instance:

glActiveTexture(GL_TEXTURE0);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, texture[0]);glEnable(GL_TEXTURE_GEN_S);glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);glActiveTexture(GL_TEXTURE1);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, texture[1]);glEnable(GL_TEXTURE_GEN_T);glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);


This is just an example, and in itself is probably practically useless. But let me explain what happens. First, texture unit 0 is activated, texturing is enabled, and a texture is bound. Texture coordinate generation is enabled for the s-coordinate.

Now, the second block of code changes the active texture unit to GL_TEXTURE1. Texturing is enabled, and another texture is bound. But the texture is bound to GL_TEXTURE1, and GL_TEXTURE0 still holds the first texture we bound. Then texture coordinate generation is enabled for the t-coordinate, but only for GL_TEXTURE1.

If you want to combine the textures in different ways, you'll have to look into the glTexEnv function. You might also want to take a look at the GL_TEXTURE_ENV_COMBINE_ARB extension.

Topic Locked

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

Sign in to reply to this topic.