Advertisement

How can I make an object semi-transparent?

Started by August 24, 2001 10:38 PM
5 comments, last by GDorazio 23 years, 5 months ago
I am trying to make an object transparent using the alpha bits and can''t seem to make it work. For instance, I want to render a sphere and put latitude and longitude lines on it but I also want to be able to faintly see the lat/lon lines on the other side of the sphere. Does anyone have any sample code or can you point me to one of the tutorials? Thanks, Gery D. Dorazio gdorazio@enque.net
  glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);glEnable(GL_BLEND);/* Render something... */glDisable(GL_BLEND);  


[Resist Windows XP''s Invasive Production Activation Technology!]
Advertisement
Besides doing that, you need to do several other things.

a) Make sure that your object has alpha values.

b) Draw all of your opaque objects first.

c) Disable WRITING to the depth buffer (It needs to be readonly).

d) Do what Null_And_Void said, set the blending mode, and enable blending.

e) Draw all of your semi-transparent objects in order from back to front in relation to you (not a problem if you only have 1 object, or if there is no way you could arrange a viewpoint so that they are lined up.

f) Turn off blending. You are done
-Blackstream Will you, won't you, will you, won't you, won't you take my virus?-The Mad HackerBlackstream's Webpage
If you want more information, check out either the OpenGL Superbible, the Red book, OpenGL Game Programming, or Nehe's tutorial #8.

The link for the latter is
http://nehe.gamedev.net/tutorials/lesson08.asp

Edited by - Blackstream on August 25, 2001 1:32:39 AM
-Blackstream Will you, won't you, will you, won't you, won't you take my virus?-The Mad HackerBlackstream's Webpage
First draw your longitadital lines. Then enable blending and draw the alpha-blended sphere.
glDisable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, EarthMap);
CreateSphere(0, 0, 0, 2, 64);

if ShowClouds = True then
begin
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA,GL_ONE);
glBindTexture(GL_TEXTURE_2D, CloudsMap);
CreateSphere(0, 0, 0, 2.05, 64);
end;

glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
CreateSphere(0, 0, 0, 2.05, 64);

This is the code I used to create a solid Earth sphere, a blended cloud map, and then Lat lines with a line sphere.

Instead of using a clouds map, simply use a Long/Lat map. Oh, and remove the Line Poly Mode segements.
Advertisement
Just wanted to say thanks to all who have replied. I went through them all as well as the tutorial and have been successful implementing the transparency. Thank you.

This topic is closed to new replies.

Advertisement