Jump to content
  • Advertisement
Sign in to follow this  
danto

Alpha Blending Issue

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

The subject line makes it sound like a simple problem...well maybe it is, but I certainly can't figure it out. I have had alpha textures working in my engine...still do, but I have some that have just plain stopped working. It's not the texture as I've been able to get the same texture working elsewhere. Anyway the problem is this. I have a sprite being drawn and the alpha is appearing black. I have blending enabled with alpha, but it's like it's not picking up the alpha. The strange part is if I manually pull down the alpha by doing a glColor4f(1.0f, 1.0f, 1.0f, 0.5f); the visible pixel colors are faded by half but the black part remains solid...even behind the color part of the image. It's like there is a black sprite behind the sprite I'm drawing if that makes sense. Here is some sample code...
        edgl* dgl = edgl::getInstance();

	glMatrixMode(GL_MODELVIEW);
	glPushMatrix();

	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	glTranslatef(GLfloat(pos.x),GLfloat(pos.y), GLfloat(pos.z));
	glScalef(size.X,size.Y,1.0f);
	glRotatef(rot,0.0f,0.0f,1.0f);

	glBindTexture(GL_TEXTURE_2D, image);

	dgl->drawSprite(); //draws two trianges for a quad

	glPopMatrix();


Now if I add in... glAlphaFunc(GL_GREATER, 0.5); glEnable(GL_ALPHA_TEST); ...it pulls out the alpha of the texture and shows just the color data, but it tends to be a bit harsh on the edges and not as nicely faded as the blend mode. This code was working, but isn't anymore. I have been trying to track down the cause for days with now luck. I understand that there is probably something else in my engine that is causing this behavior, but I just though I would put this out there to see if anyone knew what it might be. I'm hoping it's something simple I'm just overlooking. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
Are you rendering your transparent objects in back-to-front order after all opaque objects are rendered? I have to go soon so can't elaborate right now but I will later if no one else has by then (if this is even the problem).

Share this post


Link to post
Share on other sites
Yes I am drawing in the correct order. I'm not sure that is the problem though...for instance I have a tile grid that is using alphas and that works correctly. I draw the sprite on top of that and it is not coming up transparent.

Example...

Share this post


Link to post
Share on other sites
Absolutely. If I view the image in my resource editor or in the image viewer in the engine it shows it with the alpha transparent, but for some reason as an entity object it is not showing correctly.

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!