Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes | Protected Attributes | Static Protected Attributes | List of all members
BIAS::OpenGLCanvasBase Class Reference

base class for OpenGL canvases you could derive from to get base functionality (JW) More...

#include <Gui/OpenGLCanvasBase.hh>

+ Inheritance diagram for BIAS::OpenGLCanvasBase:
+ Collaboration diagram for BIAS::OpenGLCanvasBase:

Public Member Functions

virtual void Display ()
 main display call to be overridden by child classes usually displays: -InitWithContext (must be done and must eb first because setting up context may take some time while display is not setup correctly!) -Clear -Camera/virtual view -Geometry Implements instance More...
 
virtual void DisplayCalls ()
 
virtual void DisplayClear (const GLbitfield &mask=CLEAR_DEFAULT_MASK)
 clears buffers and resets virtual camera to identity More...
 
void DisplayCoordCross (const float &size=1.0f, const float &linewidth=1.0f)
 
virtual void DisplayRenderMode ()
 display default shade model, polygon mode, More...
 
void DisplaySelectBuffer ()
 useful for quadbuffered stereo, e.g. shutetr glasses More...
 
float GetAspectRatio () const
 GetAspectRatio is X/Y. More...
 
unsigned long GetFrameCount () const
 
unsigned int GetHeight () const
 
virtual void GetInfoGL (std::ostream &os)
 return GL state information More...
 
wxFrame * GetOwnerframe ()
 
float GetPixelValueDepth (const wxPoint &pos2d) const
 
BIAS::Vector3< float > GetPixelValueRGB (const wxPoint &pos2d)
 
BIAS::Vector4< float > GetPixelValueRGBA (const wxPoint &pos2d)
 
unsigned int GetWidth () const
 
virtual void InitMembers ()
 any constructor should call this function to initialize all data members (e.g. More...
 
virtual void InitWithContext ()
 init all things that need a context. More...
 
bool IsContextAvailable ()
 activates the current rendereing context if there is one and More...
 
virtual void OnChar (wxKeyEvent &event)
 
void OnEraseBackground (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 EVT handlers: ---------------------------------------—. More...
 
void OnSize (wxSizeEvent &event)
 
 OpenGLCanvasBase (wxFrame *parent, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=AsciiToWx("OpenGLCanvasBase"), int *attribList=NULL, const wxPalette &palette=wxNullPalette)
 
 OpenGLCanvasBase (wxFrame *parent, wxGLContext *sharedContext=NULL, wxWindowID id=-1, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=AsciiToWx("OpenGLCanvasBase"), int *attribList=NULL, const wxPalette &palette=wxNullPalette)
 constructor using a shared context More...
 
virtual std::ostream & PrintHelp (std::ostream &os)
 pop up keyboard layout help. More...
 
virtual void Reshape ()
 change of size and aspect ratio. More...
 
void ScreenShot (BIAS::ImageBase &dest, const bool &flipY=true, const GLenum &format=GL_RGB, const bool &force8Bit=false)
 
void ScreenShot (const std::string &filename, const bool &flipY=true, const GLenum &format=GL_RGB, const bool &force8Bit=false)
 
void ScreenShot ()
 JW automatic screenshot to file with filename based on frame, instance etc. More...
 
void SetFrameCount (const unsigned long &newVal)
 
void SetOwnerframe (wxFrame *ptr)
 
void SetStatusText (const wxString &text, const int c_field=0)
 let an OpenGL canvas use the status bar of the containing frame and cout as fallback (JW) More...
 
void ShowFPS (const int &framecounter, const float &minUpdateIntervalSec, const unsigned int &minNewFrames, const unsigned int nField)
 
shows FPS to status bar base don frame counter and last call to this function

Measures and updates only, if two conditions ar eboth met: More...

 
void ShowFPS ()
 simple interface for the above More...
 
void ShowValue (const wxPoint &pos)
 
void SwapBuffers ()
 expands parents SwapBUffers by automatic framecount increase More...
 
void ToggleFullScreen ()
 
BIAS::Vector3< float > Unproject (const wxPoint &pos2d, double &d)
 computes 3D coordinate from 2D+Z by "unprojection" JW More...
 
virtual void UpdateTime ()
 sets the internal time param, by default based on realtime wall clock More...
 
virtual ~OpenGLCanvasBase ()
 destructor More...
 

Static Public Member Functions

static void DisplaySampleScene ()
 display soem very simple Gl calls to draw something at all More...
 
static bool GetVSync ()
 
static void SetVSync (const bool &trueForOn)
 vertical sync control on or off (VSYNC) JW More...
 
static void StereoI_CaptureStereoImage (const int &format, const int &quality)
 
static float StereoI_GetConvergence ()
 
static void StereoI_GetInfo (std::ostream &os=std::cout)
 query status information on current NVStereo rendering state JW More...
 
static float StereoI_GetSeparation ()
 
static int StereoI_GetStereoState ()
 wrappers for StereoI interface More...
 
static int StereoI_Init ()
 interace to NVidias consumer Stereo NVStereo driver API. More...
 
static float StereoI_SetConvergence (const float &val)
 
static float StereoI_SetSeparation (const float &val)
 
static int StereoI_SetStereoState (const int &val)
 
static bool ToggleIP (bool &value)
 helper toggling a bool value in place More...
 
static bool ToggleVSync ()
 try to toggle VSync setting. More...
 

Static Public Attributes

static bool animationUpdateEnabled = OPENGLCANVASBASE_DEFAULT_animationUpdateEnabled
 
static double time = 0.0
 

Protected Attributes

unsigned long framecount_
 
bool InitWithContextDone_
 
unsigned int instance_
 
BIAS::DrawTextGLp_font
 
wxFrame * p_ownerframe
 
BIAS::RenderModeGL rendermode
 

Static Protected Attributes

static unsigned int instancesTotalNo_ = 0
 

Detailed Description

base class for OpenGL canvases you could derive from to get base functionality (JW)

Has minimal dependencies and minimal event interceptions, just functionality. 
Use a derrived class for automatic event handling. 
Supports shared GL context. 
The idea is that you usually just need to derive and reimplement the DisplayCalls() routine.
This clas is 
-NOT writing mous epos value to status bar
-NOT updating periodically.
See OpenGLCanvas for an extended version. 

TODO: page flipping stereo for windows mode (no fullscreen) TODO: handle multiple rendering contexts with different caabilites (e.g 2 differen GPUs) using "GLEW MX" TODO: add application controlled VSYNC enable/disable TODO: add application controlled antialiasing settings TODO: add keys for switching between 3D stereo rendering modes TODO: Rendertexture and Framebufferobject support? TODO: support for shared display lists and vertex buffer objects (VBO,VAR)?

Use the attriblist like RGBASD for setting the correct pixel formato rliek this:

   int attriblist[] =  {
      WX_GL_RGBA,
      WX_GL_MIN_RED, 1,
      WX_GL_MIN_GREEN, 1,
      WX_GL_MIN_BLUE, 1,
      WX_GL_MIN_ALPHA, 1,
      WX_GL_STENCIL_SIZE, 1,
      WX_GL_DOUBLEBUFFER,
      0
  };

Definition at line 149 of file OpenGLCanvasBase.hh.

Constructor & Destructor Documentation

OpenGLCanvasBase::~OpenGLCanvasBase ( )
virtual

destructor

Definition at line 76 of file OpenGLCanvasBase.cpp.

OpenGLCanvasBase::OpenGLCanvasBase ( wxFrame *  parent,
wxWindowID  id = -1,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxString &  name = AsciiToWx("OpenGLCanvasBase"),
int *  attribList = NULL,
const wxPalette &  palette = wxNullPalette 
)

Definition at line 85 of file OpenGLCanvasBase.cpp.

References InitMembers(), and p_ownerframe.

OpenGLCanvasBase::OpenGLCanvasBase ( wxFrame *  parent,
wxGLContext *  sharedContext = NULL,
wxWindowID  id = -1,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = 0,
const wxString &  name = AsciiToWx("OpenGLCanvasBase"),
int *  attribList = NULL,
const wxPalette &  palette = wxNullPalette 
)

constructor using a shared context

Definition at line 108 of file OpenGLCanvasBase.cpp.

References InitMembers(), and p_ownerframe.

Member Function Documentation

void OpenGLCanvasBase::Display ( )
virtual

main display call to be overridden by child classes usually displays: -InitWithContext (must be done and must eb first because setting up context may take some time while display is not setup correctly!) -Clear -Camera/virtual view -Geometry Implements instance

Author
Jan Woetzel.

begin your fancy GL calls (scene like)

<<< end of your GL calls

Reimplemented in BIAS::OpenGLCanvas.

Definition at line 294 of file OpenGLCanvasBase.cpp.

References DisplayCalls(), DisplayRenderMode(), DisplaySelectBuffer(), InitWithContext(), InitWithContextDone_, IsContextAvailable(), SwapBuffers(), and UpdateTime().

Referenced by BIAS::OpenGLCanvas::Display(), OnChar(), OnPaint(), and Reshape().

void OpenGLCanvasBase::DisplayCalls ( )
virtual

begin your fancy GL calls

<<< end of your GL calls

Reimplemented in BIAS::ImageCanvasGLBase, and BIAS::SimpleGLCanvas.

Definition at line 340 of file OpenGLCanvasBase.cpp.

References DisplayClear(), and DisplaySampleScene().

Referenced by Display().

void OpenGLCanvasBase::DisplayClear ( const GLbitfield &  mask = CLEAR_DEFAULT_MASK)
virtual

clears buffers and resets virtual camera to identity

Definition at line 407 of file OpenGLCanvasBase.cpp.

References BIAS::GeometryGL::DisplayClear().

Referenced by DisplayCalls().

void OpenGLCanvasBase::DisplayCoordCross ( const float &  size = 1.0f,
const float &  linewidth = 1.0f 
)
void OpenGLCanvasBase::DisplayRenderMode ( )
virtual

display default shade model, polygon mode,

Definition at line 414 of file OpenGLCanvasBase.cpp.

References BIAS::GeometryGL::DisplayRenderMode(), and rendermode.

Referenced by Display().

void OpenGLCanvasBase::DisplaySampleScene ( )
static

display soem very simple Gl calls to draw something at all

Definition at line 421 of file OpenGLCanvasBase.cpp.

References BIAS::GeometryGL::DisplaySceneExampleSimple().

Referenced by DisplayCalls().

void OpenGLCanvasBase::DisplaySelectBuffer ( )

useful for quadbuffered stereo, e.g. shutetr glasses

Definition at line 353 of file OpenGLCanvasBase.cpp.

References BIAS::RenderModeGL::drawbuffermode, BIAS::MONO, rendermode, BIAS::STEREO_CONSUMER_NV, BIAS::STEREO_LEFT_RIGHT, BIAS::STEREO_QUADBUFFERED, and BIAS::STEREO_UNTOUCHED.

Referenced by Display().

float OpenGLCanvasBase::GetAspectRatio ( ) const

GetAspectRatio is X/Y.

Returns
aspect 'X/Y' = ratio of width being 'bigger' than reference height

Definition at line 474 of file OpenGLCanvasBase.cpp.

References GetHeight(), and GetWidth().

Referenced by BIAS::OpenGLCanvas::Reshape().

unsigned long BIAS::OpenGLCanvasBase::GetFrameCount ( ) const
inline

Definition at line 301 of file OpenGLCanvasBase.hh.

unsigned int OpenGLCanvasBase::GetHeight ( ) const
void OpenGLCanvasBase::GetInfoGL ( std::ostream &  os)
virtual

return GL state information

return GL state info

Reimplemented in BIAS::OpenGLCanvas.

Definition at line 271 of file OpenGLCanvasBase.cpp.

References BIAS::GeometryGL::GetInfoGL(), instance_, and StereoI_GetInfo().

Referenced by BIAS::OpenGLCanvas::GetInfoGL(), and OnChar().

wxFrame * OpenGLCanvasBase::GetOwnerframe ( )

Definition at line 258 of file OpenGLCanvasBase.cpp.

References p_ownerframe.

float OpenGLCanvasBase::GetPixelValueDepth ( const wxPoint &  pos2d) const

Definition at line 520 of file OpenGLCanvasBase.cpp.

References GetHeight().

Referenced by ShowValue().

BIAS::Vector3< float > OpenGLCanvasBase::GetPixelValueRGB ( const wxPoint &  pos2d)
BIAS::Vector4< float > OpenGLCanvasBase::GetPixelValueRGBA ( const wxPoint &  pos2d)

Definition at line 501 of file OpenGLCanvasBase.cpp.

References GetHeight(), IsContextAvailable(), and BIAS::Vector4< T >::Set().

Referenced by ShowValue().

bool OpenGLCanvasBase::GetVSync ( )
static
@return true if vertical sync is enable, 

false for free running mode JW

Definition at line 1153 of file OpenGLCanvasBase.cpp.

References BIAS::SettingsGL::GetVSyncInterval().

Referenced by InitWithContext(), OnChar(), and ToggleVSync().

unsigned int OpenGLCanvasBase::GetWidth ( ) const
void OpenGLCanvasBase::InitMembers ( )
virtual

any constructor should call this function to initialize all data members (e.g.

pointers to NULL)

Reimplemented in BIAS::OpenGLCanvas, and BIAS::ImageCanvasGLBase.

Definition at line 132 of file OpenGLCanvasBase.cpp.

References animationUpdateEnabled, framecount_, InitWithContextDone_, instance_, and instancesTotalNo_.

Referenced by BIAS::OpenGLCanvas::InitMembers(), and OpenGLCanvasBase().

void OpenGLCanvasBase::InitWithContext ( )
virtual

init all things that need a context.

sets _InitWithContextDone

OK, we have a (valid) Gl Context run init with context once

Definition at line 143 of file OpenGLCanvasBase.cpp.

References BIAS::Singleton< GlutInitWrapper >::GetInstance(), GetVSync(), BIAS::GlutInitWrapper::Init(), BIAS::DrawTextGL::InitFont(), InitWithContextDone_, IsContextAvailable(), p_font, rendermode, SetVSync(), and BIAS::RenderModeGL::vsync.

Referenced by Display().

bool OpenGLCanvasBase::IsContextAvailable ( )

activates the current rendereing context if there is one and

Returns
true if gl rendering context is available, false if there is none available (yet).

Definition at line 224 of file OpenGLCanvasBase.cpp.

Referenced by Display(), GetPixelValueRGB(), GetPixelValueRGBA(), and InitWithContext().

void OpenGLCanvasBase::OnChar ( wxKeyEvent &  event)
virtual
void OpenGLCanvasBase::OnEraseBackground ( wxEraseEvent &  event)

Definition at line 1138 of file OpenGLCanvasBase.cpp.

void OpenGLCanvasBase::OnPaint ( wxPaintEvent &  event)

EVT handlers: ---------------------------------------—.

Definition at line 920 of file OpenGLCanvasBase.cpp.

References Display().

void OpenGLCanvasBase::OnSize ( wxSizeEvent &  event)

Definition at line 929 of file OpenGLCanvasBase.cpp.

References Reshape().

std::ostream & OpenGLCanvasBase::PrintHelp ( std::ostream &  os)
virtual

pop up keyboard layout help.

Must be virtual to let child class add their bindings

Definition at line 935 of file OpenGLCanvasBase.cpp.

Referenced by OnChar().

void OpenGLCanvasBase::Reshape ( )
virtual

change of size and aspect ratio.

Reimplemented in BIAS::OpenGLCanvas.

Definition at line 445 of file OpenGLCanvasBase.cpp.

References Display(), GetHeight(), and GetWidth().

Referenced by OnSize().

void OpenGLCanvasBase::ScreenShot ( BIAS::ImageBase dest,
const bool &  flipY = true,
const GLenum &  format = GL_RGB,
const bool &  force8Bit = false 
)
void OpenGLCanvasBase::ScreenShot ( const std::string &  filename,
const bool &  flipY = true,
const GLenum &  format = GL_RGB,
const bool &  force8Bit = false 
)

Definition at line 573 of file OpenGLCanvasBase.cpp.

References GetHeight(), GetWidth(), BIAS::ImageIO::Save(), and ScreenShot().

void OpenGLCanvasBase::ScreenShot ( )

JW automatic screenshot to file with filename based on frame, instance etc.

JW

Definition at line 687 of file OpenGLCanvasBase.cpp.

References framecount_, instance_, and BIAS::FileHandling::LeadingZeroString().

Referenced by OnChar(), and ScreenShot().

void BIAS::OpenGLCanvasBase::SetFrameCount ( const unsigned long &  newVal)
inline

Definition at line 302 of file OpenGLCanvasBase.hh.

void OpenGLCanvasBase::SetOwnerframe ( wxFrame *  ptr)

Definition at line 264 of file OpenGLCanvasBase.cpp.

References p_ownerframe.

void OpenGLCanvasBase::SetStatusText ( const wxString &  text,
const int  c_field = 0 
)

let an OpenGL canvas use the status bar of the containing frame and cout as fallback (JW)

Definition at line 747 of file OpenGLCanvasBase.cpp.

References p_ownerframe.

Referenced by OnChar(), ShowFPS(), and ShowValue().

void OpenGLCanvasBase::SetVSync ( const bool &  trueForOn)
static

vertical sync control on or off (VSYNC) JW

Definition at line 1144 of file OpenGLCanvasBase.cpp.

References BIAS::SettingsGL::SetVSyncInterval().

Referenced by InitWithContext(), and ToggleVSync().

void OpenGLCanvasBase::ShowFPS ( const int &  framecounter,
const float &  minUpdateIntervalSec,
const unsigned int &  minNewFrames,
const unsigned int  nField 
)

shows FPS to status bar base don frame counter and last call to this function

Measures and updates only, if two conditions ar eboth met:

  1. at least minUpdateIntervalSec seconds have passed since prvious update
  2. at least minNewFrames were drawn since a previous update Shouls handle multiplem, shared contextst correctly (jw). JW

Definition at line 826 of file OpenGLCanvasBase.cpp.

References BIAS::AsciiToWx(), and SetStatusText().

void OpenGLCanvasBase::ShowFPS ( )

simple interface for the above

Definition at line 906 of file OpenGLCanvasBase.cpp.

References framecount_.

Referenced by BIAS::OpenGLCanvas::OnIdle().

void OpenGLCanvasBase::ShowValue ( const wxPoint &  pos)
void OpenGLCanvasBase::StereoI_CaptureStereoImage ( const int &  format,
const int &  quality 
)
static

Definition at line 1303 of file OpenGLCanvasBase.cpp.

float OpenGLCanvasBase::StereoI_GetConvergence ( )
static

Definition at line 1287 of file OpenGLCanvasBase.cpp.

void OpenGLCanvasBase::StereoI_GetInfo ( std::ostream &  os = std::cout)
static

query status information on current NVStereo rendering state JW

Definition at line 1222 of file OpenGLCanvasBase.cpp.

References StereoI_Init().

Referenced by GetInfoGL(), OnChar(), and StereoI_Init().

float OpenGLCanvasBase::StereoI_GetSeparation ( )
static

Definition at line 1271 of file OpenGLCanvasBase.cpp.

int OpenGLCanvasBase::StereoI_GetStereoState ( )
static

wrappers for StereoI interface

Definition at line 1255 of file OpenGLCanvasBase.cpp.

int OpenGLCanvasBase::StereoI_Init ( )
static

interace to NVidias consumer Stereo NVStereo driver API.

to enable/disbale stereo and control convergence and separation for stereo rendering

Returns
0 on success, negative on error.
Author
Jan Woetzel

Definition at line 1181 of file OpenGLCanvasBase.cpp.

References StereoI_GetInfo().

Referenced by StereoI_GetInfo().

float OpenGLCanvasBase::StereoI_SetConvergence ( const float &  val)
static

Definition at line 1295 of file OpenGLCanvasBase.cpp.

float OpenGLCanvasBase::StereoI_SetSeparation ( const float &  val)
static

Definition at line 1279 of file OpenGLCanvasBase.cpp.

int OpenGLCanvasBase::StereoI_SetStereoState ( const int &  val)
static

Definition at line 1263 of file OpenGLCanvasBase.cpp.

void OpenGLCanvasBase::SwapBuffers ( )

expands parents SwapBUffers by automatic framecount increase

Definition at line 288 of file OpenGLCanvasBase.cpp.

References framecount_.

Referenced by Display().

void OpenGLCanvasBase::ToggleFullScreen ( )
bool OpenGLCanvasBase::ToggleIP ( bool &  value)
static

helper toggling a bool value in place

Returns
new value JW

Definition at line 1173 of file OpenGLCanvasBase.cpp.

bool OpenGLCanvasBase::ToggleVSync ( )
static

try to toggle VSync setting.

Returns
true if toggling worked, false if status persisted.

Definition at line 1159 of file OpenGLCanvasBase.cpp.

References GetVSync(), and SetVSync().

Referenced by OnChar().

BIAS::Vector3< float > OpenGLCanvasBase::Unproject ( const wxPoint &  pos2d,
double &  d 
)

computes 3D coordinate from 2D+Z by "unprojection" JW

Definition at line 536 of file OpenGLCanvasBase.cpp.

Referenced by ShowValue().

void OpenGLCanvasBase::UpdateTime ( )
virtual

sets the internal time param, by default based on realtime wall clock

Reimplemented in BIAS::OpenGLCanvas.

Definition at line 1168 of file OpenGLCanvasBase.cpp.

Referenced by Display(), and BIAS::OpenGLCanvas::UpdateTime().

Member Data Documentation

bool OpenGLCanvasBase::animationUpdateEnabled = OPENGLCANVASBASE_DEFAULT_animationUpdateEnabled
static

Definition at line 354 of file OpenGLCanvasBase.hh.

Referenced by InitMembers(), OnChar(), and BIAS::OpenGLCanvas::UpdateTime().

unsigned long BIAS::OpenGLCanvasBase::framecount_
protected

Definition at line 359 of file OpenGLCanvasBase.hh.

Referenced by InitMembers(), ScreenShot(), ShowFPS(), and SwapBuffers().

bool BIAS::OpenGLCanvasBase::InitWithContextDone_
protected

Definition at line 365 of file OpenGLCanvasBase.hh.

Referenced by Display(), InitMembers(), and InitWithContext().

unsigned int BIAS::OpenGLCanvasBase::instance_
protected

Definition at line 367 of file OpenGLCanvasBase.hh.

Referenced by GetInfoGL(), InitMembers(), and ScreenShot().

unsigned int OpenGLCanvasBase::instancesTotalNo_ = 0
staticprotected

Definition at line 368 of file OpenGLCanvasBase.hh.

Referenced by InitMembers().

BIAS::DrawTextGL* BIAS::OpenGLCanvasBase::p_font
protected

Definition at line 376 of file OpenGLCanvasBase.hh.

Referenced by DisplayCoordCross(), and InitWithContext().

wxFrame* BIAS::OpenGLCanvasBase::p_ownerframe
protected
BIAS::RenderModeGL BIAS::OpenGLCanvasBase::rendermode
protected
double OpenGLCanvasBase::time = 0.0
static

Definition at line 352 of file OpenGLCanvasBase.hh.

Referenced by BIAS::OpenGLCanvas::UpdateTime().


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