Sign in to follow this  
ViperG

Normal Mapping Multi Texturing problem

Recommended Posts

This code works, but only because im using pushatrrib and pop attrib. id like to not use those (push and pop attrib feels like a cheap hack and im not sure how it affects performance) If I take out push and pop attrib, it seems like the multitexturing affects everything drawn after that. It's pretty weird looking.
glPushAttrib( GL_ALL_ATTRIB_BITS  );
			   glActiveTextureARB(GL_TEXTURE0_ARB);
			   glBindTexture (GL_TEXTURE_2D, GameData.Shipdata[ships[index].id].bumptid);
			   glEnable(GL_TEXTURE_2D);
			  
			   
			   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
			   glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_DOT3_RGB_EXT); 
			   glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_TEXTURE);
			   glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
			   glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_PRIMARY_COLOR_EXT); // glColor3f().
			   glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);
				   

			   glActiveTextureARB(GL_TEXTURE1_ARB);
			   glBindTexture(GL_TEXTURE_2D, GameData.Shipdata[ships[index].id].tid);
			   glEnable(GL_TEXTURE_2D);
			   
			   
			   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
			   glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_EXT, GL_MODULATE);
			   glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_EXT, GL_PREVIOUS_EXT);
			   glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_EXT, GL_SRC_COLOR);
			   glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_EXT, GL_TEXTURE);
			   glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_EXT, GL_SRC_COLOR);

			   

				vec2=(vecx*lights.x+vecy*lights.y);

				lights.x=(vec2*0.5f+0.5f);
				lights.y=(vec1*0.5f+0.5f);
				lights.z=0.79f;
			   
                                glColor4f(lights.x,lights.y,lights.z,1);

				glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
				glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);

				glBegin(GL_QUADS);    // Draw A Quad
					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f);
					glVertex3f(-tempx, tempy,0);					// Top Left
					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 1.0f);
					glVertex3f(tempx, tempy,0);					// Top Right
					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f);
					glVertex3f(tempx,-tempy,0);					// Bottom Right
					glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
					glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);
					glVertex3f(-tempx,-tempy,0);					// Bottom Left
				glEnd();
	
                           glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

				// Reset texture unit 0 and 1
			   glActiveTextureARB(GL_TEXTURE1_ARB);
			   glDisable(GL_TEXTURE_2D);

			   glActiveTextureARB(GL_TEXTURE0_ARB);
			   glDisable(GL_TEXTURE_2D);
				

			   glPopAttrib();




Share this post


Link to post
Share on other sites
well usually you don't need it for mutlitexturing. But in my case I do, and i don't understand why that is, no tutorials or code examples shows you need to use push and pop attrib to get multitexturing to work.

Share this post


Link to post
Share on other sites
While it may not be the cause of the problem, if you're worried about the performance hit that extra pushes and pops will incur, you should go ahead and take out the duplicated glEnable(GL_TEXTURE_2D) and glDisable(GL_TEXTURE_2D) calls. Calling each once will do the trick, you don't need to call them on a per texture level basis. Also, I tend to put everything dealing with textures inside of the Enable/Disable pair- it's more symmetric, and it helps me sleep better at night.

Also, what exactly happens without the push/pop? (Screenie?)

-jouley

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this