0
# GLUT Window Management
1
2
OpenGL Utility Toolkit (GLUT) providing complete window management and event handling system for creating OpenGL applications. Includes support for keyboard input, mouse interaction, timer callbacks, and display modes with automatic context creation.
3
4
## Capabilities
5
6
### Initialization and Setup
7
8
GLUT initialization and display mode configuration.
9
10
```python { .api }
11
def glutInit(argv: list):
12
"""
13
Initialize GLUT library.
14
15
Parameters:
16
- argv: Command line arguments (typically sys.argv)
17
"""
18
19
def glutInitDisplayMode(mode):
20
"""
21
Set initial display mode.
22
23
Parameters:
24
- mode: Display mode flags (GLUT_SINGLE, GLUT_DOUBLE, GLUT_RGB, etc.)
25
"""
26
27
def glutInitWindowSize(width: int, height: int):
28
"""
29
Set initial window size.
30
31
Parameters:
32
- width, height: Window dimensions in pixels
33
"""
34
35
def glutInitWindowPosition(x: int, y: int):
36
"""
37
Set initial window position.
38
39
Parameters:
40
- x, y: Window position on screen
41
"""
42
43
def glutGet(pname) -> int:
44
"""
45
Get GLUT state information.
46
47
Parameters:
48
- pname: State parameter (GLUT_WINDOW_WIDTH, GLUT_WINDOW_HEIGHT, etc.)
49
50
Returns:
51
State value
52
"""
53
```
54
55
### Window Management
56
57
Window creation, manipulation, and destruction.
58
59
```python { .api }
60
def glutCreateWindow(title: str) -> int:
61
"""
62
Create top-level window.
63
64
Parameters:
65
- title: Window title string
66
67
Returns:
68
Window identifier
69
"""
70
71
def glutCreateSubWindow(win: int, x: int, y: int, width: int, height: int) -> int:
72
"""
73
Create subwindow.
74
75
Parameters:
76
- win: Parent window identifier
77
- x, y: Position relative to parent
78
- width, height: Subwindow dimensions
79
80
Returns:
81
Subwindow identifier
82
"""
83
84
def glutDestroyWindow(win: int):
85
"""
86
Destroy window.
87
88
Parameters:
89
- win: Window identifier to destroy
90
"""
91
92
def glutSetWindow(win: int):
93
"""
94
Set current window.
95
96
Parameters:
97
- win: Window identifier to make current
98
"""
99
100
def glutGetWindow() -> int:
101
"""
102
Get current window identifier.
103
104
Returns:
105
Current window identifier
106
"""
107
108
def glutSetWindowTitle(title: str):
109
"""Set current window title."""
110
111
def glutSetIconTitle(title: str):
112
"""Set current window icon title."""
113
114
def glutReshapeWindow(width: int, height: int):
115
"""Resize current window."""
116
117
def glutPositionWindow(x: int, y: int):
118
"""Move current window."""
119
120
def glutShowWindow():
121
"""Show current window."""
122
123
def glutHideWindow():
124
"""Hide current window."""
125
126
def glutIconifyWindow():
127
"""Iconify current window."""
128
129
def glutPushWindow():
130
"""Push current window to back."""
131
132
def glutPopWindow():
133
"""Pop current window to front."""
134
135
def glutFullScreen():
136
"""Make current window full screen."""
137
```
138
139
### Event Loop and Callbacks
140
141
Main event loop and callback registration system.
142
143
```python { .api }
144
def glutMainLoop():
145
"""
146
Enter GLUT event processing loop.
147
This function never returns.
148
"""
149
150
def glutDisplayFunc(func):
151
"""
152
Set display callback function.
153
154
Parameters:
155
- func: Function called when window needs redrawing
156
"""
157
158
def glutReshapeFunc(func):
159
"""
160
Set reshape callback function.
161
162
Parameters:
163
- func: Function called when window is resized
164
Signature: func(width: int, height: int)
165
"""
166
167
def glutKeyboardFunc(func):
168
"""
169
Set keyboard callback function.
170
171
Parameters:
172
- func: Function called on key press
173
Signature: func(key: bytes, x: int, y: int)
174
"""
175
176
def glutKeyboardUpFunc(func):
177
"""
178
Set keyboard up callback function.
179
180
Parameters:
181
- func: Function called on key release
182
Signature: func(key: bytes, x: int, y: int)
183
"""
184
185
def glutSpecialFunc(func):
186
"""
187
Set special key callback function.
188
189
Parameters:
190
- func: Function called on special key press
191
Signature: func(key: int, x: int, y: int)
192
"""
193
194
def glutSpecialUpFunc(func):
195
"""
196
Set special key up callback function.
197
198
Parameters:
199
- func: Function called on special key release
200
Signature: func(key: int, x: int, y: int)
201
"""
202
203
def glutMouseFunc(func):
204
"""
205
Set mouse button callback function.
206
207
Parameters:
208
- func: Function called on mouse button press/release
209
Signature: func(button: int, state: int, x: int, y: int)
210
"""
211
212
def glutMotionFunc(func):
213
"""
214
Set mouse motion callback (with button pressed).
215
216
Parameters:
217
- func: Function called during mouse drag
218
Signature: func(x: int, y: int)
219
"""
220
221
def glutPassiveMotionFunc(func):
222
"""
223
Set passive mouse motion callback.
224
225
Parameters:
226
- func: Function called during mouse movement (no buttons)
227
Signature: func(x: int, y: int)
228
"""
229
230
def glutIdleFunc(func):
231
"""
232
Set idle callback function.
233
234
Parameters:
235
- func: Function called when no events pending, or None to disable
236
"""
237
238
def glutTimerFunc(msecs: int, func, value: int):
239
"""
240
Set timer callback function.
241
242
Parameters:
243
- msecs: Milliseconds until callback
244
- func: Timer callback function
245
Signature: func(value: int)
246
- value: Value passed to callback
247
"""
248
249
def glutVisibilityFunc(func):
250
"""
251
Set window visibility callback.
252
253
Parameters:
254
- func: Function called on visibility change
255
Signature: func(state: int)
256
"""
257
258
def glutEntryFunc(func):
259
"""
260
Set mouse entry/exit callback.
261
262
Parameters:
263
- func: Function called when mouse enters/exits window
264
Signature: func(state: int)
265
"""
266
```
267
268
### Display and Rendering
269
270
Display buffer management and rendering control.
271
272
```python { .api }
273
def glutSwapBuffers():
274
"""Swap front and back buffers (double buffering)."""
275
276
def glutPostRedisplay():
277
"""Mark current window for redisplay."""
278
279
def glutPostWindowRedisplay(win: int):
280
"""
281
Mark specified window for redisplay.
282
283
Parameters:
284
- win: Window identifier
285
"""
286
```
287
288
### Menu System
289
290
Pop-up menu creation and management.
291
292
```python { .api }
293
def glutCreateMenu(func) -> int:
294
"""
295
Create pop-up menu.
296
297
Parameters:
298
- func: Menu callback function
299
Signature: func(value: int)
300
301
Returns:
302
Menu identifier
303
"""
304
305
def glutDestroyMenu(menu: int):
306
"""
307
Destroy menu.
308
309
Parameters:
310
- menu: Menu identifier
311
"""
312
313
def glutGetMenu() -> int:
314
"""
315
Get current menu identifier.
316
317
Returns:
318
Current menu identifier
319
"""
320
321
def glutSetMenu(menu: int):
322
"""
323
Set current menu.
324
325
Parameters:
326
- menu: Menu identifier to make current
327
"""
328
329
def glutAddMenuEntry(label: str, value: int):
330
"""
331
Add menu entry.
332
333
Parameters:
334
- label: Menu item text
335
- value: Value passed to menu callback
336
"""
337
338
def glutAddSubMenu(label: str, submenu: int):
339
"""
340
Add submenu entry.
341
342
Parameters:
343
- label: Submenu text
344
- submenu: Submenu identifier
345
"""
346
347
def glutChangeToMenuEntry(item: int, label: str, value: int):
348
"""Change menu item to regular entry."""
349
350
def glutChangeToSubMenu(item: int, label: str, submenu: int):
351
"""Change menu item to submenu."""
352
353
def glutRemoveMenuItem(item: int):
354
"""Remove menu item."""
355
356
def glutAttachMenu(button: int):
357
"""
358
Attach current menu to mouse button.
359
360
Parameters:
361
- button: Mouse button (GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, GLUT_RIGHT_BUTTON)
362
"""
363
364
def glutDetachMenu(button: int):
365
"""Detach menu from mouse button."""
366
```
367
368
### Font Rendering
369
370
Text rendering with bitmap and stroke fonts.
371
372
```python { .api }
373
def glutBitmapCharacter(font, character: int):
374
"""
375
Render bitmap character.
376
377
Parameters:
378
- font: Font identifier (GLUT_BITMAP_9_BY_15, GLUT_BITMAP_HELVETICA_18, etc.)
379
- character: Character code to render
380
"""
381
382
def glutBitmapString(font, string: str):
383
"""
384
Render bitmap string.
385
386
Parameters:
387
- font: Font identifier
388
- string: String to render
389
"""
390
391
def glutBitmapWidth(font, character: int) -> int:
392
"""
393
Get bitmap character width.
394
395
Returns:
396
Character width in pixels
397
"""
398
399
def glutBitmapLength(font, string: str) -> int:
400
"""
401
Get bitmap string length.
402
403
Returns:
404
String width in pixels
405
"""
406
407
def glutStrokeCharacter(font, character: int):
408
"""
409
Render stroke character.
410
411
Parameters:
412
- font: Stroke font (GLUT_STROKE_ROMAN, GLUT_STROKE_MONO_ROMAN)
413
- character: Character code to render
414
"""
415
416
def glutStrokeString(font, string: str):
417
"""Render stroke string."""
418
419
def glutStrokeWidth(font, character: int) -> float:
420
"""
421
Get stroke character width.
422
423
Returns:
424
Character width in font units
425
"""
426
427
def glutStrokeLength(font, string: str) -> float:
428
"""
429
Get stroke string length.
430
431
Returns:
432
String width in font units
433
"""
434
```
435
436
### Geometric Primitives
437
438
Built-in geometric shapes for quick prototyping.
439
440
```python { .api }
441
def glutWireSphere(radius: float, slices: int, stacks: int):
442
"""
443
Render wireframe sphere.
444
445
Parameters:
446
- radius: Sphere radius
447
- slices: Number of longitude lines
448
- stacks: Number of latitude lines
449
"""
450
451
def glutSolidSphere(radius: float, slices: int, stacks: int):
452
"""Render solid sphere."""
453
454
def glutWireCube(size: float):
455
"""
456
Render wireframe cube.
457
458
Parameters:
459
- size: Edge length
460
"""
461
462
def glutSolidCube(size: float):
463
"""Render solid cube."""
464
465
def glutWireCone(base: float, height: float, slices: int, stacks: int):
466
"""
467
Render wireframe cone.
468
469
Parameters:
470
- base: Base radius
471
- height: Cone height
472
- slices: Number of radial subdivisions
473
- stacks: Number of height subdivisions
474
"""
475
476
def glutSolidCone(base: float, height: float, slices: int, stacks: int):
477
"""Render solid cone."""
478
479
def glutWireTorus(innerRadius: float, outerRadius: float, sides: int, rings: int):
480
"""
481
Render wireframe torus.
482
483
Parameters:
484
- innerRadius: Inner radius
485
- outerRadius: Outer radius
486
- sides: Number of sides per ring
487
- rings: Number of rings
488
"""
489
490
def glutSolidTorus(innerRadius: float, outerRadius: float, sides: int, rings: int):
491
"""Render solid torus."""
492
493
def glutWireTetrahedron():
494
"""Render wireframe tetrahedron."""
495
496
def glutSolidTetrahedron():
497
"""Render solid tetrahedron."""
498
499
def glutWireOctahedron():
500
"""Render wireframe octahedron."""
501
502
def glutSolidOctahedron():
503
"""Render solid octahedron."""
504
505
def glutWireDodecahedron():
506
"""Render wireframe dodecahedron."""
507
508
def glutSolidDodecahedron():
509
"""Render solid dodecahedron."""
510
511
def glutWireIcosahedron():
512
"""Render wireframe icosahedron."""
513
514
def glutSolidIcosahedron():
515
"""Render solid icosahedron."""
516
517
def glutWireTeapot(size: float):
518
"""
519
Render wireframe teapot (Utah teapot).
520
521
Parameters:
522
- size: Teapot size scaling factor
523
"""
524
525
def glutSolidTeapot(size: float):
526
"""Render solid teapot."""
527
```
528
529
### FreeGLUT Extensions
530
531
Extended functionality available when FreeGLUT is present.
532
533
```python { .api }
534
def glutLeaveMainLoop():
535
"""
536
Exit main event loop (FreeGLUT only).
537
Available when HAVE_FREEGLUT is True.
538
"""
539
540
def glutMainLoopEvent():
541
"""
542
Process single iteration of event loop (FreeGLUT only).
543
"""
544
545
def glutCloseFunc(func):
546
"""
547
Set window close callback (FreeGLUT only).
548
549
Parameters:
550
- func: Function called when window is closed
551
"""
552
553
def glutWMCloseFunc(func):
554
"""Set window manager close callback (FreeGLUT only)."""
555
556
# FreeGLUT detection
557
HAVE_FREEGLUT: bool # True if FreeGLUT extensions are available
558
```
559
560
## Constants
561
562
### Display Mode Flags
563
```python { .api }
564
GLUT_SINGLE: int # Single buffered
565
GLUT_DOUBLE: int # Double buffered
566
GLUT_RGB: int # RGB color mode
567
GLUT_RGBA: int # RGBA color mode
568
GLUT_INDEX: int # Color index mode
569
GLUT_DEPTH: int # Depth buffer
570
GLUT_STENCIL: int # Stencil buffer
571
GLUT_ACCUM: int # Accumulation buffer
572
GLUT_ALPHA: int # Alpha channel
573
GLUT_MULTISAMPLE: int # Multisampling
574
```
575
576
### Mouse Buttons
577
```python { .api }
578
GLUT_LEFT_BUTTON: int
579
GLUT_MIDDLE_BUTTON: int
580
GLUT_RIGHT_BUTTON: int
581
```
582
583
### Mouse Button States
584
```python { .api }
585
GLUT_DOWN: int # Button pressed
586
GLUT_UP: int # Button released
587
```
588
589
### Special Keys
590
```python { .api }
591
GLUT_KEY_F1: int through GLUT_KEY_F12: int # Function keys
592
GLUT_KEY_LEFT: int # Arrow keys
593
GLUT_KEY_UP: int
594
GLUT_KEY_RIGHT: int
595
GLUT_KEY_DOWN: int
596
GLUT_KEY_PAGE_UP: int # Navigation keys
597
GLUT_KEY_PAGE_DOWN: int
598
GLUT_KEY_HOME: int
599
GLUT_KEY_END: int
600
GLUT_KEY_INSERT: int
601
```
602
603
### Visibility States
604
```python { .api }
605
GLUT_NOT_VISIBLE: int
606
GLUT_VISIBLE: int
607
```
608
609
### Entry States
610
```python { .api }
611
GLUT_LEFT: int # Mouse left window
612
GLUT_ENTERED: int # Mouse entered window
613
```
614
615
### Font Identifiers
616
```python { .api }
617
# Bitmap fonts
618
GLUT_BITMAP_9_BY_15: int
619
GLUT_BITMAP_8_BY_13: int
620
GLUT_BITMAP_TIMES_ROMAN_10: int
621
GLUT_BITMAP_TIMES_ROMAN_24: int
622
GLUT_BITMAP_HELVETICA_10: int
623
GLUT_BITMAP_HELVETICA_12: int
624
GLUT_BITMAP_HELVETICA_18: int
625
626
# Stroke fonts
627
GLUT_STROKE_ROMAN: int
628
GLUT_STROKE_MONO_ROMAN: int
629
```