Collaboration diagram for Window Management:
Functions | |
int | glutCreateSubWindow (int parentID, int x, int y, int w, int h) |
int | glutCreateWindow (const char *title) |
void | glutDestroyWindow (int windowID) |
void | glutFullScreen (void) |
int | glutGetWindow (void) |
void * | glutGetWindowData (void) |
void | glutHideWindow (void) |
void | glutIconifyWindow (void) |
void | glutInitDisplayMode (unsigned int displayMode) |
void | glutInitDisplayString (const char *displayMode) |
void | glutInitWindowPosition (int x, int y) |
void | glutInitWindowSize (int width, int height) |
void | glutPopWindow (void) |
void | glutPositionWindow (int x, int y) |
void | glutPostRedisplay (void) |
void | glutPostWindowRedisplay (int windowID) |
void | glutPushWindow (void) |
void | glutReshapeWindow (int width, int height) |
void | glutSetCursor (int cursorID) |
void | glutSetIconTitle (const char *title) |
void | glutSetWindow (int ID) |
void | glutSetWindowData (void *data) |
void | glutSetWindowTitle (const char *title) |
void | glutShowWindow (void) |
void | glutSwapBuffers (void) |
void | glutWarpPointer (int x, int y) |
One way to divide OpenGLEAN windows is by these two categories:
...this is a good place to start, but will be seen to hardly be exhaustive of OpenGLEAN's options.
Each window has a unique identifier and OpenGL rendering context.
This section describes the OpenGLEAN API interface for creating, managing and closing windows. The section Window Callbacks describes the callback handlers that applications can provide to customise the behaviour of each window.
The desired position and size of a window is specified by glutInitWindowPosition() and glutInitWindowSize(). The display mode is specified by glutInitDisplayMode() or glutInitDisplayString() including RGBA color, double buffering, depth buffering and stencil buffering.
Once created with glutCreateWindow() windows can be controlled using:
A window is closed by calling glutDestroyWindow().
An application may open multiple top-level windows, each with optional subwindows. The current window is usually managed by the OpenGLEAN event loop, but also be explicitly controlled:
OpenGLEAN also provides the ability for application data to be associated with each window:
Of special note about window coordinates and dimensions (extracted from a freeglut comment formerly embedded in the og_state.c source file, with some editing):
There is considerable confusion about the "right thing to do" concerning window size and position. GLUT itself is not consistent between WIN32 and UNIX_X11. Since platform independence is a virtue, it was decided to break with GLUT's behaviour.
Under UNIX_X11, it is obviously not possible to get the window border sizes in order to subtract them off the window's initial position, until some time after the window has been created. Therefore it was decided to take the following behavior, on both UNIX_X11 and WIN32:
OpenGLEAN is at some liberty to change the latter point, perhaps. Because the window system can ignore or alter a client's request for window position and size, it is meaningless to query the window status until the window is open. At that time, we should be able to get full information about the window.
One further caveat: I have seen window managers that put the title bar on the side of the window. I believe that I have even seen managers that move the title bar dynamically if the size of the window changes (or perhaps the title lengths/shortens). All bets are off if the window manager is changed or reconfigured between the time that you get the coords and the time that you use them.
----
OpenGLEAN has numerous data structures that must be initialized before use. Additionally, OpenGLEAN supports some interaction with the user and environment during initialization---for example, setting the window size and position. In the same family, there are a few functions for letting the program set default values and make requests.
The glutInit*() functions cover these needs.
Bear in mind that:
|
Create a subwindow.
A subwindow lives inside of some other window (possibly a top-level window, possibly another subwindow). Because of this, it generally only interacts with other windows of your own creation, hence it is not subjected to a window manager. This is the primary source for its differences from a "normal" window:
Like a top-level window, you must register a display callback function if you wish to use glutMainloop(). A notable case where this function can fail is for offscreen windows. A coherent concept of a subwindow of an offscreen window would introduce more complication than is presently believed to be worthwhile. Attempting such a window presently just fails. Future OpenGLEAN versions may support offscreen subwindows. It is formally undefined whether the parent window contents are maintained "behind" subwindows (this allows a fairly natural way to implement offscreen subwindows: Make them simply offscreen windows, with an attachment to their parent). Offscreen subwinodws may be useful for testing complex applications without rendering to onscreen graphics. This routine can also return 0 (i.e., fail) if the parentID parent window cannot be found. Regardless of cause, failure by this function is denoted by a 0 window id being returned. It is a fatal error to call this function without first initializing OpenGLEAN via glutInit(). It is also a fatal error to call this function without having a current window. Subwindows can be very useful for partitioning a window into GUI elements: They have their own input callbacks, so you don't have to figure out which window an event is for. Graphics are clipped to the boundaries of your subwindows, so you do not need to worry much about where your drawing goes. Because windows and subwindows work almost identically from the perspective of a GLUT program, it is relatively easy to move a cluster of related controls into a separate top-level window---or, conversely, embed what was a top-level window inside of another window. OpenGLEAN can also report some basic statistics about your (sub)window, relieving you of the duty of tracking all of that information for yourself.
|
|
Create a new top-level window.
In fact, you must register a display callback via glutDisplayFunc() before you enter glutMainLoop(). For onscreen windows, you should not depend upon the window concretely existing or being visibile until you are told that it exists and is visible via a registered callback. The return value is an int. It should be positive for valid windows or 0 if failure occurred for some reason (Though traditional GLUT tends to bail out and abort rather than returning errors.) The integer is your window id. Old GLUT promises that these integers are ``small''; we do not reuse old ids, but do produce them sequentially. You can change the title later via glutSetWindowTitle(). A return value of 0 indicates an error. (By default, OpenGLEAN's glutCreateWindow() only returns if it will succeed.) It is a fatal error to call this function without first initializing OpenGLEAN via glutInit().
|
|
Destroy a window and associated subwindows.
Once a window has been destroyed, further attempts to use the window named by windowID are undefined. OpenGLEAN generally tries to be sensible, and should not recycle the dead windowID, but you should treat a destroyed window much like a pointer to deallocated memory and try not to use it. It is a fatal error to call this function without first properly initializing OpenGLEAN via glutInit().
|
|
Resize the current window to cover the entire screen The glutFullScreen() function resizes the window to cover the entire screen and hide window decorations such as title bars and icons. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Return the current window identifier, 0 if undefined glutGetWindow() returns the window id of the current window. This is useful, e.g., if you have a generic function that is used with several windows and it needs to temporarily change to another window. (There is no window stack for you to use with pushes and pops. Do not be confused by glutPushWindow() and glutPopWindow(); those pushes and pops are not stack-related!). One cause for the function to return 0 is if you have called glutDestroyWindow() on the current window and have done nothing to set a new window as current. It is a fatal error to call this function without first initializing OpenGLEAN via glutInit().
|
|
Get the user data for the current window This function will return whatever void* value is associated with the current window via glutSetWindowData(). This is NULL if you did not associate a pointer with your window. This can be useful in a situation where you have a single callback function performing services for many windows. You could keep track of the window ids in a global list and search for the current window in that list. But this is quicker than searching a data structure, and allows you to avoid the use of globals for this. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Make the current window hidden Even if a window is ``open'', it need not be visible. It may be convenient to hide a window rather than to close it, if you want to re-display the window at the same location and size, later. Redefining all of the OpenGLEAN features of a window and adding its window id to your tracking when re-opening a window may also be bothersome. So, rather than destroying it, you can simply ask for it to be hidden. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Iconify the current window Most window systems have some kind of ``minimized'' or ``iconified'' state for windows. All systems currently supported by OpenGLEAN do so. The exact meaning of iconification is somewhat system-dependant, but this makes a request of the window system to place the window into this state. Graphic output is usually suspended in this form. User input may be partially or wholly suspended. If and when your window is iconified by the window system, it may be uniconified at any time by the system. This usually happens at the request of a user. Because of this, you should not use this function to hide a window. Rather, it is to help unclutter the user's display, and is more or less consensual with the user. Use glutHideWindow() if you want to hide the window entirely. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Set the window creation display mode.
Allowable displayMode is a combination of:
Additionally, the following experimental features are implemented:
The following are defaults:
|
|
Set the window creation display mode.
The displayMode parameter is case-sensitive, and tokens are separated by ASCII TABs (\t) and SPACEs.
Additionally, the following are experimental.
|
|
Requests future windows to open at a given position.
|
|
Requests future windows to open at a given width/height..
There is a callback function to inform you of the new window shape (whether initially opened, changed by your glutReshapeWindow() request, or changed directly by the user). |
|
Request to raise the current window to the top Request that the current window be ``popped'' to the top. A window can be in front of or behind other windows, as determined by the z-order from front to back. Top-level OpenGLEAN windows can be placed at the front or back of the z-order by means of the glutPopWindow() and glutPushWindow() API functions. A z-order also applies to the subwindows of a top-level window. While the z-order of top-level windows can usually be adjusted by the user, subwindow z-order is controlled entirely by the application. If this has any effect on your window's visibility, you should receive a glutWindowStatusFunc() callback and a glutDisplayFunc() callback. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Request a change to the position of the current window.
It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Mark the current window as needing a redisplay. Whenever circumstances indicate that your window is in need of being redisplayed, you may call glutPostRedisplay() to tell OpenGLEAN that you want to redraw your graphics. Multiple calls to this function may be coalesced by OpenGLEAN to avoid excessive invocation of your drawing support. The ultimate effect of this function is to call your Display callback for the current window. It is a fatal error either to call this function without properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Mark an indicated window as needing a redisplay.
It is a fatal error to call this function without properly initializing OpenGLEAN via glutInit().
|
|
Request to lower the current window to the bottom. This function requests that the current window be ``pushed'' to the back. A window can be in front of or behind other windows, as determined by the z-order from front to back. Top-level OpenGLEAN windows can be placed at the front or back of the z-order by means of the glutPopWindow() and glutPushWindow() API functions. A z-order also applies to the subwindows of a top-level window. While the z-order of top-level windows can usually be adjusted by the user, subwindow z-order is controlled entirely by the application. There may not be an immediate effect to this function. Wait for the glutWindowStatusFunc() callback to tell you about whatever obscured/visible status your window achieves. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Request changing the size of the current window.
The window system may delay or even alter your request. Do not count on the size changing at all until you get a reshape callback. And always check the actual size passed to your reshape. Does not enforce relations between windows and subwindow size/position. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Set the cursor image to be used for the current window.
Additionally, there are the following special cases: GLUT_CURSOR_FULL_CROSSHAIR This cursor, where supported, draws a crosshair the full width and height of the display. It may be mapped by OpenGLEAN to the GLUT_CURSOR_CROSSHAIR, however. GLUT_CURSOR_NONE Turn the mouse cursor invisibile. GLUT_CURSOR_INHERIT Take the cursor that the parent window provides---this relationship is dynamic, so that changing the parent window will change all direct children with GLUT_CURSOR_INHERRIT. It is a fatal error either to call this function without properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Requests changing the iconified title of the current window.
As discussed under glutIconifyWindow(), most window systems allow a window to be placed in some kind of minimized, or iconified, state. In that state, the normal interior of the window is likely to be obscured, and the only clue about the window contents may be the window title. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Select the current window.
All OpenGL rendering goes to the current window. Many OpenGLEAN functions also implicitly use the current window. Many OpenGLEAN callback operations are tied to a window. When your callback is invoked, OpenGLEAN will set that particular window to be the current window. However, some callbacks---such as that registered via glutIdleFunc()---do not have associated windows. If a callback is not associated to a particular window, then when OpenGLEAN invokes that callback you should always use glutSetWindow() to select the appropriate window before doing any OpenGL rendering or doing any OpenGLEAN window-related operations. Even though in some cases you may be able to avoid this stipulation, it is best to always follow it. One reason is the lack of promise from OpenGLEAN to maintain any particular current window setting. Another reason is that your application may grow to use more windows, and you may find that as OpenGLEAN talks to each of your several windows (or you try to manage them), implicit assumptions about current window values may no longer hold. Lastly, this is a convenient way to select among multiple windows for drawing without actually waiting for that window's display callback. Simply set the current window and draw immediately. This is not always advisable, but may be practical. It is an error to set the current window to a non-existant window (e.g., one that you have closed). A warning will be printed on stderr if you try to do so, and the current window should be unchanged. To determine success, it is necessary to call glutGetWindow() and see if the new current window matches the one that you requested. It is a fatal error to call this function without first initializing OpenGLEAN via glutInit().
|
|
Set the user data for the current window.
It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Request changing the title of the current window.
Most window systems display a title for every (normal) top-level window in the system. The initial title is set when you call glutCreateWindow(). By means of this function you can set the titles for your top-level OpenGLEAN windows. Some window systems do not provide titles for windows, in which case this function may have no useful effect. Because the effect may be delayed or lost, you should not count on the effect of this function. However, it can be a nice touch to use the window title bar for a one-line status bar in some cases. Use discretion. If you just want one title for the window over the window's entire life, you should set it when you open the window with glutCreateWindow(). It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Request that the current window be visible glutShowWindow() requests that the window system make the current window visible. This is generally not necessary. When you create a window, it will normally become visible. Unless you specifically hide it, it will remain visible. Though visible, of course, it may be covered by other windows; that would be an issue for window stacking order not visibility. When, and if, your window's visibility status changes, you may find out via a glutWindowStatusFunc() callback. It is a fatal error either to call this function without first properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
|
Swaps the buffers for the current window. This function signals to OpenGLEAN that you are done drawing to the current window for now. If your window is double-buffered (GLUT_DOUBLE param to glutInitDisplayMode()), then OpenGLEAN will swap the front buffer with the back buffer. This also computes your current frame-rate and prints the result on stderr if indicated by the GLUT_FPS environment variable. The computed value is not necessarily the total frame rate, if you have multiple windows, as the statistic is the total number of buffer-swaps for the entire program. It is a fatal error either to call this function without properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
Here is the call graph for this function: |
|
Moves the mouse pointer to given window coordinates.
It is a fatal error either to call this function without properly initializing OpenGLEAN via glutInit() or to call this function without a current window.
|
Supported in part by SourceForge.net.
Generated on Fri Sep 16 20:15:34 2005 for OpenGLEAN by
doxygen 1.4.3
The OpenGLEAN project is hosted by
olib.org and
SourceForge.