Multitexturing Problema - FIXED

Started by
4 comments, last by Jinroh 13 years, 7 months ago
Hi all, I have a bit of a conundrum.

I'm rendering a mesh that is two parts, and each part may have one of two different setups for multi-texturing.

//Take this example.
for(int i = 0; i < numMeshePieces; i++){	//Setup MultiTexturing	if(conditionTrue)	{		glActiveTextureARB(GL_TEXTURE0_ARB);		glEnable(GL_TEXTURE_CUBE_MAP);		glBindTexture(GL_TEXTURE_CUBE_MAP, pointer1);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);		glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);		glActiveTextureARB(GL_TEXTURE1_ARB);		glEnable(GL_TEXTURE_2D);		glBindTexture(GL_TEXTURE_2D, pointer2);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);		glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_DOT3_RGB);		glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_PREVIOUS);		glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_TEXTURE);		glActiveTextureARB(GL_TEXTURE2_ARB);		glEnable(GL_TEXTURE_2D);		glBindTexture(GL_TEXTURE_2D, pointer3);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);	}else{		//Texture Stage 0		glActiveTextureARB(GL_TEXTURE0_ARB);		glEnable(GL_TEXTURE_2D);		glBindTexture(GL_TEXTURE_2D, pointer1);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);		//Texture Stage 1		glActiveTextureARB(GL_TEXTURE1_ARB);		glEnable(GL_TEXTURE_1D);		glBindTexture(GL_TEXTURE_1D, pointer2);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);	}	for(int p = 0; p < numPolys; p++) 	{		//DO RENDERING 	}}


If I do the thing like this the first mesh piece will render correctly, but then the subsequent ones will render and not be correct. They'll turn out like Gray. >_>

Must I disable or deactivate the texture stages or something? Any feedback would be appreciated. Thanks. ^^

[Edited by - Jinroh on August 30, 2010 8:40:58 PM]
The wolf and his mate howl, taking solace in the silver moon. Pressing ever foreward to see what the future holds.
Advertisement
Quote:Must I disable or deactivate the texture stages or something?

I think that is part of your answer. Extra texture units will have to unbound or disabled in subsequent stages that do not use them. And for texture units that remain active, make sure their GL_TEXTURE_ENV parameters are correct.

In your code, some parts look a bit suss. For instance:

	}else{		//Texture Stage 0		glActiveTextureARB(GL_TEXTURE0_ARB);		glEnable(GL_TEXTURE_2D);		glBindTexture(GL_TEXTURE_2D, pointer1);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);		//Texture Stage 1		glActiveTextureARB(GL_TEXTURE1_ARB);		glEnable(GL_TEXTURE_1D);		glBindTexture(GL_TEXTURE_1D, pointer2);		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);	}


...is there a reason why have both units enabled? Is GL_TEXTURE_1D intentional (not 2D)? Why use GL_COMBINE_EXT and not GL_COMBINE?

Also, you can do away with glActiveTextureARB or GL_TEXTUREn_ARB, and use glActiveTexture or GL_TEXTUREn instead, unless you are aiming for an old OpenGL version.

General procedure for setting up texture units is as follows:

glActiveTexture(GL_TEXTURE0);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, /*...*/);glTexEnvi(GL_TEXTURE_ENV, /*...*/);/*... more GL_TEXTURE_ENV stuff here... */glActiveTexture(GL_TEXTURE1);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, /*...*/);glTexEnvi(GL_TEXTURE_ENV, /*...*/);/*... more GL_TEXTURE_ENV stuff here... */glActiveTexture(GL_TEXTURE2);glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, /*...*/);glTexEnvi(GL_TEXTURE_ENV, /*...*/);/*... more GL_TEXTURE_ENV stuff here... *//*...render stuff...*/glActiveTexture(GL_TEXTURE2);glDisable(GL_TEXTURE_2D);glActiveTexture(GL_TEXTURE1);glDisable(GL_TEXTURE_2D);glActiveTexture(GL_TEXTURE0);/*...optionally you may disable texture unit 0 here, but it not necessary since you will mostly likely use it elsewhere...*/

Latest project: Sideways Racing on the iPad
Thanks for the reply. ^^ That pipeline code isn't supposed to be accurate it was just an example. I just copy/pasted and put bits and pieces here and there for it.

Would you be able to recommend a place where I can see how to disable/deactivate the texture stages once they are used? Thanks. ^^ I'll get rid of the ARB stuff too. ^^
The wolf and his mate howl, taking solace in the silver moon. Pressing ever foreward to see what the future holds.
Quote:Original post by Jinroh
Would you be able to recommend a place where I can see how to disable/deactivate the texture stages once they are used? Thanks. ^^ I'll get rid of the ARB stuff too. ^^

You disable them the same way you enable them. But instead of enabling them with glEnable, you disable them with... actually, I'll let you figure that one out yourself.
Separate your pieces by your condition as well. For instance,

SetupTexturesTheFirstWay();for(all objects){   if(condition)   {       Draw();   }}SetupTexturesTheSecondWay();for(all objects){   if(!condition)   {       Draw();   }}


This is going to make it so you only changes your texture setup 2 times, rather than switching back and forth. It is also easier to see what is going wrong.

NBA2K, Madden, Maneater, Killing Floor, Sims http://www.pawlowskipinball.com/pinballeternal

Ah I see guys. ^_^ Thanks for the advice.

I'll give it a shot and let you know how it turns out. ^^

EDIT: Got it fixed Guys Thanks for all the help!

[Edited by - Jinroh on August 30, 2010 8:08:42 PM]
The wolf and his mate howl, taking solace in the silver moon. Pressing ever foreward to see what the future holds.

This topic is closed to new replies.

Advertisement