# Visualization Library

A lightweight C++ OpenGL middleware for 2D/3D graphics

[Home] [Tutorials] [All Classes] [Grouped Classes]

# vl::OpenGLContext Class Reference

Represents an abstract GUI object containing an OpenGL context to which also keyboard, mouse or system events can be sent. More...

`#include <OpenGLContext.hpp>`

Inheritance diagram for vl::OpenGLContext:

List of all members.

## Public Member Functions

virtual const char * | className ()
| Returns the name of the class.
| OpenGLContext (int w=0, int h=0)
| Constructor.
| ~OpenGLContext ()
| Destructor.
void | initExtensions (bool log=true)
| Initializes the supported OpenGL extensions.
void | logOpenGLInfo ()
| Logs some information about the OpenGL context.
bool | isExtensionSupported (const char *ext_name)
| Returns true if the given extension is supported.
void * | getProcAddress (const char *function_name)
| Returns the address of an OpenGL extension function.
RenderTarget * | renderTarget ()
| The render target representing this OpenGL context.
const RenderTarget * | renderTarget () const
| The render target representing this OpenGL context.
ref< FBORenderTarget > | createFBORenderTarget (int width, int height)
| Creates a new FBORenderTarget (framebuffer object RenderTarget).
ref< FBORenderTarget > | createFBORenderTarget ()
| Equivalent to `"createFBORenderTarget(0,0);"`.
void | destroyFBORenderTarget (FBORenderTarget *fbort)
void | destroyAllFBORenderTargets ()
virtual void | quitApplication ()
| Asks to the windowing system that is managing the OpenGLContext to quit the application.
virtual void | destroy ()
virtual void | update ()
virtual void | setWindowTitle (const String &)
virtual bool | setFullscreen (bool fullscreen)
virtual void | show ()
virtual void | hide ()
virtual void | setPosition (int, int)
virtual void | setSize (int, int)
virtual ivec2 | position () const
virtual ivec2 | size () const
virtual bool | mouseVisible () const
virtual bool | fullscreen () const
virtual void | setMouseVisible (bool)
virtual void | getFocus ()
virtual void | swapBuffers ()
virtual void | makeCurrent ()
virtual void | setMousePosition (int x, int y)
void | setVSyncEnabled (bool enable)
bool | vsyncEnabled () const
virtual void | setContinuousUpdate (bool continuous)
bool | continuousUpdate () const
void | sortEventListeners ()
void | addEventListener (UIEventListener *el)
void | removeEventListener (UIEventListener *el)
void | eraseAllEventListeners ()
const std::vector< ref < UIEventListener > > & | eventListeners () const
UIEventListener * | eventListener (int i) const
int | eventListenerCount () const
const OpenGLContextFormat & | openglContextInfo () const
void | setOpenGLContextInfo (const OpenGLContextFormat &info)
void | ignoreNextMouseMoveEvent ()
int | width () const
int | height () const
void | dispatchResizeEvent (int w, int h)
void | dispatchMouseMoveEvent (int x, int y)
void | dispatchMouseUpEvent (EMouseButton button, int x, int y)
void | dispatchMouseDownEvent (EMouseButton button, int x, int y)
void | dispatchMouseWheelEvent (int n)
void | dispatchKeyPressEvent (unsigned short unicode_ch, EKey key)
void | dispatchKeyReleaseEvent (unsigned short unicode_ch, EKey key)
void | dispatchDestroyEvent ()
void | dispatchRunEvent ()
void | dispatchVisibilityEvent (bool visible)
void | dispatchInitEvent ()
| Dispatches the init event.
void | dispatchFileDroppedEvent (const std::vector< String > &files)
int | textureUnitCount () const
const std::set< EKey > & | keyboard () const
| Returns the std::set containing the currently pressed keys.
bool | isKeyPressed (EKey key) const
| Returns true if the given key is pressed.
void | keyPress (EKey key)
| For internal use only.
void | keyRelease (EKey key)
| For internal use only.

## Protected Attributes

ref< RenderTarget > | mRenderTarget
std::vector< ref < FBORenderTarget > > | mFBORenderTarget
std::vector< ref < UIEventListener > > | mEventListeners
std::set< EKey > | mKeyboard
OpenGLContextFormat | mGLContextInfo
bool | mMouseVisible
bool | mContinuousUpdate
bool | mIgnoreNextMouseMoveEvent
bool | mFullscreen
int | mTextureUnitCount

## Detailed Description

Represents an abstract GUI object containing an OpenGL context to which also keyboard, mouse or system events can be sent.

OpenGLContext is an abstract class that wraps a minimal common subset of GUI APIs like Win32, Qt, wxWidgets, SDL, GLUT, etc.
In order to respond to the events generated by the OpenGLContext you must subclass an UIEventListener and bind it to the OpenGLContext using the functions addEventListener(ref<UIEventListener>) and removeEventListener(ref<UIEventListener>).

OpenGLContext custom implementation
  - Key_Alt/Ctrl/Shift events must always be notified before Key_Left/Right-Alt/Ctrl/Shift events.
  - Always update the mKeyboard structure appropriately especially with respect to Key_[Left/Right]-Alt/Ctrl/Shift events.
  - When cycling through EventListeners to dispatch the events you must do it on a temporary copy of mEventListeners so that the EventListeners can safely add/remove themselves or other EventListeners to the OpenGLContext itself.

## Constructor & Destructor Documentation

vl::OpenGLContext::OpenGLContext | ( | int | w = `0`,
|  | int | h = `0` |
| ) |  |  | `[inline]`

Constructor.

vl::OpenGLContext::~OpenGLContext | ( |  | ) | `[inline]`

Destructor.

Dispatches also destroyEvent() to its event listeners.

## Member Function Documentation

virtual const char* vl::OpenGLContext::className | ( |  | ) | `[inline, virtual]`

Returns the name of the class.

Reimplemented from vl::Object.

void OpenGLContext::initExtensions | ( | bool | log = `true` | ) |

Initializes the supported OpenGL extensions.

void OpenGLContext::logOpenGLInfo | ( |  | ) |

Logs some information about the OpenGL context.

bool OpenGLContext::isExtensionSupported | ( | const char * | ext_name | ) |

Returns true if the given extension is supported.

Note:
  This is a relatively slow function, don't use it inside loops and similar.

void * OpenGLContext::getProcAddress | ( | const char * | function_name | ) |

Returns the address of an OpenGL extension function.

RenderTarget* vl::OpenGLContext::renderTarget | ( |  | ) | `[inline]`

The render target representing this OpenGL context.

The returned RenderTarget's dimensions will be automatically updated to the OpenGLContext's dimensions.

const RenderTarget* vl::OpenGLContext::renderTarget | ( |  | ) | const`[inline]`

The render target representing this OpenGL context.

The returned RenderTarget's dimensions will be automatically updated to the OpenGLContext's dimensions.

ref<FBORenderTarget> vl::OpenGLContext::createFBORenderTarget | ( | int | width,
|  | int | height |
| ) |  |  | `[inline]`

Creates a new FBORenderTarget (framebuffer object RenderTarget).

Note:
  A framebuffer object always belongs to an OpenGL context and in order to render on it the appropriate OpenGL context must be active.

ref<FBORenderTarget> vl::OpenGLContext::createFBORenderTarget | ( |  | ) | `[inline]`

Equivalent to `"createFBORenderTarget(0,0);"`.

void vl::OpenGLContext::destroyFBORenderTarget | ( | FBORenderTarget * | fbort | ) | `[inline]`

void vl::OpenGLContext::destroyAllFBORenderTargets | ( |  | ) | `[inline]`

virtual void vl::OpenGLContext::quitApplication | ( |  | ) | `[inline, virtual]`

Asks to the windowing system that is managing the OpenGLContext to quit the application.

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual void vl::OpenGLContext::destroy | ( |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWin32::Win32Window, vlMFC::MFCWindow, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual void vl::OpenGLContext::update | ( |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual void vl::OpenGLContext::setWindowTitle | ( | const String & |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual bool vl::OpenGLContext::setFullscreen | ( | bool | fullscreen | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, and vlGLUT::GLUTWindow.

virtual void vl::OpenGLContext::show | ( |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, and vlGLUT::GLUTWindow.

virtual void vl::OpenGLContext::hide | ( |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, and vlGLUT::GLUTWindow.

virtual void vl::OpenGLContext::setPosition | ( | int | ,
|  | int |  |
| ) |  |  | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual void vl::OpenGLContext::setSize | ( | int | ,
|  | int |  |
| ) |  |  | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, and vlGLUT::GLUTWindow.

virtual ivec2 vl::OpenGLContext::position | ( |  | ) | const`[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, and vlGLUT::GLUTWindow.

virtual ivec2 vl::OpenGLContext::size | ( |  | ) | const`[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWin32::Win32Context, and vlGLUT::GLUTWindow.

virtual bool vl::OpenGLContext::mouseVisible | ( |  | ) | const`[inline, virtual]`

virtual bool vl::OpenGLContext::fullscreen | ( |  | ) | const`[inline, virtual]`

virtual void vl::OpenGLContext::setMouseVisible | ( | bool |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual void vl::OpenGLContext::getFocus | ( |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, and vlGLUT::GLUTWindow.

virtual void vl::OpenGLContext::swapBuffers | ( |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual void vl::OpenGLContext::makeCurrent | ( |  | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

virtual void vl::OpenGLContext::setMousePosition | ( | int | x,
|  | int | y |
| ) |  |  | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget, vlWX::vlWXGLCanvas, vlWin32::Win32Context, vlGLUT::GLUTWindow, and vlSDL::SDLWindow.

void OpenGLContext::setVSyncEnabled | ( | bool | enable | ) |

bool OpenGLContext::vsyncEnabled | ( |  | ) | const

virtual void vl::OpenGLContext::setContinuousUpdate | ( | bool | continuous | ) | `[inline, virtual]`

Reimplemented in vlQt4::Qt4Widget.

bool vl::OpenGLContext::continuousUpdate | ( |  | ) | const`[inline]`

void OpenGLContext::sortEventListeners | ( |  | ) |

void OpenGLContext::addEventListener | ( | UIEventListener * | el | ) |

Note:
  An `UIEventListener` can be associated only to one OpenGLContext at a time.

void OpenGLContext::removeEventListener | ( | UIEventListener * | el | ) |

void OpenGLContext::eraseAllEventListeners | ( |  | ) |

const std::vector< ref<UIEventListener> >& vl::OpenGLContext::eventListeners | ( |  | ) | const`[inline]`

UIEventListener* vl::OpenGLContext::eventListener | ( | int | i | ) | const`[inline]`

int vl::OpenGLContext::eventListenerCount | ( |  | ) | const`[inline]`

const OpenGLContextFormat& vl::OpenGLContext::openglContextInfo | ( |  | ) | const`[inline]`

void vl::OpenGLContext::setOpenGLContextInfo | ( | const OpenGLContextFormat & | info | ) | `[inline]`

void vl::OpenGLContext::ignoreNextMouseMoveEvent | ( |  | ) | `[inline]`

int vl::OpenGLContext::width | ( |  | ) | const`[inline]`

int vl::OpenGLContext::height | ( |  | ) | const`[inline]`

void vl::OpenGLContext::dispatchResizeEvent | ( | int | w,
|  | int | h |
| ) |  |  | `[inline]`

void vl::OpenGLContext::dispatchMouseMoveEvent | ( | int | x,
|  | int | y |
| ) |  |  | `[inline]`

void vl::OpenGLContext::dispatchMouseUpEvent | ( | EMouseButton | button,
|  | int | x,
|  | int | y |
| ) |  |  | `[inline]`

void vl::OpenGLContext::dispatchMouseDownEvent | ( | EMouseButton | button,
|  | int | x,
|  | int | y |
| ) |  |  | `[inline]`

void vl::OpenGLContext::dispatchMouseWheelEvent | ( | int | n | ) | `[inline]`

void vl::OpenGLContext::dispatchKeyPressEvent | ( | unsigned short | unicode_ch,
|  | EKey | key |
| ) |  |  | `[inline]`

void vl::OpenGLContext::dispatchKeyReleaseEvent | ( | unsigned short | unicode_ch,
|  | EKey | key |
| ) |  |  | `[inline]`

void vl::OpenGLContext::dispatchDestroyEvent | ( |  | ) | `[inline]`

void vl::OpenGLContext::dispatchRunEvent | ( |  | ) | `[inline]`

void vl::OpenGLContext::dispatchVisibilityEvent | ( | bool | visible | ) | `[inline]`

void vl::OpenGLContext::dispatchInitEvent | ( |  | ) | `[inline]`

Dispatches the init event.

void vl::OpenGLContext::dispatchFileDroppedEvent | ( | const std::vector< String > & | files | ) | `[inline]`

int vl::OpenGLContext::textureUnitCount | ( |  | ) | const`[inline]`

const std::set<EKey>& vl::OpenGLContext::keyboard | ( |  | ) | const`[inline]`

Returns the std::set containing the currently pressed keys.

bool vl::OpenGLContext::isKeyPressed | ( | EKey | key | ) | const`[inline]`

Returns true if the given key is pressed.

void vl::OpenGLContext::keyPress | ( | EKey | key | ) | `[inline]`

For internal use only.

void vl::OpenGLContext::keyRelease | ( | EKey | key | ) | `[inline]`

For internal use only.

## Member Data Documentation

ref<RenderTarget> vl::OpenGLContext::mRenderTarget`[protected]`

std::vector< ref<FBORenderTarget> > vl::OpenGLContext::mFBORenderTarget`[protected]`

std::vector< ref<UIEventListener> > vl::OpenGLContext::mEventListeners`[protected]`

std::set<EKey> vl::OpenGLContext::mKeyboard`[protected]`

OpenGLContextFormat vl::OpenGLContext::mGLContextInfo`[protected]`

bool vl::OpenGLContext::mMouseVisible`[protected]`

bool vl::OpenGLContext::mContinuousUpdate`[protected]`

bool vl::OpenGLContext::mIgnoreNextMouseMoveEvent`[protected]`

bool vl::OpenGLContext::mFullscreen`[protected]`

int vl::OpenGLContext::mTextureUnitCount`[protected]`

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

- E:/VisualizationLibrary/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vl/OpenGLContext.hpp
- E:/VisualizationLibrary/BuildSystem/VL_DISTRO/Visualization_Library_SDK/src/vl/OpenGLContext.cpp

Visualization Library v2009.07 Reference Documentation
Copyright 2005-2009 Michele Bosi. All rights reserved.
Updated on Mon Aug 10 21:41:37 2009.
Permission is granted to use this page to write and publish articles regarding Visualization Library.