- Main Page
- Classes
- Files
- Directories

- Class List
- Class Hierarchy
- Class Members

# cViewport Class Reference

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.
cCamera * | getCamera () 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 | setPostRenderCallback (cGenericObject *a_postRenderCallback)
| Set post-render callback... the object you supply here will be rendered _after_ all other rendering.
cGenericObject * | getPostRenderCallback () const
| Get post-render callback.
void | setStereoOn (bool a_stereoEnabled)
| Enable or disable stereo rendering.
bool | getStereoOn () const
| Is stereo rendering enabled?
bool | render (const int imageIndex=CHAI_STEREO_DEFAULT)
| Render the scene in OpenGL.
const PIXELFORMATDESCRIPTOR * | getPixelFormat ()
| Returns the pixel format used by this viewport.
bool | select (const unsigned int a_windowPosX, const unsigned int a_windowPosY, const bool a_selectVisibleObjectsOnly)
| Tell the viewport to figure out whether the (x,y) viewport coordinate is within a visible object.
cGenericObject * | getLastSelectedObject ()
| Get last selected mesh.
cTriangle * | getLastSelectedTriangle ()
| Get last selected triangle.
cVector3d | getLastSelectedPoint (void)
| Get last selected point position.
double | getLastSelectedDistance (void)
| Get distance to last selected object.
virtual void | onDisplayReset ()
HDC | getGLDC ()
| Return a direct handle to the OpenGL viewing context.
void | setRenderArea (RECT &r)
bool | update (bool resizeOnly=false)
| Reconfigures the display context.
cVector3d | projectPoint (cVector3d &a_point)
## Public Attributes
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
cCamera * | m_camera
| Virtual camera connected to this viewport.
bool | m_enabled
| Status of viewport.
bool | m_stereoEnabled
| Stereo status.
cGenericObject * | m_lastSelectedObject
| Last selected mesh.
cTriangle * | m_lastSelectedTriangle
| Last selected triangle.
cVector3d | m_lastSelectedPoint
| Last selected point.
double | m_lastSelectedDistance
| Distance between camera and last selected point.
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.
cGenericObject * | m_postRenderCallback
## Static Protected Attributes
static cViewport * | lastActiveViewport = 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

cViewport::~cViewport | ( |  | ) |

Destructor of cViewport.

Destructor of cViewport.

## Member Function Documentation

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::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::render | ( | const int | imageIndex = `CHAI_STEREO_DEFAULT` | ) |

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::select | ( | const unsigned int | a_windowPosX,
|  | const unsigned int | a_windowPosY,
|  | const bool | a_selectVisibleObjectsOnly |
| ) |  |  |

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_selectVisibleObjectsOnly | Should we ignore invisible objects?

Returns:
  Return true if an object has been hit.

void cViewport::onDisplayReset | ( |  | ) | `[virtual]`

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

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

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.

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

Parameters:

  | a_point | The point to transform

Returns:
  The transformed point in window space

bool cViewport::cleanup | ( |  | ) | `[protected]`

Clean up the current rendering context.

Clean up the current rendering context

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 a_imageIndex

Parameters:

  | a_imageIndex | CHAI_MONO, CHAI_STEREO_LEFT or CHAI_STEREO_RIGHT

Returns:
  Return true if operation succeeded.

## Member Data Documentation

RECT cViewport::m_activeRenderingArea`[protected]`

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

cGenericObject* cViewport::m_postRenderCallback`[protected]`

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

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

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

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

- chai3d/src/display/CViewport.h
- chai3d/src/display/CViewport.cpp