View Full Version : how to fade a quad? how to make a cone?
06-16-2005, 12:47 AM
how can i fade a quad? from tranparent to full filled ? my problem is not actually how to fade, thats simple my problem is that i dont know which command to use for fading a quad i tried glcolor4f() but no luck
06-16-2005, 01:12 AM
On nehe.gamedev.net there is a tutorial on alpha blending I guess that should help you.
06-16-2005, 01:15 AM
but i dont want to blend the quad i just want to change its alpha value
try to enable blending before drawing and set correct blending function. Take a look for functions glBlendFunc() and glEnable/glDisable with parameter GL_BLEND.
06-16-2005, 01:52 AM
BUT I DONT WANT TO BLEND THE QUAD WITH ANY OTHER THING I JUST WANT A SEMI TRANSPARENT QUAD AND GLCOLOR4F(R,G,B,A) ISNT WORKING OKEY I >DONT< WANT TO BLEND ANYTHING!!! I JUST WANT TO CHANGE TRANSPARENCY OF A WHOLE QUAD WHENEVER I WANT THATS ALL IM LOOKING FOR JEEZ
Make many quads each one with a different color that fades in or out depending on what you want. Insert them in display lists. Then call quickly them in order to achieve the effect :p
06-16-2005, 02:07 AM
Hey, no need to shout :D
>> GLCOLOR4F(R,G,B,A) ISNT WORKING
Is it better now ?
CWiC has already given you your answer.
Look in the redbook (available under the documentation menu at the main OGL site).
Blending, Antialiasing, and Fog
After reading this chapter, you'll be able to do the following:
Blend colors to achieve such effects as making objects appear translucent
You've already seen alpha values (alpha is the A in RGBA), but they've always been 1.0, and they haven't been discussed. Alpha values are specified with glColor*(), when using glClearColor() to specify a clearing color, and when specifying certain lighting parameters such as a material property or light-source intensity. As you learned in Chapter 5 , the pixels on a monitor screen emit red, green, and blue light, which is controlled by the red, green, and blue color values. So how does an alpha value affect what gets drawn in a window on the screen? When blending is enabled, the alpha value is used to combine the color value of the fragment being processed with that of the pixel already stored in the framebuffer. Blending occurs after your scene has been rasterized and converted to fragments, but just before the final pixels are drawn in the framebuffer. Alpha values can also be used in the alpha test to accept or reject a fragment based on its alpha value. See Chapter 10 for more information about this process.
Without blending, each new fragment overwrites any existing color values in the framebuffer, as though the fragment is opaque. With blending, you can control how much of the existing color value should be combined with the new fragment's value. Thus, you can use alpha blending to create a translucent fragment, one that lets some of the previously stored color value "show through." Color blending lies at the heart of techniques such as transparency, digital compositing, and
And if you still think you don't need blending, think about it this way: you are trying to blend a black quad with the background.
And here's how you enable it:
That will work whether you use an alpha channel in a texture or just from glColor4f. (Texturing is just a way to specify colors at a more detailed level than vertex level).
06-16-2005, 03:08 AM
Thanks ZbuffeR, but:
it disables face culling? I can see my quad from both sides..! I tried to enable it only when working with the quad and later disabling it but it doesnt work all objects are shiny and face culling seems off
06-16-2005, 04:10 AM
>> it disables face culling?
No, face culling is something different. Read the docs :
And the spec as well :
Why do you need to worry about culling you fading quad by the way ?
draw fade quad
Should be ok. Beware that working with stateful graphics can be misleading at times.
06-16-2005, 05:33 AM
looked like it quitted culling (my other objects, they had double faces sides)
well I call glEnable(GL_COLOR_MATERIAL);
I draw the quad and call glDisable(GL_COLOR_MATERIAL); but it doesnt get disabled.. i think I need to call something else before this.. about color material.
heck I just want to fade a quad why is it so hard with opengl? I come from DX though.
06-16-2005, 05:42 AM
It's not hard it's trivially easy, you're just making a complete meal of this.
glDisable lighting, if you've enabled it that's your problem.
use a glBlendFunc of GL_ALPHA, GL_ONE_MINUS_ALPHA
use a GL_MODULATE texenv (the default)
Use glColor4f to your required fade value over time.
Blending is optional if you want to fade to black.
This will work, if you want to fade with lighting and materials etc then glColorMaterial is required. It doesn't affect cull face or any other rubbish.
There's a whole raft of functionality in OpenGL, when you ask to do something the assumption going in is that you have sane state, know what you're doing, and have some control over your own software. When you're offered a solution it's not going to be preceeded with caveats about not doing all the other stuff that might screw it up, the list would be too long and there's too much state to cover.
06-16-2005, 05:47 AM
thank you dorbie you know what youre doing dont you!! i thought about disabling lighting but i didnt knew if that would do the job thanks again :) now i must find a way to put the quad in front of the screen so it covers it all .. i must render it in another matrix? I just say that because I dont want it to move.. im moving my "camera" by moving a matrix first of all then I push and pop render some objects and end up popping maybe its not the best way but ill learn with the time for now it works for what i want i just guess ill need to use ortho instead of gluperspective first of all
06-16-2005, 11:34 AM
well now i got a problem with blending it doesnt blend it just gets to the clear color value when alpha is 0.0 when its 0.5 it doesnt blend with the objects that are behind it..
06-17-2005, 02:27 AM
Are you drawing the other objects first?
When you use blending you need to first draw all the opague objects, and only then the transparent ones.
Hope this helps..
06-17-2005, 02:39 AM
looks like that was the problem thank you!
this opengl state machine is a very real "state" machine but also the position of how you render something changes the output damn this is a mess
06-17-2005, 02:43 AM
i still dont understand why when my quad is close to the camera my fps drops to 300 and when its at the middle of the frustum it runs at 900fps
The drop in speed can be explained with the size of the of the quad. If quad is near to camera, quad covers more pixels on screen and it require more per-pixel work from OpenGL. The more you draw the slower it can be done...
Powered by vBulletin® Version 4.2.3 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.