Support Forum G3D Web Page |
Interface to window APIs for window management, event processing, and OpenGL context management.
More...
Inherited by G3D::GLFWWindow.
Classes | |
class | Settings |
Public Member Functions | |
virtual | ~OSWindow () |
Closes the window and frees any resources associated with it. More... | |
virtual String | caption ()=0 |
The window title. More... | |
virtual String | className () const =0 |
virtual Rect2D | clientRect () const =0 |
Size of the inside of the window (the part that the program can render to) More... | |
virtual void | decInputCaptureCount () |
virtual void | decMouseHideCount () |
virtual void | fireEvent (const GEvent &event) |
Inserts an event into the queue. More... | |
const shared_ptr< Framebuffer > & | framebuffer () const |
Returns the Framebuffer object for this window modeling the OpenGL "Hardware framebuffer", which is not an OpenGL object. More... | |
virtual Rect2D | fullRect () const =0 |
Shape of the window, including borders More... | |
virtual String | getAPIName () const =0 |
Description of the windowing API for logging purposes (e.g. More... | |
virtual String | getAPIVersion () const =0 |
Description of the windowing API for logging purposes (e.g. More... | |
virtual void | getDroppedFilenames (Array< String > &files)=0 |
Clears the files array and then sets it to a list of all files that were dropped in the last GEventType::FILE_DROP event. More... | |
virtual void | getGameControllerState (unsigned int stickNum, Array< float > &axis, Array< bool > &button) const |
Remapping of getJoystickState() to be consistent on Windows and OS X for official Xbox360 game controllers. More... | |
virtual void | getJoystickState (unsigned int stickNum, Array< float > &axis, Array< bool > &button) const =0 |
Returns the state of the given joystick. More... | |
virtual void | getRelativeMouseState (Vector2 &position, uint8 &mouseButtons) const =0 |
Returns the current mouse position and the state of the mouse buttons. More... | |
virtual void | getRelativeMouseState (int &x, int &y, uint8 &mouseButtons) const =0 |
virtual void | getRelativeMouseState (double &x, double &y, uint8 &mouseButtons) const =0 |
virtual void | getSettings (OSWindow::Settings &settings) const =0 |
Return the actual properties of this window (as opposed to the desired settings from which it was initialized) More... | |
virtual bool | hasFocus () const =0 |
Returns true if this window currently has [keyboard] focus (i.e. More... | |
virtual int | height () const =0 |
virtual void | hide () const |
virtual void | incInputCaptureCount () |
virtual void | incMouseHideCount () |
int | inputCaptureCount () const |
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. More... | |
virtual bool | isIconified () const |
Methods for returning and setting whether a window is iconified: currently, these are only implemented in GLFWWindow, so in any other case isIconified() returns false. More... | |
virtual String | joystickName (unsigned int sticknum) const =0 |
The name by which the OS refers to this joystick (e.g. More... | |
void | makeCurrent () const |
Makes the OpenGL context of this window current. More... | |
int | mouseHideCount () const |
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. More... | |
virtual int | numJoysticks () const =0 |
Returns 0 if there are no joysticks available. More... | |
virtual bool | pollEvent (GEvent &e) |
Checks to see if any events are waiting. More... | |
virtual void | popLoopBody () |
Pops a loop body off the stack. More... | |
virtual void | pushLoopBody (void(*body)(void *), void *arg) |
Pushes a function onto the stack of functions called by runMainLoop. More... | |
virtual void | pushLoopBody (GApp *app) |
Invokes GApplet::beginRun after the applet is on the stack. More... | |
RenderDevice * | renderDevice () const |
If a RenderDevice has been created and initialized for this window, returns that renderDevice. More... | |
virtual bool | requiresMainLoop () const |
Windows for which this is true require a program to hand control of the main loop to OSWindow::startMainLoop. More... | |
virtual void | runMainLoop () |
Executes an event loop, invoking callback repeatedly. More... | |
virtual void | setCaption (const String &caption)=0 |
virtual void | setClientPosition (int x, int y)=0 |
virtual void | setClientRect (const Rect2D &dims)=0 |
virtual void | setFullPosition (int x, int y)=0 |
Fails silently if unable to change the position. More... | |
virtual void | setFullRect (const Rect2D &dims)=0 |
Fails silently if unable to change the dimensions. More... | |
virtual void | setGammaRamp (const Array< uint16 > &gammaRamp)=0 |
gammaRamp.length() = 256 More... | |
virtual void | setIcon (const shared_ptr< Image > &image) |
Set the icon (if supported). More... | |
virtual void | setIcon (const String &imageFilename) |
virtual void | setIconified (bool b) |
void | setInputCaptureCount (int c) |
void | setMouseHideCount (int c) |
virtual void | setRelativeMousePosition (double x, double y)=0 |
virtual void | setRelativeMousePosition (const Vector2 &p)=0 |
Relative to the window origin. More... | |
const Settings & | settings () const |
virtual void | show () const |
virtual void | swapGLBuffers ()=0 |
Swap the OpenGL front and back buffers. More... | |
virtual int | width () const =0 |
Measured in pixels, this is the client area of the window. More... | |
Static Public Member Functions | |
static String | clipboardText () |
Uses the current() OSWindow instance to obtain text from the operating system clipboard. More... | |
static OSWindow * | create (const Settings &s=Settings()) |
Creates the default instance for this platform: More... | |
static const OSWindow * | current () |
static void | getFullScreenResolutions (Array< Vector2int32 > &array) |
Enumerates all full-screen resolutions. More... | |
static int | numDisplays () |
Number of physical displays (e.g., monitors) reported by the operating system. More... | |
static void | popGraphicsContext () |
Pop window off the top of the stack. More... | |
static float | primaryDisplayRefreshRate (int width, int height) |
Return the maximum refresh rate supported at or above this resolution. More... | |
static Vector2 | primaryDisplaySize () |
Dimensions in pixels of the primary display. More... | |
static Vector2int32 | primaryDisplayWindowSize () |
Dimensions in pixels of a maximized (but not full-screen) window on the primary display. More... | |
static void | pushGraphicsContext (OSWindow *window) |
Push the current window on the stack. More... | |
static void | setClipboardText (const String &text) |
Uses the current() OSWindow instance to put text on the operating system clipboard. More... | |
static Vector2 | virtualDisplaySize () |
Dimensions of the bounding rectangle of all displays. More... | |
Protected Member Functions | |
OSWindow () | |
virtual String | _clipboardText () const =0 |
virtual void | _setClipboardText (const String &text) const =0 |
void | executeLoopBody () |
Subclasses should call from their idle function. More... | |
virtual void | getOSEvents (Queue< GEvent > &events) |
Extract new events from the underlying operating system. More... | |
virtual void | handleResize (int width, int height) |
Handles updating size settings and viewport for window size changes. More... | |
bool | notDone () |
virtual void | setAsCurrentGraphicsContext () const =0 |
Override this with the glMakeCurrent call appropriate for your window. More... | |
virtual void | setInputCapture (bool c)=0 |
Capture the keyboard and mouse focus, locking the mouse to the client area of this window. More... | |
virtual void | setMouseVisible (bool b)=0 |
Protected Attributes | |
Queue< GEvent > | m_eventQueue |
shared_ptr< Framebuffer > | m_framebuffer |
int | m_inputCaptureCount |
int | m_mouseHideCount |
RenderDevice * | m_renderDevice |
Settings | m_settings |
Use this to maintain settings in sub-classes. More... | |
Friends | |
class | RenderDevice |
Interface to window APIs for window management, event processing, and OpenGL context management.
A OSWindow 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.
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) not already implemented in G3D.
All dimensions are of the client area (inside the frame, if the window has a frame).
All mouse and window coordinates are in true device pixels. For logical pixels on high-DPI displays, adjust using GLFWWindow::defaultGuiPixelScale(). Alternatively, the GuiXXX classes take the logical scale into account for your.
After instantiation, a OSWindow guarantees that the OpenGL context for this window is bound. It may be unbound by later code–use OSWindow::makeCurrent if you have multiple windows in your application.
Subclassing
It is common to accept a OSWindow::Settings as an argument to the constructor. OSWindow provides a protected variable OSWindow::m_settings to manage the window settings.
Subclasses are required to call GLCaps::init from the end of their constructor/create function to finish initializing OpenGL.
|
inlineprotected |
|
inlinevirtual |
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.
|
protectedpure virtual |
Implemented in G3D::GLFWWindow.
|
protectedpure virtual |
Implemented in G3D::GLFWWindow.
|
pure virtual |
The window title.
Implemented in G3D::GLFWWindow.
|
pure virtual |
Implemented in G3D::GLFWWindow.
|
pure virtual |
Size of the inside of the window (the part that the program can render to)
Implemented in G3D::GLFWWindow.
Referenced by G3D::FullScreenWidget::bounds().
|
static |
Creates the default instance for this platform:
|
inlinestatic |
|
inlinevirtual |
|
inlinevirtual |
|
protected |
Subclasses should call from their idle function.
Referenced by runMainLoop().
|
virtual |
Inserts an event into the queue.
const shared_ptr<Framebuffer>& G3D::OSWindow::framebuffer | ( | ) | const |
Returns the Framebuffer object for this window modeling the OpenGL "Hardware framebuffer", which is not an OpenGL object.
This framebuffer has a size and format (determined by querying OpenGL on construction) but cannot have attachments.
|
pure virtual |
Shape of the window, including borders
Implemented in G3D::GLFWWindow.
|
pure virtual |
Description of the windowing API for logging purposes (e.g.
"SDL").
Implemented in G3D::GLFWWindow.
|
pure virtual |
Description of the windowing API for logging purposes (e.g.
"1.2.7" for SDL 1.2.7).
Implemented in G3D::GLFWWindow.
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::GLFWWindow.
|
static |
Enumerates all full-screen resolutions.
|
virtual |
Remapping of getJoystickState() to be consistent on Windows and OS X for official Xbox360 game controllers.
|
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 assertion fails if stickNum > numJoysticks(). Joystick axes are normalized to the range -1, 1. Joystick axes should be in the starting order: X, Y, Z, Slider1, Slider2, rX, rY, rZ
There are few standards for joysticks. Different joysticks may have different mappings, and even a single joystick may be mapped differently on different operating systems or drivers.
Implemented in G3D::GLFWWindow.
Extract new events from the underlying operating system.
Reimplemented in G3D::GLFWWindow.
|
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.
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::GLFWWindow.
|
pure virtual |
Implemented in G3D::GLFWWindow.
|
pure virtual |
Implemented in G3D::GLFWWindow.
|
pure virtual |
Return the actual properties of this window (as opposed to the desired settings from which it was initialized)
Implemented in G3D::GLFWWindow.
|
protectedvirtual |
Handles updating size settings and viewport for window size changes.
Referenced by G3D::GLFWWindow::handleResizeFromCallback().
|
pure virtual |
Returns true if this window currently has [keyboard] focus (i.e.
is in the foreground, not minimized, recieves keystrokes.)
Implemented in G3D::GLFWWindow.
|
pure virtual |
Implemented in G3D::GLFWWindow.
Referenced by G3D::MonitorXR::MonitorHMD::getResolution().
|
inlinevirtual |
Reimplemented in G3D::GLFWWindow.
|
inlinevirtual |
|
inlinevirtual |
|
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.
Referenced by decInputCaptureCount(), and incInputCaptureCount().
|
inlinevirtual |
Methods for returning and setting whether a window is iconified: currently, these are only implemented in GLFWWindow, so in any other case isIconified() returns false.
Reimplemented in G3D::GLFWWindow.
|
pure virtual |
The name by which the OS refers to this joystick (e.g.
"Gravis Gamepad")
Implemented in G3D::GLFWWindow.
|
inline |
Makes the OpenGL context of this window current.
If you have multiple windows, call this before rendering to one of them. beta
|
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.
Referenced by decMouseHideCount(), and incMouseHideCount().
|
inlineprotected |
Referenced by runMainLoop().
|
static |
Number of physical displays (e.g., monitors) reported by the operating system.
The OSWindow implementation calls the appropriate subclass override for the current operating system.
|
pure virtual |
Returns 0 if there are no joysticks available.
Implemented in G3D::GLFWWindow.
|
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.
|
static |
Pop window off the top of the stack.
|
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.
|
static |
Return the maximum refresh rate supported at or above this resolution.
|
static |
Dimensions in pixels of the primary display.
The OSWindow implementation calls the appropriate subclass override for the current operating system.
|
static |
Dimensions in pixels of a maximized (but not full-screen) window on the primary display.
Task bars and menus may make this smaller than the primaryDisplaySize().
The OSWindow implementation calls the appropriate subclass override for the current operating system.
|
static |
Push the current window on the stack.
|
inlinevirtual |
Pushes a function onto the stack of functions called by runMainLoop.
|
virtual |
Invokes GApplet::beginRun after the applet is on the stack.
|
inline |
If a RenderDevice has been created and initialized for this window, returns that renderDevice.
Otherwise returns nullptr.
|
inlinevirtual |
Windows for which this is true require a program to hand control of the main loop to OSWindow::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, nullptr); 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::GLFWWindow.
Referenced by runMainLoop().
|
inlinevirtual |
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 OSWindow 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.
|
protectedpure virtual |
Override this with the glMakeCurrent call appropriate for your window.
Protected because user methods should call push/pop methods.
Implemented in G3D::GLFWWindow.
|
pure virtual |
Implemented in G3D::GLFWWindow.
|
pure virtual |
Implemented in G3D::GLFWWindow.
|
pure virtual |
Implemented in G3D::GLFWWindow.
|
static |
|
pure virtual |
Fails silently if unable to change the position.
Sets the window (not client) position.
Implemented in G3D::GLFWWindow.
|
pure virtual |
Fails silently if unable to change the dimensions.
The value returned by getSettings will not change immediately– it waits for a size event to update.
Implemented in G3D::GLFWWindow.
gammaRamp.length() = 256
Implemented in G3D::GLFWWindow.
|
inlinevirtual |
Set the icon (if supported).
Fails silently if not supported or the window has no frame. May also fail if the OSWindow implementation's underlying GUI library is too limited.
image | May have any dimension supported by underlying OS. |
Reimplemented in G3D::GLFWWindow.
Referenced by setIcon().
|
inlinevirtual |
Reimplemented in G3D::GLFWWindow.
|
inlinevirtual |
Reimplemented in G3D::GLFWWindow.
|
protectedpure 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
Implemented in G3D::GLFWWindow.
Referenced by setInputCaptureCount().
|
inline |
Referenced by decInputCaptureCount(), and incInputCaptureCount().
|
inline |
Referenced by decMouseHideCount(), and incMouseHideCount().
|
protectedpure virtual |
Implemented in G3D::GLFWWindow.
Referenced by setMouseHideCount().
|
pure virtual |
Implemented in G3D::GLFWWindow.
|
pure virtual |
Relative to the window origin.
Implemented in G3D::GLFWWindow.
|
inline |
|
inlinevirtual |
Reimplemented in G3D::GLFWWindow.
|
pure virtual |
Swap the OpenGL front and back buffers.
Called by RenderDevice::endFrame.
Implemented in G3D::GLFWWindow.
|
static |
Dimensions of the bounding rectangle of all displays.
For a multi-monitor configuration, this is the net "display" size.
|
pure virtual |
Measured in pixels, this is the client area of the window.
Returns the same width as getSettings and clientDimensions(). Convenience method for users.
Implemented in G3D::GLFWWindow.
Referenced by G3D::MonitorXR::MonitorHMD::getResolution().
|
friend |
|
mutableprotected |
|
protected |
Referenced by inputCaptureCount(), and setInputCaptureCount().
|
protected |
Referenced by mouseHideCount(), and setMouseHideCount().
|
protected |
|
protected |
Use this to maintain settings in sub-classes.
Referenced by settings().