Jump to content
  • Advertisement
Sign in to follow this  
yahn

OpenGL OpenGL blending process

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

I thought there would be a lot more information about this topic. Maybe I'm just looking in all the wrong places, but I cannot find any information about the functions necessary for blending. What I'm doing right now is:
glEnable(GL_BLEND);
glColor4f(r, g, b, a);

render();

glColor4f(1.0, 1.0, 1.0, 1.0);
glDisable(GL_BLEND);
This is blending how I want when I do this one time, but the next texture I render with this process screws everything up. So I'm assuming that I need to do something more at the end, but I cannot seem to find what I should do. Can anyone help? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
You can't render like that because the second thing that draws will overwrite whatever is in the colour buffer.

What you need to do is to do something like


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

//DrawFloor
glColor4f(1.0,1.0,1.0, 1.0f);
renderFloor();
//renderItem

//Render Slightly Transparent Object
glColor4f(1.0,1.0,0.0,0.4f);
renderObject();


Share this post


Link to post
Share on other sites
I'm not sure what you are suggesting? I'm not using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); because this deals particularly with text, and it makes it more difficult to read when I add that. Also, why is there no RGBA? I want to blend it with a particular color. Finally, what is floor?

Share this post


Link to post
Share on other sites
Quote:
Original post by yahn
This is blending how I want when I do this one time, but the next texture I render with this process screws everything up.
Please be more accurate. If you ask a generic question you'll get a generic (and generally useless) answer.
Generally blending will need a special back-to-front sort which I believe isn't going on. Whatever your result looks ok or not is a matter of the exact dataset being used.
What do you mean by "render the next texture"? If you're multipassing, you'll likely have to play a bit with Z.
Quote:
Original post by Neutrinohunter
You can't render like that because the second thing that draws will overwrite whatever is in the colour buffer.
It should if the Z is left untouched... but I fear it isn't.
I agree however he should rethink his draw order.
Quote:
Original post by yahn
I'm not sure what you are suggesting? I'm not using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); because this deals particularly with text, and it makes it more difficult to read when I add that.
Sure it does, you're fetching alpha for it. If you're using textured quads the alpha tipically comes from the texture and not from geometry... This is why there's no RGBA. Besides you shouldn't use immediate mode you should at least resist from using them that way.
Quote:
Original post by yahn
I want to blend it with a particular color.
Maybe you need the constant blend color? I've never really used it much but I believe it could be it.
Quote:
Original post by yahn
Finally, what is floor?
I suppose it's an example of something which provides a background to your blending.

Share this post


Link to post
Share on other sites
I'm not changing the Z coords. Basically, I'm trying to create a function that can render a texture blended with a color. For example, I have a string stored in a texture that I want to be able to render as red or blue. What is the process of functions I need to call?


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

glColor4f(1.0, 1.0, 1.0, 1.0f); // render the object once normally
render();

glColor4f(1.0, 0.0, 0.0, 0.4f); // render the object red
render();


That renders the texture at a lower alpha without changing it's color. However, it is not causing the color buffer error from before. How do I get it to actually render it red?

Share this post


Link to post
Share on other sites
Quote:
Original post by yahn
...
Basically, I'm trying to create a function that can render a texture blended with a color. For example, I have a string stored in a texture that I want to be able to render as red or blue.
...
In that case you most likely don't want to use blending at all. Simply setting the texture environment mode to GL_MODULATE (the default) and then changing the primary color (glColor3f) should do what you want. That will multiply the texture's color by the primary color, so if the texture is white (1,1,1) and you set the primary color to cyan (0,1,1), the resulting color will be cyan as well.

Share this post


Link to post
Share on other sites
That works, but everything after is drawn in that color as well. I tried clearing the color buffer and then setting the glColor4f(1.0, 1.0f, 1.0f, 1.0f); but that didn't change anything. How do I get it to go back to drawing without the color?

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!