|
Post by STT on Dec 13, 2004 23:34:31 GMT -5
How do you draw partially transparent textures?
|
|
|
Post by Tom Not logged in on Dec 14, 2004 0:38:29 GMT -5
You need to use OpenGL "blending". Basic idea is. 1. Enable it: glEnable (GL_BLEND) 2. Choose your transparency function. Typically it's GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, for standard transparency (see the "glBlendFunc" part in any OpenGL reference). glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) 3. Set the alpha component of your colour. This is the 4th parameter of the glColor4f command. 0 corresponds to fully transparent, 1 = fully opaque. glColor4f (1, 1, 1, .5) ' Semi transparent 4. Draw your texture. Here's a simple example. dim tex tex = LoadTexture ("textures\00005.jpg") glEnable (GL_TEXTURE_2D) glBindTexture (GL_TEXTURE_2D, tex)
glEnable (GL_BLEND) glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
TextMode (TEXT_OVERLAID) locate 14, 12: print "Transparency"
dim a# while true glClear (GL_DEPTH_BUFFER_BIT or GL_COLOR_BUFFER_BIT) DrawText () glLoadIdentity () glTranslatef (0, 0, -4) glColor4f (1, 1, 1, sin (a#) * .5 + .5) glBegin (GL_QUADS) glTexCoord2f (0, 0): glVertex2f (-1, -1) glTexCoord2f (1, 0): glVertex2f ( 1, -1) glTexCoord2f (1, 1): glVertex2f ( 1, 1) glTexCoord2f (0, 1): glVertex2f (-1, 1) glEnd ()
while SyncTimer (10) a# = a# + 0.01 wend SwapBuffers () wend
-Tom
|
|
|
Post by fdameron on Dec 14, 2004 12:59:36 GMT -5
If you want to have transparent and non-transparent object then you need to turn off depth sorting prior to drawing the transparent objects and turn it on afterwards and draw the remainder of the objects. This also ensures that no matter what order they are drawn in the effect will still work.
- Floyd
|
|
|
Post by STT on Dec 14, 2004 19:09:59 GMT -5
I thought that the fourth value in glColor4f was transparency, but when I typed it in, it didn't work. Now I know why.
Thanks for that, (although this means another comb through Microsoft's OpenGl refrence.)
EDIT: How do you turn off depth sorting?
|
|