SuperStrict
GLGraphics 800, 600
Global Vertices:Float[0]
Global Triangles:Int[0]
Global Colors:Float[0]
Global VertexID:Long = 0
Global VertCount:Long = 0
Global TriangleCount:Long = 0
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0, 1.3333, 1, 1000)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
gltranslatef( 0.0, 0.0, -6.0 )
glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
CreateCylinder( 100 )
Global Ang:Float = 1.0
While Not KeyDown(KEY_ESCAPE)
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
glRotatef( Ang, 0, 1, 0 )
' Angle :+ 1
glEnableClientState(GL_VERTEX_ARRAY)
' glEnableClientState(GL_COLOR_ARRAY)
' glColorPointer(3, GL_FLOAT, 0, Colors)
glVertexPointer(3, GL_FLOAT, 0, Vertices)
glDrawElements( GL_TRIANGLES, VertCount-1 , GL_UNSIGNED_INT, Triangles )
glDisableClientState(GL_VERTEX_ARRAY)
' glDisableClientState(GL_COLOR_ARRAY)
Flip
Wend
End
'---------------------------------------------------------
Function CreateCylinder( segments:Long, closeEnds:Byte = True )
'this will create a cylinder, closeEnds will either close the ends or leave them open
Local Angle:Float = 0.0
Local uV:Float = 0.0
Local TopVert:Long
Local BottomVert:Long
If segments<3 Or segments>100 Then Return 'if the requirements are to big then null it
If ( closeEnds = True )
TopVert = AddVertex( 0.0, 1.0, 0.0 );
BottomVert = AddVertex( 0.0, -1.0, 0.0 );
EndIf
Local Vert1:Long, Vert2:Long, Vert3:Long, Vert4:Long 'these will be used for the sides of the cylinder
Vert1 = AddVertex( Sin( Angle ) *1.0, 1.0, Cos( Angle ) *1.0 );
Vert2 = AddVertex( Sin( Angle ) *1.0, -1.0, Cos( Angle ) *1.0 );
uV :+ ( 1.0 /segments )
Repeat
Angle :+ ( 360.0 /segments ) 'increase it via the increments
Vert3 = AddVertex( Sin( Angle ) *1.0, 1.0, Cos( Angle ) *1.0 )
Vert4 = AddVertex( Sin( Angle ) *1.0, -1.0, Cos( Angle ) *1.0 )
If ( closeEnds = True )
'this will close off the ends of the cylinder if required
AddTriangle( TopVert, Vert1, Vert3 )
AddTriangle( BottomVert, Vert4, Vert2 )
EndIf
'now add the sides
AddTriangle( Vert1, Vert2, Vert3 )
AddTriangle( Vert3, Vert2, Vert4 )
uV :+ ( 1.0 /segments )
Vert1 = Vert3
Vert2 = Vert4
Until Angle>360
Print "TC:"+TriangleCount
Print "VC:"+VertCount
End Function
Function AddTriangle( index1:Long, index2:Long, index3:Long )
Triangles = Triangles[ ..TriangleCount +3 ]
Triangles[ TriangleCount ] = index1
Triangles[ TriangleCount +1 ] = index2
Triangles[ TriangleCount +2 ] = index3
TriangleCount :+ 3
End Function
Function AddVertex:Long( X:Float, Y:Float, Z:Float )
Vertices = Vertices[ ..VertCount +3 ];
Vertices[ VertCount ] = X
Vertices[ VertCount +1 ] = Y
Vertices[ VertCount +2 ] = Z
VertCount :+ 3
VertexID :+ 1
Return VertexID -1
End Function
This is a small example I knocked up :)
|