To start a new project, create a new directory - in this case we'll call it
'Quad' - and copy the template project to the new directory. (The template
project is in the 'ProjectX' folder.) You should have 4 files: 'glxMain.frm',
'glxCXXX.cls', 'glxConstants.bas', and 'ProjectX.vbp'. Open the project. Change the
name of class from 'CXXX' to 'CQuad'. There are two references to the class (in the basic
module and in the form) - you can search for 'CXXX' and replace it with 'CQuad'.
Now add the ocx project to the project group by selecting 'File | AddProject...'
and selecting 'glxCtl.vbp'. Draw a glxCtl control on frmMain. OK, save the group as
'Quad.vbg' and then run it. The form should open with a blue sphere in the
center as in the illustration.
Set gCtl = glxCtl1 Set CX = New CQuad glxCtl1.Init glxCtl1.Animate = TrueThe control in turn fires 2 events telling the CXXX class to initialize, the first, 'Init', for pre-GL initialization, and the second, 'InitGL', after GL has been initialized. When it returns, the code in Form_Load starts the animation timer. In the ocx, each time the timer fires, the 'Render' function is called, which clears the screen and fires the 'Draw' event. The 'Draw', 'Resize', and other events are passed by the form to the main class 'CQuad'. The CQuad 'Draw' simply draws a sphere at this point.
The order of events is important here. The class must be created first,
because it must respond to events from the ocx. The ocx must exist before
you can set any properties. If you want to alter the
default setup parameters of OpenGL (such as double-buffering), you must
do so after the control is created but before GL is initialized. The ocx will
fire an 'Init' to give you a chance to do so. It will then create an OpenGL
rendering context and then fire the 'InitGL' event when it is ready.
At this point you can isuue OpenGL commands. The Quad class does no
pre-initialization, and in 'InitGL' it sets up the viewing and lighting
parameters. When 'Init' returns, everything is set up. When the timer is
started, the app will start looping through the display code in the 'Draw'
function.
With gCtl
.MouseRotate = True
.Trackball.Animate = False
.Grid = glxGridX
.axis = glxXYZ
.Pick = True
End With
This code in 'Draw' causes the grid to be displayed:
With gCtl
.Trackball.Update
If m_Grids Then .DrawGrids
End With
The Trackball and Grid must be manually called in each draw cycle.