Questions and Answers



Must I use an ocx to create OpenGL apps in VB?
No. The ocx provided on this site is merely a convenient way of encapsulating code, and it also is written in VB. You can accomplish the same thing by compiling commonly used code into a dll and referencing it, or by copying and pasting the ocx source into projects.
How do I use the glxCtl.ocx to create OpenGL apps in VB?
Start a new project. Copy the files in the 'ProjectX' folder to your new project folder and add them to the project. If you have a compiled copy of glxCtl, you can add it to the toolbox, otherwise add the glxCtl.vbp file to your project by selecting 'File | Add Project'. Either way, the glxCtl should appear in the toolbox. Draw a glxCtl onto frmMain. The startup code is in Sub_Main, make sure you set the 'Project | Project Properties | Startup Object ' to Sub_Main. Then run it and you'll see a blue ball. To create an app, add code to the Draw function.
Can I redistibute the VBOpenGL type library?
You can freely redistribute the type library.
Can I change the code in glxCtl and then compile and distibute it?
Yiikes!
Please don't do that! Change the name of it, at least. If you want changes made to glxCtl, contact me. Also note that glxCtl is intended as a learning tool and utility library - there is no error checking in glxCtl and several known bugs which can cause it to crash.
Can I redistibute the glxCtl.ocx with an app I write?
Yes, but I would advise you not to, for the reasons above. If you want to develop an OpenGL app using this code, you should could comb through it carefully, add error handlers, change ALL the class names, perhaps by using different prefixes than 'glx' and 'gle', fix any bugs you find and notify me of them, change the name of the project, etc. In other words, you should build your own ocx from scratch, taking what you find here as it suits your purposes.
How do I fix 'Missing Library' errors?
First, you should be using V1.2 of the type library. Remove any other other versions from your machine. If you open a project which has a reference to V1.0 or v1.1, you will get an error. The only way I know to fix it is:
Close VB.
Open the vbp file of the sample in notepad.
Find a line like this:
Reference=*\G{03644881-8010-11D1-95AA-000000000000}#1.1#0#..\..\..\TLB\OpenG L\vbogl.tlb#VB OpenGL API 1.1 (ANSI)
Delete it. Close and save.
Now rerun the project and maually add the tlb reference to the project.
Why are there 2 versions of the type library, and which one should I use?
You should use the big one, at the top of the page. You should use version 1.2
The 'GL only' tlb is provided for those who have their own Win32 type library or who prefer to type in API declarations. If you use the 'GL only' version, the glxCtl and most of the samples will not run. You will have to add API declarations to the code before they will run.
The type library on this site is for the MS OpenGL implementation only. You can get a type library for the SGI dlls from Patrice Scribe. There is also another MS type library at Patrice's site, which is very similar to this one - the two differ mainly in that this one provides some enumerations for function parameters. Code for one will work with the other with very few changes (like adding or removing VarPtr() from parameters).
How is writing OpenGL code different in VB from C?
C code can store data internally in any convenient format, then cast it to the proper type for passing to OpenGL. VB must store data which is to be passed to GL as the required type. This can lead to some clumsy constructs. If you use classes for color and point data, and the data is an array (of 3 floats, for example), then it may be necessary to have the class make the GL call, because VB will not let classes expose arrays. (There are workarounds using Variants and VarPtr which I won't discuss.)

Another problem is that VB stores arrays differently from C. If you create a 2 dimensional array in VB (of say vertex data, as V(0 to 100, 0 to 2)) and then try to pass one of the array elements to GL using VarPtr (as VarPtr(V(10,10))), you will pass the wrong data. Stick with one dimensional arrays for data which is to be passed to GL. One way to do this is to create arrays of User Types which contains the array data:
    Type T
      v(0 to 2) As Single 
    End Type  
    Dim V(0 to 100) As T 
Then you can pass the point data at 'n' as V(n).v(0).

Aside from hacks to get parameter values into the proper format, you will probably want to model OpenGL in VB classes which expose properties, but otherwise the coding is similar.
I wrote a program but nothing happens. What's wrong?
If you set a clear color (like 0,0,0) and the window does not change to this color, then the setup of the pixel format and rc has failed.
If the screen is black, then set the glClearColor to another color (like .3,.3,.3) and see if gl is drawing black objects. If you still see nothing, then try disabling/enabling the lights. Also try disabling CULL_FACE. If you still see nothing, then, check the viewing parameters. Make sure the viewport is set correctly in the resize event, then try using gluLookAt followed by a call to the code that draws your objects. Debugging viewing errors is a common experience. Just keep twiggling, something will eventually show up.
How does an OpenGL app in VB compare in speed to the same app written in C?
For small programs like the samples on this site, most of the work is done in the OpenGL dll, so the usual provisos about VB's speed (only a tiny fraction of the execution time is spent in the VB code) apply here. The VB samples posted here will seem slower by maybe an order of magnitude than their C counterparts when in design mode, but compiled VB exe's are roughly equal in speed to C++ exe's.
Can OpenGL be used on web pages?
Yes, but in this case you must create an ocx and make all API and GL calls from within the ocx, because scripting languages cannot make these calls. You can place the entire code for the app in the ocx, or you can create a more general ocx and expose objects which allow script to set gl parameters. I will post sample code in the near future to illustrate this.

You can also use the

If you have questions, send them in I'll post them.



Please send suggestions, bug reports, and such to:



Home Page   |  Related Sites