OpenGL blending process

Started by
6 comments, last by yahn 16 years, 1 month ago
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.
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);//DrawFloorglColor4f(1.0,1.0,1.0, 1.0f);renderFloor();//renderItem//Render Slightly Transparent ObjectglColor4f(1.0,1.0,0.0,0.4f);renderObject();

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?
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.

Previously "Krohm"

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 normallyrender();glColor4f(1.0, 0.0, 0.0, 0.4f); // render the object redrender();


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?
if it is of any help, here is a java programm that visualizes all the blendmodes available in opengl.

http://www.embege.com/blendinspect/
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.
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?

This topic is closed to new replies.

Advertisement