Sign in to follow this  

How can I make my sprite(texture) blink with different colors?

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

Like when it takes damage and the main character blinks on a yellow color..how can I do it? the only thing I know do is change the material color of the poly where the sprite is being textured..But I can't change the sprite color homogeneously in this way ( like turn all the colors yellow, and not just 'influencing' its original colors... ) Heres what im doing:

	glBindTexture( GL_TEXTURE_2D, texturehandle[3] );//sprite
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
			glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );

			glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//

			glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, m_sprite_STND->w, m_sprite_STND->h, 0,
							GL_RGBA, GL_UNSIGNED_BYTE, m_sprite_STND->pixels );

...

	GLfloat mabcolors2[]={ 1.0f, 1.0f, 1.0f, 1.0f };//white/transparent
	GLfloat mscolors2[] = {1.0f, 1.0f, 1.0f, 1.0f };//yellow
		glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, mabcolors2);
		//glMaterialf(GL_FRONT, GL_SHININESS, 50.0f);
		glMaterialfv(GL_FRONT, GL_SPECULAR, mscolors2);

...


		glEnable(GL_BLEND);
			glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		glDisable(GL_CULL_FACE);
		//glDisable(GL_DEPTH_TEST);



			//glBlendFunc(GL_SRC_ALPHA, GL_ZERO  );
			//glBlendFunc (GL_ONE, GL_ONE);
		
	glBegin(GL_QUADS);
		glNormal3f(0.0f, 0.0f, -1.0f);
		glColor4f( 1.0f, 1.0f, 0.0f, 0.5f );

		
			glTexCoord2f(	dl,	 0.0f	);
		glVertex3f(-16.0f, 100.0f, -500.0f);
			glTexCoord2f(	ur,	 0.0f	);
		glVertex3f( 16.0f, 100.0f, -500.0f);
			glTexCoord2f(	ur,	 1.0f	);
		glVertex3f( 16.0f, 132.0f, -500.0f);
			glTexCoord2f(	dl,	 1.0f	);
		glVertex3f( -16.0f, 132.0f, -500.0f);
		
	glEnd();

		//glEnable(GL_DEPTH_TEST);
		glEnable(GL_CULL_FACE);
		glDisable(GL_BLEND);







Share this post


Link to post
Share on other sites
If I'm understnding this right, you want your fragment to have the alpha from the texture, but a colour you supply from somewhere else. This will leave a solid coloured cut-out in the shape of your sprite.

You could look at using glBlendFuncSeparate()

This lets you pick how the RGB and the ALPHA channels are combined by supplying a value representing the equation for each of the SRC and DEST parts. You can then specify the constant colour to use as part of the operation using glBlendColor().

Share this post


Link to post
Share on other sites

Ah, maybe texture combiners might be easier to use.

float colour[4]={ 1.0, 1.0, 0.0, 1.0 }; // solid yellow
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, colour);
// this sets your solid colour


glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_COMBINE);


glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_CONSTANT);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOUR);

// this says please use the solid colour as the RGB source for the blend

glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);

// this says please use the texture's alpha value for the blend

glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);

// this says don't use any other values, just go with SOURCE0


And then you can just do the normal alpha-blending to get your sprite's transparency to work.

Share this post


Link to post
Share on other sites
How about GL_MODLUATE ,and change color of the sprite accordingly.

ex,

... glTex--GL_MODLUATE...

if(playerHIT){ glColor3f(1,0,0); WaitSomeTime(); playerHIT = false; }

Share this post


Link to post
Share on other sites
"How about GL_MODLUATE"

That would fail the "like turn all the colors yellow, and not just 'influencing' its original colors..." part of the requirement.

Share this post


Link to post
Share on other sites

This topic is 3153 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.

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