#include <nglWindow.h>
Inheritance diagram for nglWindow:

A nglWindow gives you an OpenGL context for your GL work and a rendering window for this context. You must instantiate a nglWindow before calling any OpenGL functions. Since you can create any number of windows in an application, you must specify the context of your OpenGL code : even if you have only one window, enclose the OpenGL calls between BeginSession() and EndSession() calls.
The EndSession() method implicitly finishes the rendering (calling glFinish()) and triggers a buffer swap if the window is multi-buffered. If you render to multiple windows in parallel, it is legal to make successive calls to BeginSession() without calling the corresponding EndSession(). In other words, you can interleave BeginSession() and EndSession() calls at will.
Creating a window requires two pieces of information : OpenGL context info and general window properties (geometry and behaviour). The first info is given by the nglContextInfo object, while the second one is simply contained in a nglWindowInfo object.
Choosing an OpenGL context is not necessarily an easy task, and mainly not a very portable job. Keep in mind that the features you ask and get on your configuration might not (and won't) be available on every user's graphics card and OpenGL driver combination. Please have a closer look at the nglContextInfo documentation for this purpose.
Filling the nglWindowInfo is pretty simple. Note that you can change most of the properties later with various methods (excepted the Pos initial position hint, which only makes sense at construction time).
When you just created a new nglWindow instance, you should do in this order :
To effectively destroy the window and release the OpenGL context, simply delete the object.
Public Types | |
| typedef uint | Flags |
| typedef uint | EventMask |
| enum | StateChange { eHide, eShow, eMinimize } |
| enum | StateInfo { eHidden, eVisible } |
| enum | CursorModel { eCursorNone, eCursorArrow, eCursorCross, eCursorHand, eCursorHelp, eCursorWait, eCursorCaret, eCursorDnD, eCursorForbid, eCursorMove, eCursorResize, eCursorResizeNS, eCursorResizeWE, eCursorResizeN, eCursorResizeS, eCursorResizeW, eCursorResizeE, eCursorResizeNW, eCursorResizeNE, eCursorResizeSW, eCursorResizeSE } |
Public Member Functions | |
Life cycle | |
| nglWindow (uint Width, uint Height, bool IsFullScreen=false) | |
| nglWindow (const nglContextInfo &rContext, const nglWindowInfo &rInfo, const nglContext *pShared=NULL) | |
| virtual | ~nglWindow () |
Geometry | |
| uint | GetWidth () const |
| uint | GetHeight () const |
| void | GetSize (uint &rWidth, uint &rHeight) const |
| bool | SetSize (uint Width, uint Height) |
| void | GetPosition (int &rXPos, int &rYPos) const |
| bool | SetPosition (int XPos, int YPos) |
| bool | GetResolution (float &rHorizontal, float &rVertical) |
Appearance | |
| StateInfo | GetState () const |
| void | SetState (StateChange State) |
| nglString | GetTitle () const |
| void | SetTitle (const nglString &rTitle) |
| CursorModel | GetCursor () const |
| bool | SetCursor (CursorModel Cursor) |
Events control | |
| EventMask | GetEventMask () const |
| void | SetEventMask (EventMask Events) |
Extension | |
| const OSInfo * | GetOSInfo () const |
Mouse | |
| nglMouseInfo::Mode | GetMouseMode () const |
| void | SetMouseMode (nglMouseInfo::Mode Mode) |
| void | GetMouse (nglMouseInfo &rInfo, bool Local=true) const |
Keyboard | |
| bool | GetKeyRepeat () const |
| void | SetKeyRepeat (bool AllowRepeat=true) |
| bool | IsKeyDown (nglKeyCode Key) const |
Rendering | |
| virtual void | BeginSession () |
| virtual void | EndSession () |
| void | Invalidate () |
User callbacks | |
| virtual void | OnCreation () |
| virtual void | OnDestruction () |
| virtual void | OnActivation () |
| virtual void | OnDesactivation () |
| virtual void | OnClose () |
| virtual void | OnPaint () |
| virtual void | OnState (StateInfo State) |
| virtual void | OnResize (uint Width, uint Height) |
| virtual void | OnKeyDown (nglKeyCode Key, nglChar Char) |
| virtual void | OnKeyUp (nglKeyCode Key, nglChar Char) |
| virtual void | OnMouseClick (nglMouseInfo &rInfo) |
| virtual void | OnMouseUnclick (nglMouseInfo &rInfo) |
| virtual void | OnMouseMove (nglMouseInfo &rInfo) |
Static Public Member Functions | |
| static void | ParseArgs (nglContextInfo &rContext, nglWindowInfo &rInfo) |
| static const nglChar * | GetKeyName (nglKeyCode Key) |
Static Public Attributes | |
| static const Flags | NoFlag |
| static const Flags | NoResize |
| static const Flags | NoBorder |
| static const Flags | FullScreen |
| static const EventMask | NoEvents |
| static const EventMask | MouseEvents |
| static const EventMask | KeyEvents |
| static const EventMask | AllEvents |
Protected Member Functions | |
| virtual const nglChar * | OnError (uint &rError) const |
Classes | |
| class | OSInfo |
| < OS-specific properties More... | |
|
|
Controls the reception of keyboard and mouse events, see SetEventMask().
|
|
|
Used during nglWindow construction, see nglWindowInfo.
|
|
|
< See SetCursor() and GetCursor()
|
|
|
< See SetState()
|
|
|
< See GetState()
|
|
||||||||||||||||
|
Simple constructor for the lazy ones.
nglWindow* window; nglContextInfo context; // Fetch default context nglWindowInfo info; info.Width = Width; info.Height = Height; info.Flags = IsFullScreen ? FullScreen : NoFlag; window = new nglWindow (context, info, NULL); See nglContextInfo and nglWindowInfo for default settings. Important : do not put your window init code in your inherited class constructor, use the OnCreation() callback for this purpose. The reason being that the system objects might not be ready for use from the constructor. |
|
||||||||||||||||
|
Full constructor for the mighty ones.
pShared is non null, the newly created context will be shared with *pShared's one. Both windows will have distinct contexts working in parallel, but will share display lists and texture names. |
|
|
Immediatly destroy the window and release the OpenGL context. Important : you should put your window destroy code in the OnDestruction() callback rather than in the destructor. This callback will be called event if a delete is issued on the nglWindow object. |
|
|
Set the window OpenGL context as the current context. All further OpenGL calls will refer to this window context. Implements nglContext. |
|
|
Finish the rendering on the current OpenGL context (implicitly calls glFinish()) and swap frame buffers if appropriate). Implements nglContext. |
|
|
|
|
|
|
|
|
Return the current (user area) height.
|
|
|
Retrieve the human readable name of a physical key
|
|
|
|
|
||||||||||||
|
Get the current mouse position and button state.
Any number of button flags can be set in the rInfo.Buttons bit mask, except ButtonDoubleClick which does not make sense in this context. |
|
|
|
|
|
|
|
||||||||||||
|
Get the window (user area) position in screen coordinate space.
|
|
||||||||||||
|
Retrieve screen resolution in DPI (dots per inch).
|
|
||||||||||||
|
Get the window (user area) size.
|
|
|
|
|
|
|
|
|
Return the current (user area) width.
|
|
|
Append a paint event to the event queue. It means the OnPaint() callback will be called as soon as possible when you give the control back to the main loop. Only one paint event can be queued. Hence you can call Invalidate() many times before returning from an event handler, it will only trigger one paint event. |
|
|
Test a physical key state.
The key code cannot be converted to a printable character, since it would require the key context (wether a modifier like Alt, Ctl or Apple was hold, or a more complex composing method such as used on asiatic layouts). Use the OnKeyDown() callback if you want to interpret key strokes for text composing purposes. When a window looses its focus (see OnDesactivation()), all key states are reset (the keys are virtually released at once). |
|
|
This method is called when the window gets the focus, meaning it can receive keyboard and mouse events. |
|
|
This method is called when the user wants to close a displayed or iconified window.
The window will not be automatically destroyed, it is up to you to decide its fate. It is legal to call |
|
|
This method is called when the window object creation succeeded. You should put your init code here, and not in the constructor. |
|
|
This method is called when the window looses the focus, meaning it won't receive further keyboard and mouse events. |
|
|
This method is called when the window object is destroyed. You should put your destroy code here, and not in the destructor. |
|
|
const nglChar** ChildErrorTable = {_T("no error"), _T("Bad luck"), NULL}; const nglChar* Child::OnError (uint& rError) const { return FetchError(ChildErrorTable, Parent::OnError(rError), rError); } Reimplemented from nglContext. |
|
||||||||||||
|
This method is called when a key is pressed.
|
|
||||||||||||
|
This method is called when a key is released.
|
|
|
This method is called as soon as a mouse button is pressed.
ButtonDoubleClick and ButtonTripleClick bits might be set in aButton, together with the hit button flag. |
|
|
This method is called when a mouse motion is detected.
This event is only triggered if the window has the focus (ie. has received a OnActivation() event). |
|
|
This method is called when a mouse button is released.
ButtonDoubleClick and ButtonTripleClick bits cannot be set in Buttons. |
|
|
At least a part of the window must be redrawn. The window might have been explicitely invalidated by the programmer (see Invalidate()). |
|
||||||||||||
|
This method is called when the user resizes the window.
|
|
|
This method is called when the window display state changes.
|
|
||||||||||||
|
Command line options parser
|
|
|
Sets the window current cursor
|
|
|
Sets a new event mask
|
|
|
Sets key repeat mode
|
|
|
Sets current mouse mode
|
|
||||||||||||
|
Set the window (user area's top left corner) position in screen coordinate space.
|
|
||||||||||||
|
Sets the window user area size.
In fullscreen mode, this method is ignored. |
|
|
Change the window display state.
If the window is 'fullscreen', minimizing or withdrawing the window will restore the default desktop resolution, while showing it will switch back to the right video mode and restore the fullscreen mode. |
|
|
Sets the window current title.
|
|
|
Enable all events |
|
|
This window is full screen (a video mode switch occurs if necessary) |
|
|
Enable key events : OnKeyUp() and OnKeyDown() callbacks are controlled by this flag. |
|
|
Enable mouse events : OnMouseClick(), OnMouseUnclick() and OnMouseMove() callbacks are controlled by this flag. |
|
|
The window will have no decorations at all; often used for so called 'splash screens'. This type of window is implicitly not user-resizable however the NoResize flag can stay (independently) unset. |
|
|
Disable all events |
|
|
Use defaults (all flags unset) |
|
|
The window manager will prevent the user from resizing the window, however the programmer can still use nglWindow::SetSize with success. |
1.4.1