#include <OpenGLWnd.h>
Inheritance diagram for COpenGLWnd:
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. |
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.
|
The rendering mode. The rendering mode can be:
Definition at line 216 of file OpenGLWnd.h. |
|
Closes down and resets renderer.
Reimplemented from BaseOGLVRMLModelRenderer. Definition at line 190 of file OpenGLWnd.cpp. References BaseOGLVRMLModelRenderer::Close(), and SetContext(). |
|
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.
Definition at line 779 of file OpenGLWnd.cpp. Referenced by SetContext(). |
|
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().
Definition at line 1058 of file OpenGLWnd.cpp. References RenderToScreen(). |
|
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(). |
|
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.
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(). |
|
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(). |
|
The interaction for pressing the left mouse button while CTRL is held. CTRL + left mouse button is used for zooming.
Definition at line 989 of file OpenGLWnd.cpp. |
|
The interaction for dragging the left mouse button while CTRL is held. CTRL + left mouse button is used for zooming.
Definition at line 1019 of file OpenGLWnd.cpp. References RenderToScreen(). |
|
The interaction for pressing the left mouse button. The left mouse button is used for moving the model horizontaly and verticaly.
Definition at line 972 of file OpenGLWnd.cpp. |
|
The interaction for dragging the left mouse button. The left mouse button is used for moving the model horizontaly and verticaly.
Definition at line 995 of file OpenGLWnd.cpp. References RenderToScreen(). |
|
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(). |
|
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(). |
|
Resize window. Resize And Initialize The GL Window.
Definition at line 867 of file OpenGLWnd.cpp. Referenced by Init(). |
|
The interaction for pressing the right mouse button. The right mouse button is used for rotating the model.
Definition at line 978 of file OpenGLWnd.cpp. |
|
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(). |
|
The interaction for dragging the right mouse button. The right mouse button is used for rotating the model.
Definition at line 1011 of file OpenGLWnd.cpp. |
|
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(). |
|
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.
Definition at line 888 of file OpenGLWnd.cpp. |
|
Sets the renderingmode. The rendering mode can be:
Definition at line 900 of file OpenGLWnd.cpp. Referenced by Init(), and ToggleBackfaceCull(). |
|
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(). |
|
Toggle backface culling. Toggle the backface culling on or off. Definition at line 894 of file OpenGLWnd.cpp. References SetRenderingMode(). |
|
Frame rate. Calculated based on the last 50 rendered frames. Definition at line 328 of file OpenGLWnd.h. Referenced by RenderToScreen(). |