1 /***********************************************************
2 * Copyright (C) 1997, Be Inc. All rights reserved.
6 * DESCRIPTION: initialize GLUT state
7 ***********************************************************/
9 /***********************************************************
11 ***********************************************************/
16 #include "glutState.h"
19 /***********************************************************
21 ***********************************************************/
24 /***********************************************************
26 ***********************************************************/
27 static int __glutArgc
;
28 static char **__glutArgv
;
30 /***********************************************************
31 * FUNCTION: __glutInitTime
33 * DESCRIPTION: set up start time variable
34 ***********************************************************/
35 void __glutInitTime(bigtime_t
*beginning
)
37 static int beenhere
= 0;
38 static bigtime_t genesis
;
41 genesis
= system_time();
47 /***********************************************************
48 * FUNCTION: removeArgs
50 * DESCRIPTION: helper function for glutInit to remove args
51 * from argv variable passed in
52 ***********************************************************/
54 removeArgs(int *argcp
, char **argv
, int numToRemove
)
58 for (i
= 0, j
= numToRemove
; argv
[j
]; i
++, j
++) {
62 *argcp
-= numToRemove
;
65 /***********************************************************
66 * FUNCTION: bAppThread
68 * DESCRIPTION: starts the BApplication message loop running
69 ***********************************************************/
70 static int32
bAppThread(void *arg
) {
75 /***********************************************************
76 * FUNCTION: glutInit (2.1)
78 * DESCRIPTION: create BApplication, parse cmd-line arguments,
79 * and set up gState structure.
80 ***********************************************************/
81 void glutInit(int *argcp
, char **argv
) {
82 char *str
, *geometry
= NULL
;
86 __glutWarning("glutInit being called a second time.");
89 /* Determine temporary program name. */
90 str
= strrchr(argv
[0], '/');
92 gState
.programName
= argv
[0];
94 gState
.programName
= str
+ 1;
97 /* Make private copy of command line arguments. */
99 __glutArgv
= (char **) malloc(__glutArgc
* sizeof(char *));
101 __glutFatalError("out of memory.");
102 for (i
= 0; i
< __glutArgc
; i
++) {
103 __glutArgv
[i
] = strdup(argv
[i
]);
105 __glutFatalError("out of memory.");
108 /* determine permanent program name */
109 str
= strrchr(__glutArgv
[0], '/');
111 gState
.programName
= __glutArgv
[0];
113 gState
.programName
= str
+ 1;
116 /* parse arguments for standard options */
117 for (i
= 1; i
< __glutArgc
; i
++) {
118 if (!strcmp(__glutArgv
[i
], "-display")) {
119 __glutWarning("-display option only valid for X glut.");
120 if (++i
>= __glutArgc
) {
122 "follow -display option with X display name.");
124 removeArgs(argcp
, &argv
[1], 2);
125 } else if (!strcmp(__glutArgv
[i
], "-geometry")) {
126 if (++i
>= __glutArgc
) {
128 "follow -geometry option with geometry parameter.");
130 geometry
= __glutArgv
[i
];
131 removeArgs(argcp
, &argv
[1], 2);
132 } else if (!strcmp(__glutArgv
[i
], "-direct")) {
133 __glutWarning("-direct option only valid for X glut.");
134 removeArgs(argcp
, &argv
[1], 1);
135 } else if (!strcmp(__glutArgv
[i
], "-indirect")) {
136 __glutWarning("-indirect option only valid for X glut.");
137 removeArgs(argcp
, &argv
[1], 1);
138 } else if (!strcmp(__glutArgv
[i
], "-iconic")) {
139 __glutWarning("-iconic option doesn't make sense in BeOS.");
140 removeArgs(argcp
, &argv
[1], 1);
141 } else if (!strcmp(__glutArgv
[i
], "-gldebug")) {
143 removeArgs(argcp
, &argv
[1], 1);
144 } else if (!strcmp(__glutArgv
[i
], "-sync")) {
145 __glutWarning("-sync option only valid for X glut.");
146 removeArgs(argcp
, &argv
[1], 1);
148 /* Once unknown option encountered, stop command line
154 __glutInit(); /* Create BApplication first so DisplayWidth() works */
156 int flags
, x
, y
, width
, height
;
158 /* Fix bogus "{width|height} may be used before set"
163 flags
= XParseGeometry(geometry
, &x
, &y
,
164 (unsigned int *) &width
, (unsigned int *) &height
);
165 if (WidthValue
& flags
) {
166 /* Careful because X does not allow zero or negative
169 gState
.initWidth
= width
;
171 if (HeightValue
& flags
) {
172 /* Careful because X does not allow zero or negative
175 gState
.initHeight
= height
;
177 if (XValue
& flags
) {
178 if (XNegative
& flags
)
179 x
= DisplayWidth() + x
- gState
.initWidth
;
180 /* Play safe: reject negative X locations */
184 if (YValue
& flags
) {
185 if (YNegative
& flags
)
186 y
= DisplayHeight() + y
- gState
.initHeight
;
187 /* Play safe: reject negative Y locations */
194 /***********************************************************
195 * FUNCTION: __glutInit
197 * DESCRIPTION: create BApplication, parse cmd-line arguments,
198 * and set up gState structure.
199 ***********************************************************/
202 gState
.display
= new BApplication("application/x-glut-demo");
204 thread_id appthread
= spawn_thread(bAppThread
, "BApplication", B_NORMAL_PRIORITY
, 0);
205 resume_thread(appthread
);
208 __glutInitTime(&unused
);
211 /***********************************************************
212 * FUNCTION: glutInitWindowPosition (2.2)
214 * DESCRIPTION: set initial window position
215 ***********************************************************/
216 void glutInitWindowPosition(int x
, int y
) {
221 /***********************************************************
222 * FUNCTION: glutInitWindowSize (2.2)
224 * DESCRIPTION: set initial window size
225 ***********************************************************/
226 void glutInitWindowSize(int width
, int height
) {
227 gState
.initWidth
= width
;
228 gState
.initHeight
= height
;
231 /***********************************************************
232 * FUNCTION: glutInitDisplayMode (2.3)
234 * DESCRIPTION: set initial display mode
235 ***********************************************************/
236 void glutInitDisplayMode(unsigned int mode
) {
237 gState
.displayMode
= mode
;