Skip to main content
gamedev.net
🔒 Locked

transparency/beginner question

Started by johnnyboy Mar 7, 2004 at 10:07 AM 0 replies 600+ views
Original Post
johnnyboy
johnnyboy
hi, still working through the tutorials (quite useful!) how would I specify which objects within a certain scene have transparent faces, and those that don''t? I.e., using the crate example, say I wanted two crates -- one 50% alpha (so you can see ''into'' the crate), and the other one totally opaque... how would that be accomplished? maybe it''s just something listed later - but trying glEnable(gl_blend) around the quads, and then disable outside of it doesn''t seem to work... thanks!
!
OrangyTang
OrangyTang
You also need to specify a blend function for blending. This depends on how you want things to look and what surface material you''re trying to display.

First you''ll need to set a transparency value somehow. Typically you can do this via the vertex alpha in the colour. So instead of glColour3f you use the 4f version. 1 is fully opaque and 0 is totally transparent. So you''ll need to set that to 0.5 for 50% transparency.

Assuming you want a glass-like surface, try glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) which basically gets you a weighted avarage of existing colour (your background) and the incomming colour (the crate being drawn). But be aware that this means you will need to sort transparent object back to front or you''ll get weird looking overlaps.
glBlendFunc(GL_SRC_ALPHA, GL_ONE) will get you additive blending, which is great for particles and doesn''t need objects to be sorted.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.