15.010 what is the difference between transparent, translucent, And blended primitives?
A transparent physical material shows objects behind it as unobscured and doesn' t reflect light off its surface. clear glass is a nearly transparent material. although glass allows most light to pass through unobscured, in reality it also reflects some light. A perfectly transparent material is completely invisible.
A translucent physical material shows objects behind it, but those objects are obscured by the translucent material. in addition, a translucent material reflects some of the light that hits it, making the material visible. physical examples of translucent materials include sheer cloth, thin plastic, and smoked glass.
Transparent and translucent are often used synonymously. materials that are neither transparent nor translucent are opaque.
blending is OpenGL's mechanic for combining color already in the framebuffer with the color of the incoming primitive. the result of this combination is then stored back in the framebuffer. blending is frequently used to simulate translucent physical materials. one example is rendering the smoked glass windshield of a car. the driver and Interior are still visible, but they are obscured by the dark color of the smoked glass.
15.020 How can I achieve a transparent effect?
OpenGL doesn't support a direct interface for rendering translucent (partially opaque) primitives. however, you can create a transparency effect with the blend feature and carefully ordering your primitive data. you might also consider using Screen Door transparency .
An OpenGL application typically enables blending as follows:
Glable (gl_blend );
Glblendfunc (gl_src_alpha, gl_one_minus_src_alpha );
after blending is enabled, as shown above, the incoming primitive color is blended with the color already stored in the framebuffer. glblendfunc () controls how this blending occurs. the typical use described abve modifies the incoming color by its associated Alpha value and modifies the destination color by one minus the incoming Alpha value. the sum of these two colors is then written back into the framebuffer.
the primitive's Opacity is specified using glcolor4 *(). RGB specifies the color, and the Alpha parameter specifies the opacity.
when using depth Buffering in an application, you need to be careful about the order in which you render primitives. fully opaque primitives need to be rendered first, followed by partially opaque primitives in back-to-front order. if you don't render primitives in this order, the primitives, which wowould otherwise be visible through a partially opaque primitive, might lose the depth test entirely.
15.030 How can I create Screen Door transparency?
This is accomplished by specifying a polygon stipple pattern with glpolygonstipple () and by rendering the transparent primitive with polygon stippling enabled (glenable )). the number of bits set in the stipple pattern determine the amount of trans0000cy and opacity; setting more bits result in a more opaque object, and setting fewer bits results in a more translucent object. screendoor transparency is sometimes preferable to blending, becuase it's order independent (primitives don't need to be rendered in back-to-front order ).
15.040 How can I render glass with OpenGL?
This question is difficult to answer, because what looks like glass to one person might not to another. What follows is a general algorithm to get you started.
first render all opaque objects in your scene. disable lighting, enable blending, and render your glass geometry with a small Alpha value. this shoshould result in a faint rendering of your object in the framebuffer. (Note: you may need to sort your glass geometry, so it's rendered in back to front Z order .)
Now, you need to add the specular highlight. set your ambient and diffuse material colors to black, and your specular material and light colors to white. enable lighting. set gldepthfunc (gl_equal), then render your glass object a second time.
15.050 Do I need to render my primitives from back to front for correct rendering of translucent primitives to occur?
if your hardware supports destination Alpha, you can experiment with different glblendfunc () settings that use destination Alpha. however, this won't solve all the problems with depth buffered translucent surfaces. the only sure way to achieve always Ally correct results is to sort and render your primitives from back to front.
15.060 I want to use blending but can't get destination Alpha to work. Can I blend or create a transparency effect without destination Alpha?
Using OpenGL devices don't support destination Alpha. In particle, the OpenGL 1.1 Software rendering libraries from Microsoft don't support it. the OpenGL specification doesn't require it.
If you have a system that supports destination Alpha, using it is a simple matter of asking for it when you create your window. for example, pass fig (), then set up a blending function that uses destination Alpha, such:
Glblendfunc (gl_one_minus_dst_alpha, gl_dst_alpha );
Often this question is asked under the mistaken assumption that destination Alpha is required to do blending. it's not. you can use blending in your ways to obtain a transparency effect that uses source Alpha instead of destination Alpha. the fact that you might be on a platform without destination Alpha shouldn't prevent you from obtaining a transparency effect. See OpenGL programming guide Chapter 6 for ways to use blending to achieve transparency.
15.070 If I draw a translucent primitive and draw another primitive behind it, I would CT the second primitive to show through the first, but it's not there?
Is depth buffering enabled?
If You're drawing a polygon that's behind another polygon, and depth test is enabled, then the new polygon will typically lose the depth test, and no blending will occur. on the other hand, if you 've disabled depth test, the new polygon will be blended with the existing polygon, regardless of whether it's behind or in front of it.
15.080 How can I make part of my texture maps transparent or translucent?
It depends on the effect you're trying to achieve.
If you want blending to occur after the texture has been applied, then use the OpenGL blending feature. Try this:
Glable (gl_blend );
Glblendfunc (gl_one, gl_one );
you might want to use the Alpha values that result from texture mapping in the blend function. if so, (gl_src_alpha, gl_one_minus_src_alpha) is always a good function to start.
However, if you want blending to occur when the primitive is texture mapped (I. E ., you want parts of the texture map to allow the underlying color of the primitive to show through), then don't use OpenGL blending. instead, you 'd use gltexenv (), and set the texture environment mode to gl_blend. in this case, you 'd want to leave the texture environment color to its default value of (0, 0, 0 ).