Here's a demo with a proper show_sphere() function.
If you want to make it a bit more simple, you can remove all the lighting commands. (Just search the code for "light.") ;-)
Code: Select all
' Atom Show OpenGL Demo! v0.1
' (C) 2008 Innova and Kristopher Windsor
' Adjusted by Brad Fuller and Kristopher Windsor (again! :-P)
#include "GL/gl.bi"
#include "GL/glu.bi"
Const screenx = 640, screeny = 480
Const true = -1, false = 0, pihalf = Atn(1) * 2
Type camera_type
As Double eye(1 To 3)
As Double see(1 To 3)
As Double up(1 To 3)
End Type
Type coord_type
As Double x, y
End Type
Dim Shared LightDiffuse(0 To 3) As Single => {3, 3, 3, 1}
Dim Shared LightPosition(0 To 3) As Single => {0, 0, 0, 1}
Dim Shared As String Key
Dim Shared As camera_type camera
Sub start
Screenres screenx, screeny, 32,, 2
glMatrixMode GL_PROJECTION
glLoadIdentity
gluPerspective 35.0, screenx / screeny, .01, 8
glMatrixMode GL_MODELVIEW
glLoadIdentity
glClearColor 0, 0, 0, 1
glEnable GL_DEPTH_TEST 'properly handles overlapping polygons (draw order for layering)
glEnable GL_LIGHT1
glLightfv GL_LIGHT1, GL_DIFFUSE, @LightDiffuse(0)
glEnable GL_LIGHTING
glEnable GL_COLOR_MATERIAL
Randomize Timer
End Sub
Sub show_sphere (Byval x As Double, Byval y As Double, Byval z As Double, Byval size As Double, Byval c As Integer)
#define clor(c) glColor3b( (c And &HFF0000) Shr 17, (c And &HFF00) Shr 9, (c And &HFF) Shr 1)
Static As GLUquadricObj Ptr q 'Quadratic For Drawing A Sphere
If q = 0 Then q = gluNewQuadric() 'Initialize Quadratic
clor(c)
glTranslated(x, y, z) 'move camera so it looks like the sphere is drawn in a different place
gluSphere(q, size, 64, 32) 'sphere
glTranslated(-x, -y, -z) 'set camera back to normal
End Sub
Sub go
Static As Double angle_x, angle_y, angle_z
'coords are set for bird's eye view
'top left of map is at (0, 0, 0)
'all parts of map are 1un cubed
glClear GL_DEPTH_BUFFER_BIT Or GL_COLOR_BUFFER_BIT
glLoadIdentity
LightPosition(0) = 0
LightPosition(1) = 0
LightPosition(2) = 1
glLightfv GL_LIGHT1, GL_POSITION, @LightPosition(0)
With camera
.eye(1) = 6
.eye(2) = 0
.eye(3) = 0
.see(1) = 0
.see(2) = 0
.see(3) = 0
.up(1) = 0
.up(2) = 0
.up(3) = 1
gluLookat .eye(1), .eye(2), .eye(3), .see(1), .see(2), .see(3), .up(1), .up(2), .up(3)
End With
'random spinning (instead of walking around the ground)
angle_x += .4
angle_y += .6
angle_z += .7
glRotatef angle_x, 1, 0, 0
glRotatef angle_y, 0, 1, 0
glRotatef angle_z, 0, 0, 1
'ground
If Multikey(&H39) Then 'space bar
glBegin GL_QUADS
glColor3d .4, .2, 0
glNormal3f 0, 0, 1
glVertex3d -1, -1, 0
glVertex3d 1, -1, 0
glVertex3d 1, 1, 0
glVertex3d -1, 1, 0
glEnd
End If
'center sphere (red)
show_sphere 0, 0, 0, .5, &HFF4444
'four spheres on the ground (blue)
show_sphere 1, 0, 0, .2, &H4444FF
show_sphere 0, 1, 0, .2, &H4444FF
show_sphere -1, 0, 0, .2, &H4444FF
show_sphere 0, -1, 0, .2, &H4444FF
'four spheres above the ground (yellow)
show_sphere 1, 0, 1, .2, &HFFFF44
show_sphere 0, 1, 1, .2, &HFFFF44
show_sphere -1, 0, 1, .2, &HFFFF44
show_sphere 0, -1, 1, .2, &HFFFF44
'four spheres below the ground (green)
show_sphere 1, 0, -1, .2, &H44FFFF
show_sphere 0, 1, -1, .2, &H44FFFF
show_sphere -1, 0, -1, .2, &H44FFFF
show_sphere 0, -1, -1, .2, &H44FFFF
'one really big sphere far away, above the ground (white)
show_sphere 0, 0, 3, 2, &HFFFFFF
Flip
End Sub
Sub main
start
Do
go
Sleep 10
Key = Inkey
Loop Until Key = Chr(27)
End Sub
main