Readme!



Notice! To use ANYTHING on this site you need VB5 Service Pack2 or above.
If you are at all new to OpenGL, you MUST get a copy of 'OpenGL Programming Guide, 2nd edition', Woo, Neider, Davis (the 'Red Book').

VB5 and VB6

The latest version of glxCtl.ocx was compiled with VB6, so you'll need at least the VB6 runtimes to use it. The ocx uses no other ocx's, so just the runtime should work. You should be able to use it in VB5 projects, but I can't guarantee that. If you can't, then you should download the source code of the latest version and compile it in VB5, as it has some important changes in the texture classes. v1.2 is the last version compiled with VB5 - I'll leave it posted for a while.

To compile VB6 files in VB5, you need to remove some code from the class modules. At the top of VB6 class modules is a section like this:
BEGIN
(stuff about data binding)
END
You must remove the BEGIN/END section. You can do this manually, or you can try the following utility:

ClassConverter.exe

Some VB6 projects have a line like this in vbp file:

Retained=0
Delete this line if you get an error saying "Retained is an invalid key."

A few samples use the common controls ocx. These projects may not load properly if you don't have the same version of the ocx. To fix this, you can create a new project and put a toolbar/statusbar/imagelist on it. Then save it and open it in Notepad and copy the GUIDs in the new 'vbp' and 'frm' files to the sample. A complete description of how to do this is here:

ReadMeOCX.txt

Set up

1. Install the type library. The easiest way to do this is to start a new project, select 'References', and then 'Browse', and then select the type library (vbogl.tlb). VB will register the type library. Alternately, you can use regsvr32.

2. To view the samples, you must download the glxCtl.ocx, either source or executable. Each version comes with a template project which uses it (ProjectX, ProjectZ). You can register the executable by starting a new project, adding a reference to the type library, then select 'Components' and look for 'glCtl' in the list. If it isn't there, click 'Browse' and point to the directory where you installed it.

To use OpenGL from Visual Basic, the only thing necessary is a type library. The ocx functions as a library of code routines, you may use it or not as you wish. If you decide to use it, download the source code so you can see exactly what it does. Don't be intimidated by its size, the bulk of the code is seldom used GLE routines - the core of the ocx is relatively simple.

If you have any problems with the above, make sure you have VB5 SP2, then first register the type library, then register the ocx. If you can't register the ocx, download the source code and open the project. VB will give you more specific error messages and you will be able to pinpoint the problem.

Verification

Assuming you have done the above, the next thing is run the template project and verify that everything is working.

1. ProjectX. ProjectX uses the source code, so open the 'ProjectX.vbg'. Whenever you use the source code, open the UserControl and close it before you try to run the project. This causes VB to do some kind of registry voodoo, without which you will likely get an error when you try to run the project.

2. ProjectZ. ProjectZ uses the compiled ocx, so open 'ProjectZ.vbp'. When it opens, it will likely give an error saying it can't load the 'glxCtl.ocx'. Say OK, delete the picturebox if VB drew one in place of the ocx, and right click the toolbox and select 'Components'. Look for 'glCtl' in the list. If it isn't there, select 'Browse' and then select it. VB should now add the ocx to the toolbox. Draw a glCtl anywhere on the form, and run it.

Troubleshooting

If you haven't ever done so before, open a 'vbp' file in Notepad and look at it. The first 3 lines of 'ProjectZ.vbp' look like this:

Reference=*\G{00020430-0000-0000-C000-000000000046}#2.0#0#D:\WINNT\System32\STDOLE2.TLB#OLE Automation
Reference=*\G{03644881-8010-11D1-95AA-000000000000}#1.1#0#..\..\..\TLB\OpenGL\vbogl.tlb#VB OpenGL API 1.2 (ANSI)
Object={21E0F1D3-71F8-11D2-9717-000000000000}#1.0#0; glxCtl.ocx

ProjectX is the same, except for the 3rd line:
Object=*\A..\glxCtl.vbp

As you can see, there are relative paths to the type library and source code project. The type library is usually not a problem, because VB finds it by its registry entry. But if ProjectX.vbp and glxCtl.vbp aren't in a certain path-relation to each other, VB will be unable to load the glxCtl project.

ProjectZ finds the ocx by the GUID. If the ocx is recompiled, VB changes all the GUIDs, so the next time the project is opened, it will give an error saying it couldn't load the ocx. The ocx must be added to the project again, and redrawn on the form.

Sometimes a VB project can contain both of the 3rd lines. This happens when you start a project using the compiled ocx, then add the source code project, perhaps to trace through some code. The next time you try to run the 'vbp' file, VB will give an error saying either the project or the compiled ocx can't be found. You must edit the vbp file in Notepad to remove one of the lines to resolve this.

Sometimes a line refering to the source project can end up in frmMain:
Object=*\A..\glxCtl.vbp
When you try to run your project using the compiled ocx, VB will say it can't find the source code project. You must delete the line in Notepad.

Almost all problems running the samples involve the above lines in the vbp. The surest solution is to delete the 3rd line - the ocx - then open the project in VB and add the component again.

Samples

The latest version of glCtl (v1.3) is not binary compatible with earlier versions. I went through all the samples and changed them to run with v1.3. The changes made were to the glxTexture and glxImage classes. If you have earlier versions of the samples, you'll have to change a couple of lines in some of the samples which do texturing.
* Call the 'BuildMipMap' method in the glxImage class rather than calling gl direct.
* Use SetPixels instead of SetData to set image data in glxImage.
All the new texturing samples use these and other features missing in earlier versions of glCtl. All future samples here will be written with VB6, but should run without modification in VB5.

Problems

1. No matter what I do I get an "Error loading dll" message.

Start a new project, add a reference to the type library, then add the ocx. If you cannot, this means you are missing VB SP2, or the gl dlls, or some other system component.

If you can add the ocx to a new project, but can't open a sample, then you need to edit the sample to remove all references to the ocx, then open it and manually add the ocx to the component toolbox. (See above.)

2. If I try to add the file project glxCtl.vbp I get the following error 'ThreadingModel is an invalid key' and it fails to load the file.

This means you need VB5 SP2. I have been told that the Service Packs cannot be applied to the Learning Edition.

3. When I load a project group and try to run it, I get an "Automation error".

If you are using the source code of the ocx, click on the user control and open it. Then close it again and the project should now run. If you have a compiled ocx on your system, and you try to run a project using the source code, VB must overwrite the registry information with some temporary information. Opening the user control causes VB to do this, apparently.

4. I get a error saying VB can't create a reference to the type library.

The type library path be different on your machine. Open the References and select 'VB OpenGL API' from the list.

5. After editing the ocx source code, I can't open or run projects.

Sometimes, after a single line of code is edited in ocx project, I get several errors which prevent the project from running. Usually VB stops at a line containing a reference to one of the ocx classes and says the type is not defined. Sometimes I get an 'Error loading dll" message. Deleting the ocx, saving and reloading doesn't help. The error messages usually make no sense. In this case, recompiling the ocx usually fixes the problem. This is a registry problem, I expect.

This is the most difficult problem I have with VB, but it's by no means the only one. Other bizarre automation errors can occur, and it just takes some trial and error to straighten them out. Beware of compiling an ocx and then deleting it, or of copying an ocx's source files to a new directory - this causes orphaned registry entries.







Please send suggestions, bug reports, and such to:



Home Page   |  Related Sites