PDA

View Full Version : GL_INTERPOLATE_ARB kills me



tetsu
04-16-2002, 01:04 PM
I read the terrain-texturing article on delphi3d.net which introduces the use of the GL_ARB_texture_env_combine extension. The main target with the article was to have "smooth transitions" between two textures. I tried some on my own but couldn't get near the same result as in the demo. Even at minimal scale, it doesn't work; look at this:

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture[1]);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_RGB_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture[0]);

glBegin(GL_QUADS);

glColor4ub(255,255,255,255);
glMultiTexCoord2f(GL_TEXTURE0_ARB,0,1);
glMultiTexCoord2f(GL_TEXTURE1_ARB,0,1);
glVertex3f(-5, 5,0);

glColor4ub(255,255,255,0); glMultiTexCoord2f(GL_TEXTURE0_ARB,1,1);
glMultiTexCoord2f(GL_TEXTURE1_ARB,1,1);
glVertex3f( 5, 5,0);

glColor4ub(255,255,255,0); glMultiTexCoord2f(GL_TEXTURE0_ARB,1,0); glMultiTexCoord2f(GL_TEXTURE1_ARB,1,0);
glVertex3f( 5,-5,0);

glColor4ub(255,255,255,255); glMultiTexCoord2f(GL_TEXTURE0_ARB,0,0);
glMultiTexCoord2f(GL_TEXTURE1_ARB,0,0);
glVertex3f(-5,-5,0);

glEnd();


The result is almost identical to if I had used GL_MODULATE as parameter to GL_TEXTURE_ENV_MODE. Can anyone help me, I'm rather clueless right now... http://www.opengl.org/discussion_boards/ubb/smile.gif

/Tetsu

Tom Nuydens
04-16-2002, 01:25 PM
Your code interpolates based on RGB, but you only ever change alpha. Try setting operand2 to GL_SRC_ALPHA instead of GL_SRC_COLOR.

Also, make sure you set texture0's mode to GL_REPLACE. It might be set to GL_MODULATE with your current setup, which would mean you're not interpolating between tex0 and tex1, but between (tex0*col0) and tex1.

-- Tom

tetsu
04-17-2002, 05:54 AM
That's right, thanks.

Hmm...
No, still no change...
Maybe I have to use GL_SOURCE0_ALPHA_ARB and GL_SOURCE1_ALPHA_ARB also?

|code|
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture[1]);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_RGB_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_INTERPOLATE_ARB);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_PREVIOUS_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB_ARB, GL_SRC_COLOR);

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB_ARB, GL_PRIMARY_COLOR_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB_ARB, GL_SRC_ALPHA);


glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, Texture[0]);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

glBegin(GL_QUADS);

glColor4ub(255,255,255,0);
glMultiTexCoord2f(GL_TEXTURE0_ARB,0,1);
glMultiTexCoord2f(GL_TEXTURE1_ARB,0,1);
glVertex3f(-5, 5,0);

glColor4ub(255,255,255,255);
glMultiTexCoord2f(GL_TEXTURE0_ARB,1,1);
glMultiTexCoord2f(GL_TEXTURE1_ARB,1,1);
glVertex3f( 5, 5,0);

glColor4ub(255,255,255,255);
glMultiTexCoord2f(GL_TEXTURE0_ARB,1,0);
glMultiTexCoord2f(GL_TEXTURE1_ARB,1,0);
glVertex3f( 5,-5,0);

glColor4ub(255,255,255,255);

glMultiTexCoord2f(GL_TEXTURE0_ARB,0,0);
glMultiTexCoord2f(GL_TEXTURE1_ARB,0,0);
glVertex3f(-5,-5,0);

glEnd();

/Tetsu

[This message has been edited by tetsu (edited 04-17-2002).]

tetsu
04-17-2002, 06:18 AM
Hmm, something's REALLY wrong...
This code:

glBegin(GL_QUADS);
glColor4f(0,1,1,0);
glTexCoord2f(0,1);
glVertex3f(-5,5,0);

glColor4f(1,0,1,1);
glTexCoord2f(1,1);
glVertex3f(5,5,0);

glColor4f(1,1,0,1);
glTexCoord2f(1,0);
glVertex3f(5,-5,0);

glColor4f(0,0,1,0);
glTexCoord2f(0,0);
glVertex3f(-5,-5,0);
glEnd();

Produces an all-white quad... I guess there's a setting somewhere that's not right...

/Tetsu

tetsu
04-17-2002, 06:25 AM
Yep, glShadeModel was called with GL_FLAT, that explains it. Let's see if it works now...

/Tetsu

tetsu
04-17-2002, 07:01 AM
One more bad thing...

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_RGB_ARB);

should be

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);

Now I'm getting somewhere http://www.opengl.org/discussion_boards/ubb/smile.gif

/Tetsu