You can use a transparent surface to simulate a window or maybe the surface of some water. Back in Lesson One the alpha value for glColor4fv was briefly mentioned. Here we will use it to control the transparency of a surface. The acceptable values are between 0 & 1, with 0 being completely transparent and 1 being solid.
Before this will work a few OpenGL states need to be set. The first is to enable blending. This tells OpenGL that if there is a transparent surface in the scene that it needs to blend the colors wherever it interacts with another surface.
The second call needed is to glBlendFunc and it tells OpenGL which method to use when blending the colors.
The only thing to keep in mind is that the transparent surface needs to be created last in order to work.
Fog is an easy to add special effect with OpenGL. It can be used to add depth perception to a scene. The first step is to make a call to glEnable with GL.FOG as the argument. As with all other enabled functions, it can be turned off with a call to glDisable.
Next is to set the color of the fog. Again, the values for the individual color should be between 0 & 1. The default values are 0,0,0,0.
Then we need to set the density of the fog. This value should also be between 0 & 1, with the default value being 1.
'fog
GL.FOG=2912
GL.FOG.DENSITY=2914
GL.FOG.COLOR=2918CALL glEnable GL.FOG
STRUCT fogColor , red ASulong , green ASulong , blue ASulong , alpha ASulong
fogColor.red.struct= R4(.5 )
fogColor.green.struct= R4(.5 )
fogColor.blue.struct= R4(.5 )
fogColor.alpha.struct= R4(1)
CALLDLL #gl , "glFogfv" ,_ ' set fog color to gray
GL.FOG.COLORASlong,_
fogColor AS STRUCT ,_
ret AS void
density = R4(.25 )
CALLDLL #gl , "glFogf" ,_ ' set the density of the fog
GL.FOG.DENSITYASlong,_
density ASulong ,_
ret AS void
FOR a =1TO345CALL ClearView eyeX , eyeY , eyeZ , centerX , centerY , centerZ , upX , upY , upZ
CALL glColor4fv 0 , 0 , 0 , 1CALL glBegin GL.QUADSCALL glVertex -2 , -1 , -2CALL glVertex -2 , -1 , 2CALL glVertex 2 , -1 , 2CALL glVertex 2 , -1 , -2CALL glEnd
CALL glRotatef a , 0 , 1 , 0CALL glColor4fv 0 , 0 , 1 , 1CALL glBegin GL.TRIANGLESCALL glVertex -1 , -1 , -2CALL glVertex 0 , 1 , -2CALL glVertex 1 , -1 , -2CALL glEnd
CALL glBegin GL.TRIANGLESCALL glVertex -1 , -1 , 0CALL glVertex 0 , 1 , 0CALL glVertex 1 , -1 , 0CALL glEnd
CALL glBegin GL.TRIANGLESCALL glVertex -1 , -1 , 2CALL glVertex 0 , 1 , 2CALL glVertex 1 , -1 , 2CALL glEnd
CALL RefreshView
CALL Pause 15NEXT a
WAIT
OpenGL 3D Graphics in Liberty BASIC
Lesson Eight: Transparent Surfaces and Fog
by Robert McAllisterTransparent surfaces:
You can use a transparent surface to simulate a window or maybe the surface of some water. Back in Lesson One the alpha value for glColor4fv was briefly mentioned. Here we will use it to control the transparency of a surface. The acceptable values are between 0 & 1, with 0 being completely transparent and 1 being solid.
Before this will work a few OpenGL states need to be set. The first is to enable blending. This tells OpenGL that if there is a transparent surface in the scene that it needs to blend the colors wherever it interacts with another surface.
The second call needed is to glBlendFunc and it tells OpenGL which method to use when blending the colors.
The only thing to keep in mind is that the transparent surface needs to be created last in order to work.
Fog:
Fog is an easy to add special effect with OpenGL. It can be used to add depth perception to a scene. The first step is to make a call to glEnable with GL.FOG as the argument. As with all other enabled functions, it can be turned off with a call to glDisable.
Next is to set the color of the fog. Again, the values for the individual color should be between 0 & 1. The default values are 0,0,0,0.
Then we need to set the density of the fog. This value should also be between 0 & 1, with the default value being 1.
In the next lesson we will dig into "OpenGL calls and argument types"