Contents User Forum Source Index APIs by Task APIs by Level Data


G3D::GWindow Class Reference

Interface to window APIs for window management, event processing, and OpenGL context management. More...

#include <GWindow.h>

Inherited by G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

List of all members.

Public Member Functions

virtual std::string caption ()=0
virtual void decInputCaptureCount ()
virtual void decMouseHideCount ()
virtual Rect2D dimensions () const=0
virtual void fireEvent (const GEvent &event)
virtual std::string getAPIName () const=0
virtual std::string getAPIVersion () const=0
virtual void getDroppedFilenames (Array< std::string > &files)=0
virtual void getJoystickState (unsigned int stickNum, Array< float > &axis, Array< bool > &button)=0
virtual void getRelativeMouseState (double &x, double &y, uint8 &mouseButtons) const =0
virtual void getRelativeMouseState (int &x, int &y, uint8 &mouseButtons) const =0
virtual void getRelativeMouseState (Vector2 &position, uint8 &mouseButtons) const=0
virtual void getSettings (GWindow::Settings &settings) const =0
virtual bool hasFocus () const=0
virtual int height () const=0
virtual void incInputCaptureCount ()
virtual void incMouseHideCount ()
int inputCaptureCount () const
virtual std::string joystickName (unsigned int sticknum)=0
void makeCurrent () const
int mouseHideCount () const
virtual void notifyResize (int w, int h)=0
virtual int numJoysticks () const=0
virtual bool pollEvent (GEvent &e)
virtual void popLoopBody ()
virtual void pushLoopBody (GApp *app)
virtual void pushLoopBody (void(*body)(void *), void *arg)
RenderDevicerenderDevice () const
virtual bool requiresMainLoop () const
virtual void runMainLoop ()
virtual void setCaption (const std::string &caption)=0
virtual void setDimensions (const Rect2D &dims)=0
virtual void setGammaRamp (const Array< uint16 > &gammaRamp)=0
virtual void setIcon (const std::string &imageFilename)
virtual void setIcon (const GImage &image)
void setInputCaptureCount (int c)
void setMouseHideCount (int c)
virtual void setPosition (int x, int y)=0
virtual void setRelativeMousePosition (const Vector2 &p)=0
virtual void setRelativeMousePosition (double x, double y)=0
virtual void swapGLBuffers ()=0
virtual int width () const=0
virtual ~GWindow ()

Static Public Member Functions

static const GWindowcurrent ()

Protected Member Functions

void executeLoopBody ()
 GWindow ()
bool notDone ()
virtual bool pollOSEvent (GEvent &e)
virtual void reallyMakeCurrent () const
virtual void setInputCapture (bool c)=0
virtual void setMouseVisible (bool b)=0

Protected Attributes

Queue< GEventm_eventQueue
int m_inputCaptureCount
int m_mouseHideCount

Friends

class RenderDevice

Classes

class  LoopBody
class  Settings


Detailed Description

Interface to window APIs for window management, event processing, and OpenGL context management.

A GWindow may be a user-level window, with a minimize button and frame, or simply a rectangular area within a larger window. In the latter case, several of the methods (e.g., setCaption) are likely to be ignored by the implementation. See G3D::SDLWindow and the wxWindows, Qt, and Glut implementations in the contrib directory.

Many parts of G3D assume that there is only one OS-level window, with one OpenGL context. (Although you can have multiple non-GL windows if using a native windowing API and you can even have multiple OpenGL contexts if you manage switching between them yourself).

Subclass this interface to support your preferred window system (e.g. ActiveX window, OS/X Carbon, MFC window, glut) or use the generic SDLWindow subclass that supports all platforms.

All dimensions are of the client area (inside the frame, if the window has a frame).

After instantiation, a GWindow guarantees that the OpenGL context for this window is bound. It may be unbound by later code--use GWindow::makeCurrent if you have multiple windows in your application.

Subclassing

It is common to accept a GWindowSettings as an argument to the constructor.

Subclasses are required to call GLCaps::init from the end of their constructor/create function to finish initializing OpenGL.

Input This class will be extended with UI events and constants in a future revision. For now it is limited to rendering and window management. Consider writing your own UserInput replacement in the mean time.

Implementations The following GWindow subclasses already exist: G3D::SDLWindow, G3D::Win32Window, wxGWindow (wxWidgets), GlutWindow, and QGWindow (Qt).

One typically chooses among these based on the GUI API used to manage the main window.


Constructor & Destructor Documentation

G3D::GWindow::GWindow (  )  [inline, protected]

virtual G3D::GWindow::~GWindow (  )  [inline, virtual]

Closes the window and frees any resources associated with it.

When subclassing, put any shutdown code (e.g. SDL_Quit()) in your destructor. Put initialization code (e.g. SDL_Init()) in the constructor.


Member Function Documentation

virtual std::string G3D::GWindow::caption (  )  [pure virtual]

The window title.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

static const GWindow* G3D::GWindow::current (  )  [inline, static]

virtual void G3D::GWindow::decInputCaptureCount (  )  [inline, virtual]

virtual void G3D::GWindow::decMouseHideCount (  )  [inline, virtual]

virtual Rect2D G3D::GWindow::dimensions (  )  const [pure virtual]

Shape of the client area of the window in screen coordinates.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

void G3D::GWindow::executeLoopBody (  )  [protected]

Subclasses should call from their idle function.

virtual void G3D::GWindow::fireEvent ( const GEvent event  )  [virtual]

Inserts an event into the queue.

virtual std::string G3D::GWindow::getAPIName (  )  const [pure virtual]

Description of the windowing API for logging purposes (e.g.

"SDL").

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual std::string G3D::GWindow::getAPIVersion (  )  const [pure virtual]

Description of the windowing API for logging purposes (e.g.

"1.2.7" for SDL 1.2.7).

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::getDroppedFilenames ( Array< std::string > &  files  )  [pure virtual]

Clears the files array and then sets it to a list of all files that were dropped in the last GEventType::FILE_DROP event.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::getJoystickState ( unsigned int  stickNum,
Array< float > &  axis,
Array< bool > &  button 
) [pure virtual]

Returns the state of the given joystick.

Not all sticks support all buttons and axes and frequently the state of one stick overlaps the state of another. An asserition fails if stickNum > numJoysticks(). Joystick axes are normalized to the range [-1, 1] (but might not be calibrated...). Joystick axes should be in the starting order: X, Y, Z, Slider1, Slider2, rX, rY, rZ

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::getRelativeMouseState ( double &  x,
double &  y,
uint8 mouseButtons 
) const [pure virtual]

virtual void G3D::GWindow::getRelativeMouseState ( int &  x,
int &  y,
uint8 mouseButtons 
) const [pure virtual]

virtual void G3D::GWindow::getRelativeMouseState ( Vector2 position,
uint8 mouseButtons 
) const [pure virtual]

Returns the current mouse position and the state of the mouse buttons.

It is essential to sample both simultaneously so that the mouse has not moved from the location where a click occurred.

Parameters:
position In pixels, with y=up. Relative to the upper left corner of the window.
mouseButtons If button i is currently pressed then bit i is set.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::getSettings ( GWindow::Settings settings  )  const [pure virtual]

Return the actual properties of this window (as opposed to the desired settings from which it was initialized).

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual bool G3D::GWindow::hasFocus (  )  const [pure virtual]

Returns true if this window currently has [keyboard] focus (i.e.

is in the foreground, not minimized, recieves keystrokes.)

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual int G3D::GWindow::height (  )  const [pure virtual]

virtual void G3D::GWindow::incInputCaptureCount (  )  [inline, virtual]

virtual void G3D::GWindow::incMouseHideCount (  )  [inline, virtual]

int G3D::GWindow::inputCaptureCount (  )  const [inline]

If the count is 1 or greater, then the keyboard and mouse focus is captured, locking the mouse to the client area of this window.

The use of a count instead of an explicit capture/release API allows multiple parts of a program to capture input without accidentally releasing and enclosing capture.

virtual std::string G3D::GWindow::joystickName ( unsigned int  sticknum  )  [pure virtual]

The name by which the OS refers to this joystick (e.g.

"Gravis Gamepad")

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

void G3D::GWindow::makeCurrent (  )  const [inline]

Makes the OpenGL context of this window current.

If you have multiple windows, call this before rendering to one of them. beta

int G3D::GWindow::mouseHideCount (  )  const [inline]

If the count is 1 or greater, then the keyboard and mouse focus is captured, locking the mouse to the client area of this window.

The use of a count instead of an explicit capture/release API allows multiple parts of a program to capture input without accidentally releasing and enclosing capture.

bool G3D::GWindow::notDone (  )  [inline, protected]

virtual void G3D::GWindow::notifyResize ( int  w,
int  h 
) [pure virtual]

Notifies the window that it has been resized (called by RenderDevice::notifyResize).

Some window systems (e.g. SDL) need explicit notification in this form when a resize event comes in.

Must not destroy the underlying OpenGL context (i.e. textures, vertex buffers, and GPU programs must be preserved across calls).

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual int G3D::GWindow::numJoysticks (  )  const [pure virtual]

Returns 0 if there are no joysticks available.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual bool G3D::GWindow::pollEvent ( GEvent e  )  [virtual]

Checks to see if any events are waiting.

If there is an event, returns true and fills out the GEvent structure. Otherwise returns false. The caller is responsible for invoking GWindow::notifyResize with any resize events; the GWindow does not notify itself.

virtual bool G3D::GWindow::pollOSEvent ( GEvent e  )  [protected, virtual]

Extract one event from the underlying operating system.

Reimplemented in G3D::CarbonWindow, and G3D::SDLWindow.

virtual void G3D::GWindow::popLoopBody (  )  [virtual]

Pops a loop body off the stack.

If the loop body was a GApplet, invokes GApplet::endRun on it. If the loop body was a GApp2, invokes GApp2::endRun on it.

virtual void G3D::GWindow::pushLoopBody ( GApp app  )  [virtual]

Invokes GApplet::beginRun after the applet is on the stack.

virtual void G3D::GWindow::pushLoopBody ( void(*)(void *)  body,
void *  arg 
) [inline, virtual]

Pushes a function onto the stack of functions called by runMainLoop.

virtual void G3D::GWindow::reallyMakeCurrent (  )  const [inline, protected, virtual]

Override this with the glMakeCurrent call appropriate for your window.

Reimplemented in G3D::SDLWindow, and G3D::Win32Window.

RenderDevice* G3D::GWindow::renderDevice (  )  const [inline]

If a RenderDevice has been created and initialized for this window, returns that renderDevice.

Otherwise returns NULL.

virtual bool G3D::GWindow::requiresMainLoop (  )  const [inline, virtual]

Windows for which this is true require a program to hand control of the main loop to GWindow::startMainLoop.

The program's functionality may then be implemented through the "loop body" function.

That is, if requiresMainLoop returns true, you must use the following structure:

           void doEvents() {
              GEvent e;
              while (window->pollEvent(e)) {
                  ... // Event handling
              } 
           }

           void doGraphics() {
              renderDevice->beginFrame();
                  renderDevice->clear(true, true, true);
                  ...  // draw stuff
              renderDevice->endFrame();
           }

           void loopBody(void*) {
all per-frame code; event-handling, physics, networking, AI, etc.
              doEvents();
              doLogic();
              doNetwork();
              doAI();
              doGraphics();

To end the program, invoke window->popLoopBody
           }

           window->pushLoopBody(callback, NULL);
           window->runMainLoop(); // doesn't return
        

When requiresMainLoop returns false, you may use either the above structure or the following one (which puts you in more control of when graphics vs. other code is executed):

            while (true) {
              doEvents();
              doLogic();
              doNetwork();
              doAI();
              doGraphics();
            }       
        

This design is necessary because some underlying Window APIs (e.g. ActiveX, GLUT) enforce an event-driven structure.

Reimplemented in G3D::CarbonWindow, and G3D::Win32Window.

virtual void G3D::GWindow::runMainLoop (  )  [inline, virtual]

Executes an event loop, invoking callback repeatedly.

Put everything that you want to execute once per frame into the callback function. It is guaranteed safe to call pollEvents and all other GWindow methods from the callback function.

The default implementation (for requiresMainLoop() == false GWindows) just calls the callback continuously. Subclasses should use the notDone() and executeLoopBody() functions.

virtual void G3D::GWindow::setCaption ( const std::string &  caption  )  [pure virtual]

virtual void G3D::GWindow::setDimensions ( const Rect2D dims  )  [pure virtual]

Fails silently if unable to change the dimensions.

The value returned by getSettings will not change immediately-- it waits for a notifyResize call.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::setGammaRamp ( const Array< uint16 > &  gammaRamp  )  [pure virtual]

virtual void G3D::GWindow::setIcon ( const std::string &  imageFilename  )  [inline, virtual]

virtual void G3D::GWindow::setIcon ( const GImage image  )  [inline, virtual]

Set the icon (if supported).

Fails silently if not supported or the window has no frame. May also fail if the GWindow implementation's underlying GUI library is too limited.

Parameters:
image May have any dimension supported by underlying OS.

Reimplemented in G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::setInputCapture ( bool  c  )  [protected, pure virtual]

Capture the keyboard and mouse focus, locking the mouse to the client area of this window.

Sets the inputCaptureCount to 1 if c is true and 0 if c is false

Deprecated:
use setInputCaptureCount

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

void G3D::GWindow::setInputCaptureCount ( int  c  )  [inline]

void G3D::GWindow::setMouseHideCount ( int  c  )  [inline]

virtual void G3D::GWindow::setMouseVisible ( bool  b  )  [protected, pure virtual]

Deprecated:
Use setMouseVisibleCount

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::setPosition ( int  x,
int  y 
) [pure virtual]

Fails silently if unable to change the position.

Sets the window (not client) position.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::setRelativeMousePosition ( const Vector2 p  )  [pure virtual]

Relative to the window origin.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual void G3D::GWindow::setRelativeMousePosition ( double  x,
double  y 
) [pure virtual]

virtual void G3D::GWindow::swapGLBuffers (  )  [pure virtual]

Swap the OpenGL front and back buffers.

Called by RenderDevice::endFrame.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.

virtual int G3D::GWindow::width (  )  const [pure virtual]

Measured in pixels, this is the client area of the window.

Returns the same width as getSettings and dimensions(). Convenience method for users.

Implemented in G3D::CarbonWindow, G3D::SDLWindow, and G3D::Win32Window.


Friends And Related Function Documentation

friend class RenderDevice [friend]


Member Data Documentation


The documentation for this class was generated from the following file:
Generated on Thu Aug 2 11:40:46 2007 for G3D by doxygen 1.5.2
Hosted by SourceForge.net Logo