Jump to content

  • Log In with Google      Sign In   
  • Create Account


glClearColor() and its Alpha value


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 abolfoooud   Members   -  Reputation: 109

Like
0Likes
Like

Posted 14 December 2006 - 11:58 PM

This thread was raised before but unfortunately did not help much. I would like to know how to use the alpha value of glClearColor(). i am doing womething like this // in init glEnable(GL_BLEND); glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA); glClearColor(0,0,0,0); glDisable(GL_BLEND); but it does not give anyeffect. I want to superimpose opengl 3d objects on a bitmap on the background. so i want to make the black background transparent. cheers AF

Sponsor:

#2 coordz   Members   -  Reputation: 130

Like
0Likes
Like

Posted 15 December 2006 - 12:32 AM

The clear colour you set is only used when you do a glClear(). So...

glClearColor(0,0,0,0);

Sets a black background with alpha of zero but doesn't actually change your framebuffer. Then you do

glClear(GL_COLOR_BUFFER_BIT);

which actaully clears the screen. *Then* if you enable blending and set it up

glEnable(GL_BLEND);
glBlendFunc(GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);

and do your drawing now the alpha in your framebuffer will get used. Thing is though is that in your example you set your background to alpha zero then use a blend funtion that assigns your dest alpha (zero) to your source and then 1-dest_alpha (one) to your destination..... so you don't draw anything.

I think what you want to do is to draw a big textured quad first with your background bitmap and then draw your 3d objects. You don;t need to use blending unless you want the edges of you 3d objects blended into your background somehow.

Hope that helps.

#3 abolfoooud   Members   -  Reputation: 109

Like
0Likes
Like

Posted 15 December 2006 - 12:43 AM

Thanx coordz

actually i did not make myself clear. I undestand the solution you gave me but that is not the effect i am after. I want to add 3D effect on an image. I want the user to apply the effects he likes, something like image processing but adding 3D effects rather than 2d. So, i want to have in the background the image (instead of the black!!) then start manipulating 3d objects on top of it.
is that possible to do?

What i was trying to achieve with alpha value in glClearColor is to set the background into total transparent :D but it seems that was too much of creativity :p

cheers
AF

#4 Sharlin   Members   -  Reputation: 860

Like
0Likes
Like

Posted 15 December 2006 - 12:53 AM


for(each frame)
{
glClear(GL_DEPTH_BUFFER_BIT);
glDisable(GL_DEPTH_TEST);
draw a screen-filling textured quad; that's your background

glEnable(GL_DEPTH_TEST);
draw the foreground stuff
}


Of course, if the foreground stuff doesn't need depth testing, you can throw those lines out.

#5 abolfoooud   Members   -  Reputation: 109

Like
0Likes
Like

Posted 15 December 2006 - 01:50 AM

thanx Sharlin for teh suggestion. i think this could be a solution actually.
I did not think about it that way :D

cheers
AF




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS