Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Srekel

Multitexturing problems with GL_INTERPOLATE

This topic is 5131 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

We're trying to draw a skybox that changes from day-texture to night-texture as time goes by. But it just won't work, even though we've look all around the web for help (including the search function here ) Anyways, here is the code that does the stuff:

	glActiveTextureARB(GL_TEXTURE0_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, skyBox0->mTextureNum);

	glActiveTextureARB(GL_TEXTURE6_ARB);
	glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D, skyBoxn0->mTextureNum);

	static float trans = 0.0;
	trans += 0.05;
	GLfloat test[4]={1.0, 1.0, 1.0, fabs(sinf(trans))}; // generate a transparency value between 0 and 1

	glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, test);

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

	glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_RGB_ARB,	GL_TEXTURE0_ARB);
	glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_RGB_ARB,	GL_SRC_COLOR);
	//glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE0_ALPHA_ARB,	GL_CONSTANT_ARB);

	//glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND0_ALPHA_ARB,	GL_SRC_COLOR);

	
	glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_RGB_ARB,	GL_TEXTURE6_ARB);
	glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_RGB_ARB,	GL_SRC_COLOR);
	//glTexEnvi(GL_TEXTURE_ENV,GL_SOURCE1_ALPHA_ARB,	GL_CONSTANT_ARB);

	//glTexEnvi(GL_TEXTURE_ENV,GL_OPERAND1_ALPHA_ARB,	GL_ONE_MINUS_SRC_COLOR);

	
	glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB,	GL_CONSTANT_ARB);
	glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB,	GL_SRC_COLOR);
 
and later we do this:
//I just cut and pasted this code, so not everything is here.

	(*v)[X] = (*camPos)[X]+x;
	(*v)[Y] = (*camPos)[Y]+y;
	(*v)[Z] = (*camPos)[Z]-124.5;
	s = (x+125.f) / 250.0;
	t = 1 - (y+125.f) / 250.0;


	glFogCoordfEXT(calcFog(v));
	glMultiTexCoord2fARB(GL_TEXTURE0_ARB, s, t);
	glMultiTexCoord2fARB(GL_TEXTURE6_ARB, s, t);			
	//glTexCoord2f((x+125.0f)/250,1-(y+125.0f)/250);

	glNormal3fv(*v);
	glVertex3fv(*v);
 
[edited by - Srekel on May 7, 2004 3:37:02 PM]

Share this post


Link to post
Share on other sites
Advertisement
You don''t appear to be using multitexturing correctly. . . You have to bind a texture, then set the multitexturing op for it, bind the next and set its op, and so on.

Perhaps this might work:


// bind and enable the first texture

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, skyBox0->mTextureNum);

// set the combine op to GL_REPLACE

glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB);
glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_RGB_ARB, GL_REPLACE);

// set the source parameter to the currently bound texture

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


// bind the next texture

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, skyBoxn0->mTextureNum);

static float trans = 0.0;
trans += 0.05;
GLfloat test[4]={1.0, 1.0, 1.0, fabs(sinf(trans))};
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, test);

// set the combine op to interpolate

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

// set the first parameter to the result of the previous op

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

// set the second parameter to the currently bound texture

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

// set the last parameter to the constant

glTexEnvf(GL_TEXTURE_ENV,GL_SOURCE2_RGB_ARB, GL_CONSTANT_ARB);
glTexEnvf(GL_TEXTURE_ENV,GL_OPERAND2_RGB_ARB, GL_SRC_COLOR);

Share this post


Link to post
Share on other sites
Also, I think you have to set up the combiner opertaions for Alpha and RGB seperately.


ie:
GL_COMBINE_ALPHA_ARB, GL_SOURCE0_ALPHA_ARB, GL_OPERAND_ALPHA_ARB.

so uncommenting those alpha lines (and changin SRC_COLOR to SRC_ALPHA) and adding

glTexEnvi(GL_TEXTURE_ENV,GL_COMBINE_ALPHA_ARB,GL_INTERPOLATE_ARB);


should work.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!