Main Page   Class Hierarchy   Compound List   File List   Compound Members  

COpenGLWnd Class Reference

The OpenGL-enabled view with the rendering loop and basic interaction. More...

#include <OpenGLWnd.h>

Inheritance diagram for COpenGLWnd:

BaseOGLVRMLModelRenderer VRMLModelRenderer List of all members.

Public Types

enum  VGLR_RENDERING_MODE
 The rendering mode. More...


Public Member Functions

bool DrawBackgroundImage ()
 Draw the background image on the screen.

BOOL InitOpenGL ()
 Initialize OpenGL.

void SetContext ()
 Pre-render setup function.

void StartRenderingTimer ()
 Start the rendering timer.

void Init (VRMLModel *initModel)
 Initialise the renderer with a VRMLModel to render.

void RenderToScreen ()
 Render the model to screen.

void SetModelViewMatrix (GLfloat *m)
 Set the model view matrix (for camera control).

void ReSizeGLScene (GLsizei width, GLsizei height)
 Resize window.

void SetRenderingMode (VGLR_RENDERING_MODE newMode)
 Sets the renderingmode.

void LeftButtonDown (int x, int y)
 The interaction for pressing the left mouse button.

void RightButtonDown (int x, int y)
 The interaction for pressing the right mouse button.

void LeftButtonControlDown (int x, int y)
 The interaction for pressing the left mouse button while CTRL is held.

void LeftButtonDrag (int x, int y)
 The interaction for dragging the left mouse button.

void RightButtonDrag (int x, int y)
 The interaction for dragging the right mouse button.

void LeftButtonControlDrag (int x, int y)
 The interaction for dragging the left mouse button while CTRL is held.

void RightButtonDownTimerFunc ()
 The interaction for dragging the right mouse button.

void ToggleBackfaceCull ()
 Toggle backface culling.

void FitToScreen ()
 Re-positions model onscreen.

void FitToScreen (float zoom)
 Fits the model to screen with a zoom factor.

void Close ()
 Closes down and resets renderer.


Public Attributes

float renderingFrameRate
 Frame rate.


Protected Member Functions

afx_msg int OnCreate (LPCREATESTRUCT lpCreateStruct)
 Initialize OpenGL when window is created.

afx_msg void OnTimer (UINT nIDEvent)
 Timer callback.


Detailed Description

The OpenGL-enabled view with the rendering loop and basic interaction.

Handles all the basic OpenGL initializations and, through VRMLRenderer, provides the rendering and basic mouse and keyboard interaction (camera control, rendering modes). It can render one or more objects of type VRMLModel; these are typically the virtual character models, but other objects can be loaded and rendered in the scene.

Unless there are special needs other than regular real-time rendering and interaction, it is recommended to simply reuse this class as it is by copying the OpenGLWnd.cpp and OpenGLWnd.h files into your new project, and use it in the same way as demonstrated in the examples. If you are building a new application, the detailed step-by-step procedure is given in the section on Building a new application from scratch on the visage|SDK main page. In this case, it should not be necessary to enter the details of this class.

The rendering loop is implemented by starting a timer (InitOpenGL() function does this), so that the OnTimer function is called every mTIMER_RENDERING_INTERVAL milliseconds (default is 20 milliseconds). This function calls RenderToScreen() in order to draw the models. The actual drawing is performed in the base class BaseOGLVRMLModelRenderer. COpenGLWnd provides the hook to the MFC window.

This class implements the following interactions that are available to the user:

If it is desired to bypass the interactive camera control, it is possible to control the camera using the COpenGLWnd::SetModelViewMatrix() function.

In this example it is also demonstrated how to add a background image to the application. This is done in the function SetContext(), which is called in every frame before the rendering. This function is a good place to insert other effects as well.

For the user interested to modify the rendering process or implement their own, here is how it works. First, the renderer is initialized by calling COpenGLWnd::InitOpenGL() (this is done in COpenGLWnd::OnCreate() so the application developer does not need to do it). The COpenGLWnd::InitOpenGL() function initializes the rendering, and starts the rendering timer. The timer calls the function COpenGLWnd::RenderToScreen() (through the function OnTimer()) every 20 milliseconds (mTIMER_RENDERING_INTERVAL). The COpenGLWnd::RenderToScreen() renders all models that are attached to the renderer. The actual implementation of the rendering is in the parent class, BaseOGLVRMLModelRenderer::RenderToScreen(). The models are attached to the renderer using the COpenGLWnd::Init() function. In this example this is done in CExample1Doc::LoadVCModelFile(). Once the model is attached to the renderer, the renderer will keep rendering it until it is removed. Note that the rendering loop (implemented by the timer mechanism) and the animation loop(s) implemented by FAPlayer are running asynchronously in separate threads. The FAPlayer updates the VRMLModel in its animation loop, and the renderer (COpenGLWnd) renders it in every rendering cycle. To avoid rendering partially animated models, the flag VRMLModel::locked is used. This flag is set by both animation and rendering loops during critical operation to make sure that the other loop waits until the operation is finished. In this way, multiple virtual characters can be animated, each in its own FAPlayer running in a separate thread, and they are all rendered by the renderer.

Definition at line 69 of file OpenGLWnd.h.


Member Enumeration Documentation

enum COpenGLWnd::VGLR_RENDERING_MODE
 

The rendering mode.

The rendering mode can be:

  • VGLR_RENDERING_WIREFRAME for the wireframe mode
  • VGLR_RENDERING_AS_IS for the "standard" lighted, smooth shaded mode

Definition at line 216 of file OpenGLWnd.h.


Member Function Documentation

void COpenGLWnd::Close  )  [virtual]
 

Closes down and resets renderer.

Reimplemented from BaseOGLVRMLModelRenderer.

Definition at line 190 of file OpenGLWnd.cpp.

References BaseOGLVRMLModelRenderer::Close(), and SetContext().

bool COpenGLWnd::DrawBackgroundImage  ) 
 

Draw the background image on the screen.

Load the background image from the file background.jpg the first time this function is called. If loading is succesful, the image is drawn on the screen every time the function is called. This function is called by SetContext(), so it is executed at the beginning of every frame.

Returns:
true if image is succesfully drawn, 0 otherwise
See also:
SetContext()

Definition at line 779 of file OpenGLWnd.cpp.

Referenced by SetContext().

void COpenGLWnd::FitToScreen float  zoom  ) 
 

Fits the model to screen with a zoom factor.

The FitToScreen() function sometimes does not provide a satisfactory result. This function allows to correct by zooming in or out with respect to the original result produced by FitToScreen().

Parameters:
zoom The zoom factor. 1.0 is the regular fit. Bigger number zooms out (good for smaller windows).

Definition at line 1058 of file OpenGLWnd.cpp.

References RenderToScreen().

void COpenGLWnd::FitToScreen  ) 
 

Re-positions model onscreen.

Re-positions model onscreen based on the previously obtained measurements of the model. Basically, this resets the view.

Definition at line 1046 of file OpenGLWnd.cpp.

References RenderToScreen().

void COpenGLWnd::Init VRMLModel *  initModel  )  [virtual]
 

Initialise the renderer with a VRMLModel to render.

Standard rendering mode is set. The view is set such that the model is fully visible on screen.

This function can be called several times with different models in case more than one model is rendered. Up to 1000 models are supported.

Parameters:
initModel the model to load in the renderer.

Reimplemented from BaseOGLVRMLModelRenderer.

Definition at line 44 of file OpenGLWnd.cpp.

References VRMLFitToScreenTraverser::GetCoords(), BaseOGLVRMLModelRenderer::Init(), VRMLFitToScreenTraverser::Reset(), ReSizeGLScene(), VRMLModel::rootNode, SetContext(), SetRenderingMode(), and VRMLModel::traverse().

Referenced by CVisageLinkDoc::OnFileStart().

BOOL COpenGLWnd::InitOpenGL  ) 
 

Initialize OpenGL.

Perform necessary OpenGL initializations, including the startup of the rendering timer through StartRenderingTimer().

Definition at line 307 of file OpenGLWnd.cpp.

References StartRenderingTimer().

Referenced by OnCreate().

void COpenGLWnd::LeftButtonControlDown int  x,
int  y
 

The interaction for pressing the left mouse button while CTRL is held.

CTRL + left mouse button is used for zooming.

Parameters:
x x position of the mouse.
y y position of the mouse.

Definition at line 989 of file OpenGLWnd.cpp.

void COpenGLWnd::LeftButtonControlDrag int  x,
int  y
 

The interaction for dragging the left mouse button while CTRL is held.

CTRL + left mouse button is used for zooming.

Parameters:
x x position of the mouse.
y y position of the mouse.

Definition at line 1019 of file OpenGLWnd.cpp.

References RenderToScreen().

void COpenGLWnd::LeftButtonDown int  x,
int  y
 

The interaction for pressing the left mouse button.

The left mouse button is used for moving the model horizontaly and verticaly.

Parameters:
x x position of the mouse.
y y position of the mouse.

Definition at line 972 of file OpenGLWnd.cpp.

void COpenGLWnd::LeftButtonDrag int  x,
int  y
 

The interaction for dragging the left mouse button.

The left mouse button is used for moving the model horizontaly and verticaly.

Parameters:
x x position of the mouse.
y y position of the mouse.

Definition at line 995 of file OpenGLWnd.cpp.

References RenderToScreen().

void COpenGLWnd::OnTimer UINT  nIDEvent  )  [protected]
 

Timer callback.

This function is called by the timer. This is used to implement the rendering cycle.

Definition at line 505 of file OpenGLWnd.cpp.

References RenderToScreen(), and RightButtonDownTimerFunc().

void COpenGLWnd::RenderToScreen  )  [virtual]
 

Render the model to screen.

Render the loaded model to screen. If no model is loaded, clears the screen.

Reimplemented from BaseOGLVRMLModelRenderer.

Definition at line 122 of file OpenGLWnd.cpp.

References CMainFrame::m_wndStatusBar, renderingFrameRate, BaseOGLVRMLModelRenderer::RenderToScreen(), and SetContext().

Referenced by FitToScreen(), LeftButtonControlDrag(), LeftButtonDrag(), OnTimer(), and RightButtonDownTimerFunc().

void COpenGLWnd::ReSizeGLScene GLsizei  width,
GLsizei  height
 

Resize window.

Resize And Initialize The GL Window.

Parameters:
width the width of the window.
height the height of the window.

Definition at line 867 of file OpenGLWnd.cpp.

Referenced by Init().

void COpenGLWnd::RightButtonDown int  x,
int  y
 

The interaction for pressing the right mouse button.

The right mouse button is used for rotating the model.

Parameters:
x x position of the mouse.
y y position of the mouse.

Definition at line 978 of file OpenGLWnd.cpp.

void COpenGLWnd::RightButtonDownTimerFunc  ) 
 

The interaction for dragging the right mouse button.

The right mouse button is used for rotating the model. This function is called by a timer in order to keep rotating the model when the user drags the mouse with the right button down, then holds it in place while still keeping the button down.

Definition at line 1027 of file OpenGLWnd.cpp.

References RenderToScreen().

Referenced by OnTimer().

void COpenGLWnd::RightButtonDrag int  x,
int  y
 

The interaction for dragging the right mouse button.

The right mouse button is used for rotating the model.

Parameters:
x x position of the mouse.
y y position of the mouse.

Definition at line 1011 of file OpenGLWnd.cpp.

void COpenGLWnd::SetContext  ) 
 

Pre-render setup function.

This function is called before the rendering in each rendering cycle. It sets up the GL context and clears the screen to prepare for the next frame to be rendered.

This is a good place to insert the rendering of other objects in the scene, background image or similar.

Definition at line 546 of file OpenGLWnd.cpp.

References DrawBackgroundImage().

Referenced by Close(), Init(), and RenderToScreen().

void COpenGLWnd::SetModelViewMatrix GLfloat *  m  ) 
 

Set the model view matrix (for camera control).

This can be used to control the camera view. This matrix will be loaded using glLoadMatrixf(). glMatrixMode is set to GL_MODELVIEW. If m is 0, the default camera control mode is used. In the default mode, the renderer first sets the view automatically based on the size of the model, and then the camera is controlled interactively by the user using the mouse.

Parameters:
m the modelview matrix to be loaded.

Definition at line 888 of file OpenGLWnd.cpp.

void COpenGLWnd::SetRenderingMode VGLR_RENDERING_MODE  newMode  ) 
 

Sets the renderingmode.

The rendering mode can be:

  • VGLR_RENDERING_WIREFRAME for the wireframe mode
  • VGLR_RENDERING_AS_IS for the "standard" lighted, smooth shaded mode

Definition at line 900 of file OpenGLWnd.cpp.

Referenced by Init(), and ToggleBackfaceCull().

void COpenGLWnd::StartRenderingTimer  ) 
 

Start the rendering timer.

Start the timer for the rendering. After this, the OnTimer() function is automatically called every mTIMER_RENDERING_INTERVAL milliseconds, and in turn it calls the render function. Thus we have a rendering function call every mTIMER_RENDERING_INTERVAL milliseconds.

Definition at line 496 of file OpenGLWnd.cpp.

Referenced by InitOpenGL().

void COpenGLWnd::ToggleBackfaceCull  ) 
 

Toggle backface culling.

Toggle the backface culling on or off.

Definition at line 894 of file OpenGLWnd.cpp.

References SetRenderingMode().


Member Data Documentation

float COpenGLWnd::renderingFrameRate
 

Frame rate.

Calculated based on the last 50 rendered frames.

Definition at line 328 of file OpenGLWnd.h.

Referenced by RenderToScreen().


The documentation for this class was generated from the following files:
Generated on Wed Nov 8 16:13:38 2006 for VisageLink by doxygen 1.3.1