Q

Home » Borg » Q’s OPENGL OCX Control (For Visual Basic 6.0)

Q’s OPENGL OCX Control (For Visual Basic 6.0)

Enter your email address to follow this blog and receive notifications of new posts by email.

Join 45 other followers

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).

WOW

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).

SweetHome3D-500_0[1]

With this, this project has two deliverables

  1. 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:

  2. A windowless OCX Control which renders a model transparently, with adjustable model opacity.To what end?

    Real time overlays on GPS maps:

    inavi-k2-navigation[1]
    Augmented Reality Control Overlays:

    vlcsnap-2013-01-27-22h40m55s0[1]
    And for making Games and television shows which might feature things that are ‘bigger on the inside:

    TARDIS

HOW TO: Project Information

In Visual Studio, Create a New Project, a Visual C++ MFC Active Control as follows:

MFCActiveXControl
With these settings for the primary container control:

Step 3
This control will be the base control, which I have named mine “Q’s OPENGL Control”

BUILD this as follows:
build

This creates a file with the extension ‘.ocx’ in this debug location:

FileListing

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:

StandardEXE

This creates an empty Visual Basic ‘Forms’ based application which doesn’t do anything:

BasicTemplate

From here, I found an image I could use as the background to give the illusion of depth…

robbins-sb-int-02[1]

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.

Form

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:

QGLControl

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:

DrawOCX

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:

GenericRun

The goal is to make the 3d OCX control generate OpenGL content similar to what I did in this C# project here:

qglcontrol[1]

And allow me to adjust the properties of EACH INDIVIDUAL control separately.

Here’s the properties I have in the C# project:

Properties

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:

  1. 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.
  2. 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.
  3. 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.
  4. Add in Code for loading of Generic Model Types:
    – Circle (single pixel thickness circle)
    – Cone
    – Disk (an Outer and Inner Circumference )
    – Cylinder
    – Pyramid ( four sided, filled )
    – Sphere
    – Segmented Disk ( With two named angles from 0 to 359 degrees)
    – Square (flat plane)
    – Cube
    – 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.
  5. 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.
  6. Come up with a cooler icon for the Visual Basic Toolbar. You might knock this one out first 🙂
  7. Add in these Methods and Events (Q TODO)
    – TODO

Software Requirements

Developed on Microsoft Windows 7.0, x64 version (only)
Microsoft Visual Basic 6.0
Microsoft Visual Studio 2005 / Visual C++ 2005

System Requirements

Low. Exceedingly low. Think old pocket calculator low.

 


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Enter your email address to follow this blog and receive notifications of new posts by email.