Q’s OPENGL OCX Control (For Visual Basic 6.0)
Project Name: QGLOCX
Project Overview and Background:
While not an optimal environment for intensive 3d graphical drawing, Visual Basic 6.0 is an unparalleled development environment for logical flow and ease of putting together powerful working application.
The goal for this project is to create a reusable self contained OCX control which manages all it’s own resources up to and including its windows, device context, and swapping those contexts into and out of OpenGL.
This control will be developed in Visual Studio 2005 leveraging Visual C++ 2005, both for compatibility’s sake and for minimizing the footprint in memory, size and redistributable requirements of the release version of the OCX control, and will be usable by any development environment which can leverage OCX controls, with a target environment to be Visual Basic 6.0.
Project Deliverables, Details and Reasoning
Originally, I created this control leveraging Microsoft Visual Studio 2010 in C# as a proof of concept.
The question I had was: is it possible to use OPENGL concurrently with different models? I had seen numerous examples of different perspectives of the same model, but not a single one had different models.
Where would this be useful? Most 3d interfaces and games have a HUD which is a 2d overlay.
For instance, Worlds of Warcraft has a wonderful 3d presentation for the primary window, with elements of a 2D Heads Up Display (outlined in red).
Modern CAD programs allow the interaction with 3d objects on a design time based to interact with 3d Models…
For instance, in this next image a designer can select from 3d objects (upper left) which can then be placed in the 3d model itself (lower right).
With this, this project has two deliverables
- A windowed container OCX Control which can render a model in its own window and server as a parent control.In the Worlds of Warcraft example, this might be used to create the ‘master window’ I look at the world with.
In the CAD example, this might be the house model I see in the lower right hand corner.
Once that control’s done, then the tougher part:
- A windowless OCX Control which renders a model transparently, with adjustable model opacity.To what end?
Real time overlays on GPS maps:
Augmented Reality Control Overlays:
And for making Games and television shows which might feature things that are ‘bigger on the inside:
HOW TO: Project Information
In Visual Studio, Create a New Project, a Visual C++ MFC Active Control as follows:
With these settings for the primary container control:
This control will be the base control, which I have named mine “Q’s OPENGL Control”
BUILD this as follows:
This creates a file with the extension ‘.ocx’ in this debug location:
To ‘test out’ this generic control (which contains nothing but the default information at this point), I open up a new Forms project in Visual Basic 6/.0 as follows:
This creates an empty Visual Basic ‘Forms’ based application which doesn’t do anything:
From here, I found an image I could use as the background to give the illusion of depth…
This image (or video) can be streamed on a real time basis…
Place that image (or video feed) as the backdrop for a Visual Basic forms based project.
From there, I select the control I just generated by going to Project->Components and adding the control by using the ‘browse button to go to the location the OCX control was generated as follows:
This then ‘adds’ the control to the toolbar palette (left), which I then select and add to the form a demonstration of this single generic control I just generated in Visual C++ as follows:
This single, generic project can now be ‘run’ in Visual Basic using the play button on the toolbar (above), which creates a single window which doesn’t do a whole lot:
The goal is to make the 3d OCX control generate OpenGL content similar to what I did in this C# project here:
And allow me to adjust the properties of EACH INDIVIDUAL control separately.
Here’s the properties I have in the C# project:
And here’s the C# project in it’s entirety, which is is partially complete, enough to prove that multiple OpenGL windows could be animated simultaneously within the same form and not annihilate resources.
Detailed Project Requirements:
- Convert the C# OpenGL code to Visual C++ / 2005 version. Bring the control up to it’s current working state. Verify numerous OCX Controls can be placed on a single form and remain functional within a Visual Basic 6.0 environment.
- Resolve these issues with the control (in C++):
– Texture coloring is off and not retaining original texture
– Digital artifacts are occurring in rotations. Elimintae ’em.
- Add in Timer value for update frequency of animation(s) in FPS. So 30 Frames per second, for instance, would have a timer (exclusive to this OCX instance) that would go off every 30/1000 of a second or 0.03 seconds. With this, ALSO trigger an event which can get cascaded to the container window with a single parameter – a (cancel) boolean which can be leveraged to disable animations by setting it to false in the client code.
- Add in Code for loading of Generic Model Types:
– Circle (single pixel thickness circle)
– Disk (an Outer and Inner Circumference )
– Pyramid ( four sided, filled )
– Segmented Disk ( With two named angles from 0 to 359 degrees)
– Square (flat plane)
– Text (Developer selects text and font)And two more interesting shapes:
– Saturn (sphere with disk around it)
– Atom (large sphere with 1 to N smaller spheres around it, with 2^N maximum atoms per ring where N= ring number, and 1 being the first ring.
- Add in capability to load complex external models, starting with a simple .OBS format, moving to 3DS formats and so on. DO NOT USE EXTERNAL LIBRARIES for this UNLESS YOU HAVE THE SOURCE CODE (NOT just ‘lib or .dll) INCLUDED! why? We want COMPLETE control of this, without licensing issues.
- Come up with a cooler icon for the Visual Basic Toolbar. You might knock this one out first 🙂
- Add in these Methods and Events (Q TODO)
Developed on Microsoft Windows 7.0, x64 version (only)
Microsoft Visual Basic 6.0
Microsoft Visual Studio 2005 / Visual C++ 2005
Low. Exceedingly low. Think old pocket calculator low.