cViewport Class Reference
[Viewports]

cViewport describes a two-dimensional window for rendering an OpenGL scene. Basically this class encapsulates an OpenGL rendering context. Creating a window is left to the application programmer, since that will depend on the development environment that you're using. Once you have a window handle, use this class to bind it to an OpenGL context. More...

#include <CViewport.h>

List of all members.

Public Member Functions

 cViewport (HWND a_winHandle, cCamera *a_camera, const bool a_stereoEnabled=false, PIXELFORMATDESCRIPTOR *a_pixelFormat=0)
 Constructor of cViewport.
 ~cViewport ()
 Destructor of cViewport.
unsigned int getHeight () const
 Get height of active viewport area.
unsigned int getWidth () const
 Get width of active viewport area.
void setCamera (cCamera *a_camera)
 Set the camera through which this viewport will be rendered.
cCameragetCamera () const
 Get the camera through which this viewport is being rendered.
void setEnabled (const bool &a_enabled)
 Enable or disable rendering of this viewport.
bool getEnabled () const
 Get the rendering status of this viewport.
void setStereoOn (bool a_stereoEnabled)
 Enable or disable stereo rendering.
bool getStereoOn () const
 Is stereo rendering enabled?
bool select (const unsigned int a_windowPosX, const unsigned int a_windowPosY, cCollisionSettings *a_collisionSettings=NULL)
 Tell the viewport to figure out whether the (x,y) viewport coordinate is within a visible object.
cGenericObjectgetLastSelectedObject ()
 Get last selected mesh.
cTrianglegetLastSelectedTriangle ()
 Get last selected triangle.
cVector3d getLastSelectedPoint (void)
 Get last selected point position.
cVector3d getLastSelectedPointNormal (void)
 Get last selected point normal.
double getLastSelectedDistance (void)
 Get distance to last selected object.
bool render (const int imageIndex=CHAI_STEREO_DEFAULT)
 Call this method to render the scene in OpenGL.
virtual void onDisplayReset ()
HDC getGLDC ()
 Return a direct handle to the OpenGL viewing context.
const PIXELFORMATDESCRIPTOR * getPixelFormat ()
 Returns the pixel format used by this viewport.
bool update (bool resizeOnly=false)
 Reconfigures the display context.
void setPostRenderCallback (cGenericObject *a_postRenderCallback)
 Set post-render callback... the object you supply here will be rendered _after_ all other rendering.
cGenericObjectgetPostRenderCallback () const
 Get post-render callback.
void setRenderArea (RECT &r)
void getRenderArea (RECT &r)
 Read the rendering area.
cVector3d projectPoint (cVector3d &a_point)

Static Public Member Functions

static cViewportgetLastActiveViewport ()
 Return the last activated viewport. (Last Viewport for which the render() function was called).

Public Attributes

cCollisionRecorder m_collisionRecorder
 Last collision events with mouse.
int m_glViewport [4]
 It's useful to store the last viewport transformation, for gluProject'ing things.

Protected Member Functions

bool cleanup ()
 Clean up the current rendering context.
virtual bool renderView (const int a_imageIndex)
 Render the scene in OpenGL. Nukes the contents of the GL buffers.

Protected Attributes

cCameram_camera
 Virtual camera connected to this viewport.
bool m_enabled
 Status of viewport.
bool m_stereoEnabled
 Stereo status.
HWND m_winHandle
 Handle to window display.
HGLRC m_glContext
 OpenGL display context.
HDC m_glDC
 display context.
bool m_glReady
 GL Status.
RECT m_activeRenderingArea
RECT m_forceRenderArea
PIXELFORMATDESCRIPTOR m_pixelFormat
 Descriptor of the context opened for OpenGL rendering.
cGenericObjectm_postRenderCallback

Static Protected Attributes

static cViewportlastActiveViewport = 0


Detailed Description

cViewport describes a two-dimensional window for rendering an OpenGL scene. Basically this class encapsulates an OpenGL rendering context. Creating a window is left to the application programmer, since that will depend on the development environment that you're using. Once you have a window handle, use this class to bind it to an OpenGL context.

Typically a cViewport is connected to a cCamera for rendering, and a cCamera is typically connected to a cWorld, where objects actually live.


Constructor & Destructor Documentation

cViewport::cViewport ( HWND  a_winHandle,
cCamera a_camera,
const bool  a_stereoEnabled = false,
PIXELFORMATDESCRIPTOR *  a_pixelFormat = 0 
)

Constructor of cViewport.

Constructor of cViewport.

Parameters:
a_winHandle Handle to the actual win32 window.
a_camera The camera through which this viewport should be rendered.
a_stereoEnabled If true, a stereo rendering context is created.
a_pixelFormat If non-zero, this custom pixel format is used to initialize the viewport.


Member Function Documentation

void cViewport::onDisplayReset (  )  [virtual]

Clients should call this when the scene associated wit this viewport may need re-initialization, e.g. after a switch to or from fullscreen.

Clients should call this when the scene associated with this viewport may need re-initialization, e.g. after a switch to or from fullscreen. Automatically called from update() when the viewport creates a new GL context.

cVector3d cViewport::projectPoint ( cVector3d a_point  ) 

Project a world-space point from 3D to 2D, using my viewport xform, my camera's projection matrix, and his world's modelview matrix.

Project a world-space point from 3D to 2D, using my viewport xform, my camera's projection matrix, and his world's modelview matrix.

Parameters:
a_point The point to transform
Returns:
The transformed point in window space

bool cViewport::render ( const int  imageIndex = CHAI_STEREO_DEFAULT  ) 

Call this method to render the scene in OpenGL.

Call this method to render the OpenGL world inside the viewport.

The default rendering option (CHAI_STEREO_DEFAULT) tells the viewport to decide whether it's rendering in stereo, and - if so - to render a full stereo pair. The other rendering options let you specify a specific image index (mono, left, or right).

The actual rendering is done in the renderView() function, once this function decides which frame to render.

Usually you want to use CHAI_STEREO_DEFAULT. The best reasons not to are:

(1) I have a stereo context, but sometimes I want to render in mono for a while. Alternatively, I could just disable stereo rendering temporarily.

(2) I have a stereo context, but I have a lot of computation to do and I want to get control back between the left and right frames.

Parameters:
imageIndex Either CHAI_STEREO_DEFAULT, CHAI_MONO, CHAI_STEREO_LEFT, or CHAI_STEREO_RIGHT
Returns:
Return true if operation succeeded.

bool cViewport::renderView ( const int  a_imageIndex  )  [protected, virtual]

Render the scene in OpenGL. Nukes the contents of the GL buffers.

Renders the OpenGL scene in the buffer specified by imageIndex.

Parameters:
a_imageIndex CHAI_MONO, CHAI_STEREO_LEFT or CHAI_STEREO_RIGHT
Returns:
Return true if operation succeeded.

bool cViewport::select ( const unsigned int  a_windowPosX,
const unsigned int  a_windowPosY,
cCollisionSettings a_collisionSettings = NULL 
)

Tell the viewport to figure out whether the (x,y) viewport coordinate is within a visible object.

Select an object on displayed in the viewport. This method casts a virtual ray through the viewport and asks the world for the first object hit by that ray.

It's most useful if you want to allow the user to use the mouse to click on objects in your virtual scene.

Use getLastSelectedObject(), getLastSelectedTriangle(), and getLastSelectedPoint() to extract information about the results of this operation.

Parameters:
a_windowPosX X coordinate position of mouse click.
a_windowPosY Y coordinate position of mouse click.
a_collisionSettings Settings used for performing collision detection.
Returns:
Return true if an object has been hit.

void cViewport::setCamera ( cCamera a_camera  ) 

Set the camera through which this viewport will be rendered.

Set camera. The viewport will now display the image filmed by this virtual camera.

Parameters:
a_camera Virtual camera in world.

void cViewport::setRenderArea ( RECT &  r  ) 

You can use this to specify a specific rectangle to which you want this viewport to render within the window. Supply -1 for each coordinate to return to the default behavior (rendering to the whole window). The _positive_ y axis goes _up_.

You can use this to specify a specific rectangle to which you want this viewport to render within the window. Supply -1 for each coordinate to return to the default behavior (rendering to the whole window). The _positive_ y axis goes _up_.

Parameters:
r The rendering area within the GL context

void cViewport::setStereoOn ( bool  a_stereoEnabled  ) 

Enable or disable stereo rendering.

Enable or disable stereo rendering on this viewport.

Note that it is not possible to change the pixel format of a window in Windows, so if you create a viewport that doesn't have stereo support, you can't enable stereo rendering without creating a new window/viewport.

bool cViewport::update ( bool  resizeOnly = false  ) 

Reconfigures the display context.

If the window has been modified, or just created, call this function to update the OpenGL display context.

Parameters:
resizeOnly If false (default), reinitializes the GL context.
Returns:
Return true if operation succeeded.


Member Data Documentation

cViewport * cViewport::lastActiveViewport = 0 [static, protected]

The most recent viewport to initiate rendering; useful for finding global opengl state information

The rectangle to which we're rendering within the GL window, equal to the window size by default. The _positive_ y axis goes _up_.

RECT cViewport::m_forceRenderArea [protected]

If we're forcing rendering to a particular rectangle within the viewport, this rectangle contains those coordinates. Otherwise all coordinates are -1, which tells cViewport to use the whole window. The _positive_ y axis goes _up_.

If non-zero, this object will get rendered immediately before the GL buffer is swapped out, after all other.


The documentation for this class was generated from the following files:


CHAI3D 2.0.0 documentation
Please address any questions to support@chai3d.org
(C) 2003-2009 - CHAI 3D
All Rights Reserved.