Draft for Information Only
Content
Initialization Functions (Initialization) Sources and References
Initialization Functions (Initialization)
- Initialization Functions (Initialization)
Routines beginning with the glutInit- prefix are used to initialize GLUT state. The primary initialization routine is glutInit that should only be called exactly once in a GLUT program. No non-glutInit- pre- fixed GLUT or OpenGL routines should be called before glutInit.
The other glutInit- routines may be called before glutInit. The reason is these routines can be used to set default window initializationstate that might be modified by the command processing done in glutInit. For example, glutInitWindowSize(400, 400) can be called before glutInit to indicate 400 by 400 is the program’s default window size. Setting the initial window size or position before glutInit allows the GLUT program user to specify the initial size or position using command line arguments.
- glutInit (OpenGL GLUT 3.0)
glutInit is used to initialize the GLUT library.
- Usage
void glutInit(int *argcp, char **argv);
- argcp
A pointer to the program’s unmodified argc variable from main. Upon return, the value pointed to by argcp will be updated, because glutInit extracts any command line options intended for the GLUT library.
- argv
The program’s unmodified argv variable from main. Like argcp, the data for argv will be updated because glutInit extracts any command line options understood by the GLUT library.
- Description
glutInit will initialize the GLUT library and negotiate a session with the window system. During this pro- cess, glutInit may cause the termination of the GLUT program with an error message to the user if GLUT cannot be properly initialized. Examples of this situation include the failure to connect to the window system, the lack of window system support for OpenGL, and invalid command line options.
glutInit also processes command line options, but the specific options parse are window system depen- dent.
- X Implementation Notes
The X Window System specific options parsed by glutInit are as follows:
- -display DISPLAY Specify the X server to connect to. If not specified, the value of the DISPLAY environ- ment variable is used.
- -geometry WxH+X+Y Determines where window’s should be created on the screen. The parameter follow- ing -geometry should be formatted as a standard X geometry specification. The effect of using this option is to change the GLUT initial size and initial position the same as if glutInitWindowSize or glutInitWindowPosition were called directly.
- -iconic Requests all top-level windows be created in an iconic state.
- -indirect Force the use of indirect OpenGL rendering contexts.
- -direct Force the use of direct OpenGL rendering contexts (not all GLX implementations support direct rendering contexts). A fatal error is generated if direct rendering is not supported by the OpenGL imple- mentation. If neither -indirect or -direct are used to force a particular behavior, GLUT will attempt to use direct rendering if possible and otherwise fallback to indirect rendering.
- -gldebug After processing callbacks and/or events, check if there are any OpenGL errors by calling glGetError. If an error is reported, print out a warning by looking up the error code with gluErrorString. Using this option is helpful in detecting OpenGL run-time errors.
- -sync Enable synchronous X protocol transactions. This option makes it easier to track down potential X protocol errors.
- glutInitWindowPosition, glutInitWindowSize (OpenGL GLUT 3.0)
The glutInitWindowPosition and glutInitWindowSize functions specify a desired position and size for windows that freeglut will create in the future.
- Usage
void glutInitWindowPosition ( int x, int y );
void glutInitWindowSize ( int width, int height );
- width Width in pixels.
- height Height in pixels.
- x Window X location in pixels.
- y Window Y location in pixels.
- Description
The glutInitWindowPosition and glutInitWindowSize functions specify a desired position and size for windows that freeglut will create in the future. The position is measured in pixels from the upper left hand corner of the screen, with "x" increasing to the right and "y" increasing towards the bottom of the screen. The size is measured in pixels. freeglut does not promise to follow these specifications in creating its windows, but it certainly makes an attempt to.
The position and size of a window are a matter of some subtlety. Most windows have a usable area surrounded by a border and with a title bar on the top. The border and title bar are commonly called "decorations." The position of the window unfortunately varies with the operating system. On both Linux and Windows, you specify the coordinates of the upper left-hand corner of the window's decorations. Also for both operating systems, the size of the window is the size of the usable interior.
With glutGet information can be acquired about the current window's size, position and decorations. Note however that according to freeglut's conventions, the information returned about the window coordinates does not correspond to the coordinates used when setting window position. In addition, GLUT only accepts positive window coordinates, and ignores all negative window coordinates. But if GLUT_ALLOW_NEGATIVE_WINDOW_POSITION is enabled, then negative window coordinates can be used. This is useful for multi-montitor setups where the second monitor may be in the negative desktop space of the primary monitor, as now the window can be placed on the additional monitors. Furthermore, this flag also determines how negative coordinates and sizes are interpreted for subwindows.
Windows has some additional quirks which the application programmer should know about. First, the minimum y-coordinate of a window decoration is zero. (This is a feature of freeglut and can be adjusted if so desired.) Second, there appears to be a minimum window width on Windows which is 104 pixels. The user may specify a smaller width, but the Windows system calls ignore it. It is also impossible to make a window narrower than this by dragging on its corner.
- Changes From GLUT
For some reason, GLUT is not affected by the 104-pixel minimum window width. If the user clicks on the corner of a window which is narrower than this amount, the window will immediately snap out to this width, but the application can call glutReshapeWindow and make a window narrower again.
If GLUT_ALLOW_NEGATIVE_WINDOW_POSITION is enabled, glutInitWindowPosition will accept negative window coordinates.
- OpenGL GLUT 3.0 Description
Windows created by glutCreateWindow will be requested to be created with the current initial window position and size.
The The initial value of the initial window position GLUT state is -1 and -1. If either the X or Y component to the initial window position is negative, the actual window position is left to the window system to determine. The initial value of the initial window size GLUT state is 300 by 300. The initial window size components must be greater than zero.
The intent of the initial window position and size values is to provide a suggestion to the window system for a window’s initial size and position. The window system is not obligated to use this information. Therefore, GLUT programs should not assume the window was created at the specified size or position. A GLUT program should use the window’s reshape callback to determine the true size of the window.
- glutInitDisplayMode (OpenGL GLUT 3.0)lutInitDisplayString
- glutInitErrorFunc, glutInitWarningFunc
Sources and References
©sideway
ID: 250102601 Last Updated: 1/26/2025 Revision: 0
|
 |