Post by Guppyb on Jul 8, 2004 21:53:36 GMT -5
I've been playing around with Basic4gl (when time permits) and haven't seen some basic shape demos like creating a cylinder, hopefully someone finds this useful.
Enjoy...
I know I notated the hell out of it. I'm not a programmer by nature and I realize that there are optimizations that can be made, so please be kind.
...G
Enjoy...
dim xrot#, yrot#, zrot#
' X,Y and Z axis rotation
dim cylinderrad , cylindheight
' Cylinder radius size and height
dim i
' loop variable
dim cylinder_shade#
' level of brightness to shade cylinder segment
' next variables are for FPS routine
dim OldTick, CurrentTick , TimeTick , Frames , FramesSecond#
glEnable (GL_CULL_FACE)
TextMode (TEXT_OVERLAID)
OldTick = TickCount () 'set current tickcount
while true
gosub FPSroutine 'do FPS routine
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT) ' Clear screen and depth buffer
glLoadIdentity() ' Reset the current modelview matrix
glTranslatef(0.0,0.0,-5.0) ' Move into the screen 5 units
glucylinder ()
glRotatef(xrot#,1.0,0.0,0.0) ' Rotate on the X axis
glRotatef(yrot#,0.0,1.0,0.0) ' Rotate on the Y axis
glRotatef(zrot#,0.0,0.0,1.0) ' Rotate on the Z axis
cylinderrad = 1: cylindheight = 4 ' set cylinder circumfrence and height
gosub drawcylinder ' jump to cylinder routine
DrawText ()
SwapBuffers ()
xrot# = xrot# + 0.1 ' X axis rotation
yrot# = yrot# + 0.2 ' Y axis rotation
zrot# = zrot# + 0.05 ' Z axis rotation
wend
'********************Cylinder routine****************************
drawcylinder:
glColor3f(0.5,0.5,0.5) 'set top of cylinder to grey
glBegin (GL_Polygon)
For i = 0 to 36 ' draw polygon top of cylinder in 10 degree steps
glVertex3f (cylinderrad * cosd(i*10) , (cylindheight /2) * -1, cylinderrad * sind (i*10))
next
glend ()
glColor3f(1.0,1.0,1.0) ' set color to white because color changes relative inside glBegin
glbegin (GL_Quad_strip)
For i = 0 to 36 'draw actual cylinder in 10 degree steps
cylinder_shade# = abs (0.055 * (18-i)) ' determine shade color of cylinder
glColor3f(cylinder_shade#, cylinder_shade#, cylinder_shade#) ' color cylinder
glVertex3f (cylinderrad * cosd(i*10), (cylindheight /2) * -1, cylinderrad * sind (i*10)) ' draw top vertex
glVertex3f (cylinderrad * cosd(i*10), (cylindheight / 2), cylinderrad * sind (i*10)) 'draw bottom vertex
next
glend ()
' last routine to draw bottom of cylinder, same as top routine except reverse
' reason for this is that surface would be backwards and therefore culled by the gl-cull-face
glColor3f(0.5,0.5,0.5)
glBegin (GL_Polygon)
For i = 0 to 36
glVertex3f (cylinderrad * cosd((36-i)*10), (cylindheight /2) , cylinderrad * sind ((36-i)*10))
next
glend ()
return
'*******************FPS routine****************************
FPSroutine:
CurrentTick = TickCount()
TimeTick = CurrentTick - OldTick
if TimeTick >= 1000 then FramesSecond# = Frames * (TimeTick/1000) : Locate 0,0: Print FramesSecond#: Frames = 0: OldTick = CurrentTick: endif
Frames = Frames + 1
Return
I know I notated the hell out of it. I'm not a programmer by nature and I realize that there are optimizations that can be made, so please be kind.
...G