Jump to content
  • Advertisement
Sign in to follow this  
CNBABY

OpenGL about multitexture

This topic is 4796 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hello,everybody i just know that using OpenGL extensions ARB_multitexture and ARB_texture_env_combine in conjunction with specially encoded vertex colors to blend multiple textures together. if i use glMultiTexCoord2fARB(),i would indicate the coordinations of texture directly.Now i want to generate the coordinations automatically like as glTexgen().how could i do? could you help me?is there any other method? please!

Share this post


Link to post
Share on other sites
Advertisement
Any calls you make to enable texgen or set the texgen mode are applied to the currently active texture unit - i.e. the one you set with glActiveTexture(). So setting up texgen for multiple texture units really is not that different from setting them up for a single texture unit.

Share this post


Link to post
Share on other sites
Yeah, Once you have loaded the textures into opengl, you can multitexture them.

You load the textures normally, just like you would load any texture to texture a quad. It's how you draw them thats differen't.


glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture1);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture2);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD);

glBegin(GL_QUADS);
---->Draw Quad here
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0, 0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0, 0);
glVertex3f(-1.0f,0.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1, 0);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1, 0);
glVertex3f(-1.0f,1.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,1, 1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1, 1);
glVertex3f(1.0f,1.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB,0, 1);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0, 1);
glVertex3f(1.0f,0.0f,0.0f);
glEnd();

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);




Share this post


Link to post
Share on other sites
hi,ViperG and Myopic Rhino :
your mean is that , after i call glActiveTextureARB(),then i could set texgen for the corresponding texture.

i guess the code is:
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture1);
float x[] = { 2.0f, 0.0f, 0.0f, 0.0f };
float y[] = { 0.0f, 2.0f, 0.0f, 0.0f };
float z[] = { 0.0f, 0.0f, 2.0f, 0.0f };
float w[] = { 0.0f, 0.0f, 0.0f, 2.0f };
glTexGenfv( GL_S, GL_EYE_PLANE, x );
glTexGenfv( GL_T, GL_EYE_PLANE, y );
glTexGenfv( GL_R, GL_EYE_PLANE, z );
glTexGenfv( GL_Q, GL_EYE_PLANE, w );

glTexGeni( GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );
glTexGeni( GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );
glTexGeni( GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );
glTexGeni( GL_Q, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );

glEnable( GL_TEXTURE_GEN_S );
glEnable( GL_TEXTURE_GEN_T );
glEnable( GL_TEXTURE_GEN_R );
glEnable( GL_TEXTURE_GEN_Q );


glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture2);
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_ADD);

glBegin(GL_QUADS);
---->Draw Quad here

glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0, 0);
glVertex3f(-1.0f,0.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1, 0);
glVertex3f(-1.0f,1.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,1, 1);
glVertex3f(1.0f,1.0f,0.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0, 1);
glVertex3f(1.0f,0.0f,0.0f);
glEnd();

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable( GL_TEXTURE_GEN_S );
glDisable( GL_TEXTURE_GEN_T );
glDisable( GL_TEXTURE_GEN_R );
glDisable( GL_TEXTURE_GEN_Q );
glDisable(GL_TEXTURE_2D);


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!