A small VRML viewer using OpenGL and MFC

FIG. 1. You can easily display a wrl-based terrain
using OpenGL and MFC.

This contribution is a small MFC sample to learn how to :

display a VRML file

use OpenGL display lists

superimpose wireframe on a flat or smoothly shaded mesh

smoothly subdivide a 3D triangular mesh (from Charles Loop)

implement mouse interaction (rotation and translation)

build a scene graph from a vrml 2.0 file (hand-made and not lex-based)

DISPLAY LIST

Using display lists is a nice way to accelerate your rendering application.
A display list compiles a sequence of gl drawings using standard OpenGL
calls, then can be recalled later using a simple list id number. The resulting
list is thus resident in the main memory in a precompilated mode, the which
greatly accelerates rendering loops. A good command sequence to build a
display list may be :

The sample builds a scene graph from a vrml 2.0 file (exported via 3D Studio
Max only), then uses display lists. Each 3D mesh contains a list number,
and use a glCallList command instead of standards glBegin(GL_TRIANGLES)
commands when its list is built. A flag m_Modified permits to rebuild the
list when the mesh is modified.

SUPERIMPOSING WIREFRAME

Sometime you would like to view the wireframe superimposing the flat or
smooth shaded mesh. A good way to do this is to use the glPolygonOffset
command, which creates a z-buffer offset. The following code shows the
RenderScene function of the document, if one resumes two rendering passes
are necessary, the first render the mesh using lighted flat mode, the second
cut off the light, set the line mode, set a z-buffer offset, then draw
the mesh again.

FIG. 2. You can superimpose a wireframe on a flat-rendered
mesh, using a second rendering loop with the line option.

SMOOTH SUBDIVISION

From a given 3D mesh, how can we improve the geometric appearence on smooth
models ? The Charles Loop smooth subdivision comes here to help us. Each
triangle is divided in four triangles (see figure 3), and a filtering function
permits the mesh to be smoothed. The command is easy-to-use in the document,
and I let you discover the details in the mesh's code.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

nice work! I'd like to have some nice effect when I hoover the mouse over eash mesh, that the specific mesh the mouse is hoovering over, the mesh boundary will become highlighted (changed color, line thickness) and that I will know which triangle it is (number is fine), so I can keep track of a user selection..

I'm searching for a ActiveX or other Libary to draw 3d surfaces with Color from high, like you have done. I want to draw 3d Images i get from an Camera and display them with min 12Hz. Is this possible by using this aktiveX, and how shoud i do this?

I am implementing Transparency in Mesh Viewer. For that i have to change Alpha value. But when i change alpha value OF CCOLOR Class it hardly makes any difference. In that class Only m_Green,m_Red & m_Blue value been set.Even i m confused how thesse colors are transfered to OpenGl libraries or mesh.

Hey,
I have a VRML 2.0 file where i am giving the object a scale, and sound. when i run it in cosmo player it works perfectly, just the way i want it but when i run it in openGL, only the graphic is showing up. It doesn't play the sound and the scale doen'st work.Is there any way to make it work? am i missing any include file??

In the code file, i have
gstSeparator *rootSep;
gstSeparator *vrmlSep = new gstSeparator();
vrmlSep = gstReadVRMLFile("heart2.wrl");

won't the other things that i have in VRML file work? This is partially what i have in my VRML file.

IGES(*.igs),Neutral(*.neu),STEP(*.stp),STL(*.stl),Inventor(*.iv),
WaveFront(*.obj),Render(*.slp),ACIS File(*.sat),Assembly(*.asm).
Please give me some examples like the above "A small VRML viewer",thank you very much!

How to run 2 different(or same) OpenGL objects in one DialogBox?
IDC_STATIC1 is a first OpenGL objects Scene window.
IDC_STATIC2 is a second OpenGL objects Scene window.
IDC_STATIC1 and IDC_STATIC2 ,they are placed on IDD_DIALOG1.