Transparency.dpr 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. {: A basic sample to demonstrate how transparency & Z-buffer work/fight together.
  2. In this sample, only the sphere are transparent. The form has a few options
  3. that allow to adjust in which order objects are rendered, and what kind of
  4. transparency is used.
  5. Transparency in GLScene is activated by setting Material.Blending to either
  6. 'bmTransparency' or 'bmAdditive', AND giving a <1.0 value to the Diffuse
  7. color alpha channel (alpha = 0.0 means absolute transparency, alpha = 1.0
  8. means absolute opacity).
  9. How do Z-Buffer & transparency work ? When point has to be rendered, OpenGL
  10. first checks its distance to the camera, the "Z" axis. If the distance
  11. check is successfull (the new point is closer), it is rendered, and if
  12. the point is part of a "transparent" object, then OpenGL will mix the existing
  13. point's color with our new point's color. If the Z check fails, OpenGL doesn't
  14. even bother about checking transparency.
  15. This is why, if you want to render transparent objects, you must make sure
  16. you render the farthest objects first, to give transparency a chance.
  17. However this effect can be usefull if you want to render mixed, half-transparent
  18. half-opaque objects.
  19. They are two ways to order objects in GLScene :<ul>
  20. <li>ordering : can be done at design-time in the editor or at runtime with
  21. MoveUp/MoveDown methods
  22. <li>sorting : adjust the ObjectSorting property (see help for more details)
  23. </ul>
  24. }
  25. program Transparency;
  26. uses
  27. Forms,
  28. fTransparency in 'fTransparency.pas' {Form1};
  29. {$R *.RES}
  30. begin
  31. Application.Initialize;
  32. Application.CreateForm(TForm1, Form1);
  33. Application.Run;
  34. end.