Jump to content
  • Advertisement
Sign in to follow this  
PureW

Trouble with alphablending

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

Hello, I'm playing with a 2D space shooter, and I want some motion trails. Because of that I've written a function that draws a few partially transparent textured quads of the space ship before I draw the real ship. If you look at this image: you'll see that the space ship, coloured red and standing still, blends together with the motion trail. I've displaced the ship a few pixels to better see the problem. The white area in the middle shouldn't be there, it should be red like the area to the right. The red ship should overwrite the motion trail but instead it blends together with it. In the main loop I first draw the motion trail with this function:
void Player::doMotionBlur()
{
	int passes = 8;
	float timeSlice = 3.0;

	float accumX = x-timeSlice*vel[0];
	float accumY = y-timeSlice*vel[1];
	//glDrawBuffer( GL_AUX1 );
	//glAccum( GL_LOAD, 1.0 );
	

	for (int i=0; i<passes; ++i )
	{
		accumX += vel[0]*timeSlice/(passes-i);
		accumY += vel[1]*timeSlice/(passes-i);
		//glClear( GL_COLOR_BUFFER_BIT );
		cGr->drawSprite( ship, accumX, accumY, rot, 1.0/i );
		//glAccum( GL_ACCUM, 1.0/passes );
	}
}



After that I draw the real ship with no transparency. And the drawSprite-func looks like this:
void cGraphics::drawSprite( texture& sprite, int x, int y, float rotation, float blended )
{
	float colour=1;
	glColor4f( colour, colour, colour, blended );
	glBindTexture(GL_TEXTURE_2D, sprite.data);
	float depth = -2;
	glBegin( GL_QUADS );	
		glTexCoord2f(0.0, 0.0);	glVertex3f( x, y, depth );
		glTexCoord2f(1.0, 0.0);	glVertex3f( x+sprite.width, y, depth);
		glTexCoord2f(1.0, 1.0);	glVertex3f( x+sprite.width, y+sprite.height, depth );
		glTexCoord2f(0.0, 1.0);	glVertex3f( x, y+sprite.height, depth );
	glEnd();
}





I've set up the blending settings with: glBlendFunc( GL_SRC_ALPHA, GL_ONE ); glEnable( GL_BLEND ); What is the problem? Perhaps there's something wrong with the tga-file. Anyway here is the executable (47kb).

Share this post


Link to post
Share on other sites
Advertisement
It was a simple solution, I changed the glBlendFunc into
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!