0
# Core OpenGL Functions
1
2
Complete OpenGL API providing fundamental graphics functionality including drawing primitives, state management, transformations, texturing, lighting, and vertex operations. PyOpenGL supports all OpenGL versions from 1.0 through 4.6 with comprehensive extension coverage from major vendors.
3
4
## Capabilities
5
6
### Drawing Primitives
7
8
Basic geometric primitives for immediate mode rendering with points, lines, triangles, and quads.
9
10
```python { .api }
11
def glBegin(mode):
12
"""
13
Begin primitive rendering.
14
15
Parameters:
16
- mode: Primitive type (GL_POINTS, GL_LINES, GL_TRIANGLES, GL_QUADS, etc.)
17
"""
18
19
def glEnd():
20
"""End primitive rendering."""
21
22
def glVertex2f(x: float, y: float):
23
"""Specify 2D vertex coordinates."""
24
25
def glVertex3f(x: float, y: float, z: float):
26
"""Specify 3D vertex coordinates."""
27
28
def glVertex3fv(v: list):
29
"""
30
Specify 3D vertex from array.
31
32
Parameters:
33
- v: Array-like of 3 float values [x, y, z]
34
"""
35
```
36
37
### Modern Vertex Arrays
38
39
Modern OpenGL vertex array rendering for high-performance graphics.
40
41
```python { .api }
42
def glDrawArrays(mode, first: int, count: int):
43
"""
44
Draw arrays of vertex data.
45
46
Parameters:
47
- mode: Primitive type
48
- first: Starting array index
49
- count: Number of vertices to render
50
"""
51
52
def glDrawElements(mode, count: int, type, indices):
53
"""
54
Draw indexed vertex arrays.
55
56
Parameters:
57
- mode: Primitive type
58
- count: Number of elements
59
- type: Index data type (GL_UNSIGNED_BYTE, GL_UNSIGNED_SHORT, GL_UNSIGNED_INT)
60
- indices: Index array or buffer offset
61
"""
62
63
def glVertexPointer(size: int, type, stride: int, pointer):
64
"""
65
Define vertex coordinate array.
66
67
Parameters:
68
- size: Coordinates per vertex (2, 3, or 4)
69
- type: Data type (GL_FLOAT, GL_DOUBLE, etc.)
70
- stride: Byte offset between vertices
71
- pointer: Array data or buffer offset
72
"""
73
74
def glColorPointer(size: int, type, stride: int, pointer):
75
"""Define color array for vertices."""
76
77
def glNormalPointer(type, stride: int, pointer):
78
"""Define normal vector array."""
79
80
def glTexCoordPointer(size: int, type, stride: int, pointer):
81
"""Define texture coordinate array."""
82
83
def glEnableClientState(array):
84
"""
85
Enable vertex array.
86
87
Parameters:
88
- array: Array type (GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_NORMAL_ARRAY, etc.)
89
"""
90
91
def glDisableClientState(array):
92
"""Disable vertex array."""
93
```
94
95
### State Management
96
97
OpenGL state machine control for rendering modes, capabilities, and parameters.
98
99
```python { .api }
100
def glEnable(cap):
101
"""
102
Enable OpenGL capability.
103
104
Parameters:
105
- cap: Capability (GL_DEPTH_TEST, GL_LIGHTING, GL_TEXTURE_2D, etc.)
106
"""
107
108
def glDisable(cap):
109
"""Disable OpenGL capability."""
110
111
def glIsEnabled(cap) -> bool:
112
"""Test if capability is enabled."""
113
114
def glGetBooleanv(pname) -> list:
115
"""Get boolean state values."""
116
117
def glGetIntegerv(pname) -> list:
118
"""Get integer state values."""
119
120
def glGetFloatv(pname) -> list:
121
"""Get float state values."""
122
123
def glGetDoublev(pname) -> list:
124
"""Get double state values."""
125
126
# Convenience aliases for state queries
127
glGetBoolean = glGetBooleanv # Alias for boolean state query
128
glGetDouble = glGetDoublev # Alias for double state query
129
glGetFloat = glGetFloatv # Alias for float state query
130
glGetInteger = glGetIntegerv # Alias for integer state query
131
```
132
133
### Matrix Operations
134
135
Transformation matrix management for model, view, and projection transformations.
136
137
```python { .api }
138
def glMatrixMode(mode):
139
"""
140
Set current matrix mode.
141
142
Parameters:
143
- mode: Matrix type (GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE)
144
"""
145
146
def glLoadIdentity():
147
"""Load identity matrix."""
148
149
def glLoadMatrixf(m: list):
150
"""
151
Load matrix from array.
152
153
Parameters:
154
- m: 16-element array in column-major order
155
"""
156
157
def glMultMatrixf(m: list):
158
"""Multiply current matrix by given matrix."""
159
160
def glPushMatrix():
161
"""Push current matrix onto stack."""
162
163
def glPopMatrix():
164
"""Pop matrix from stack."""
165
166
def glTranslatef(x: float, y: float, z: float):
167
"""Apply translation transformation."""
168
169
def glRotatef(angle: float, x: float, y: float, z: float):
170
"""
171
Apply rotation transformation.
172
173
Parameters:
174
- angle: Rotation angle in degrees
175
- x, y, z: Rotation axis vector
176
"""
177
178
def glScalef(x: float, y: float, z: float):
179
"""Apply scaling transformation."""
180
181
# Convenience aliases for common functions
182
glRotate = glRotated # Alias for double-precision rotation
183
glTranslate = glTranslated # Alias for double-precision translation
184
glScale = glScaled # Alias for double-precision scaling
185
glLight = glLightfv # Alias for vector light parameter setting
186
glTexCoord = glTexCoord2d # Alias for 2D double-precision texture coordinates
187
glNormal = glNormal3d # Alias for 3D double-precision normal vectors
188
```
189
190
### Color and Material
191
192
Color specification and material properties for lighting calculations.
193
194
```python { .api }
195
def glColor3f(red: float, green: float, blue: float):
196
"""Set current color (RGB)."""
197
198
def glColor4f(red: float, green: float, blue: float, alpha: float):
199
"""Set current color with alpha (RGBA)."""
200
201
def glColor3fv(v: list):
202
"""Set color from RGB array."""
203
204
def glColor4fv(v: list):
205
"""Set color from RGBA array."""
206
207
def glNormal3f(nx: float, ny: float, nz: float):
208
"""Set current normal vector."""
209
210
def glNormal3fv(v: list):
211
"""Set normal from array."""
212
213
def glMaterialf(face, pname, param: float):
214
"""
215
Set material property (single value).
216
217
Parameters:
218
- face: Material face (GL_FRONT, GL_BACK, GL_FRONT_AND_BACK)
219
- pname: Property name (GL_SHININESS)
220
- param: Property value
221
"""
222
223
def glMaterialfv(face, pname, params: list):
224
"""
225
Set material property (array values).
226
227
Parameters:
228
- pname: Property (GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION)
229
- params: Property values array
230
"""
231
```
232
233
### Lighting
234
235
Lighting system configuration and light source management.
236
237
```python { .api }
238
def glLightf(light, pname, param: float):
239
"""
240
Set light parameter (single value).
241
242
Parameters:
243
- light: Light identifier (GL_LIGHT0 through GL_LIGHT7)
244
- pname: Parameter name
245
- param: Parameter value
246
"""
247
248
def glLightfv(light, pname, params: list):
249
"""
250
Set light parameter (array values).
251
252
Parameters:
253
- pname: Parameter (GL_POSITION, GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR)
254
- params: Parameter values array
255
"""
256
257
def glLightModelfv(pname, params: list):
258
"""
259
Set lighting model parameters.
260
261
Parameters:
262
- pname: Model parameter (GL_LIGHT_MODEL_AMBIENT, GL_LIGHT_MODEL_TWO_SIDE)
263
- params: Parameter values
264
"""
265
266
def glShadeModel(mode):
267
"""
268
Set shading model.
269
270
Parameters:
271
- mode: Shading type (GL_FLAT, GL_SMOOTH)
272
"""
273
```
274
275
### Texturing
276
277
Texture mapping functionality for applying images to geometry.
278
279
```python { .api }
280
def glGenTextures(n: int) -> list:
281
"""
282
Generate texture names.
283
284
Parameters:
285
- n: Number of texture names to generate
286
287
Returns:
288
List of texture identifiers
289
"""
290
291
def glBindTexture(target, texture: int):
292
"""
293
Bind texture to target.
294
295
Parameters:
296
- target: Texture target (GL_TEXTURE_2D, GL_TEXTURE_CUBE_MAP, etc.)
297
- texture: Texture identifier
298
"""
299
300
def glTexImage2D(target, level: int, internalformat, width: int, height: int,
301
border: int, format, type, pixels):
302
"""
303
Define 2D texture image.
304
305
Parameters:
306
- target: Texture target
307
- level: Mipmap level (0 for base level)
308
- internalformat: Internal format (GL_RGB, GL_RGBA, etc.)
309
- width, height: Image dimensions
310
- border: Border width (must be 0)
311
- format: Pixel format
312
- type: Pixel data type
313
- pixels: Image data array
314
"""
315
316
def glTexParameteri(target, pname, param: int):
317
"""
318
Set texture parameter.
319
320
Parameters:
321
- pname: Parameter (GL_TEXTURE_WRAP_S, GL_TEXTURE_MAG_FILTER, etc.)
322
- param: Parameter value
323
"""
324
325
def glTexCoord2f(s: float, t: float):
326
"""Set current texture coordinates."""
327
328
def glTexCoord2fv(v: list):
329
"""Set texture coordinates from array."""
330
```
331
332
### Buffer Management
333
334
Frame buffer and depth buffer operations.
335
336
```python { .api }
337
def glClear(mask):
338
"""
339
Clear buffers.
340
341
Parameters:
342
- mask: Buffer mask (GL_COLOR_BUFFER_BIT, GL_DEPTH_BUFFER_BIT, GL_STENCIL_BUFFER_BIT)
343
"""
344
345
def glClearColor(red: float, green: float, blue: float, alpha: float):
346
"""Set clear color for color buffer."""
347
348
def glClearDepth(depth: float):
349
"""
350
Set clear value for depth buffer.
351
352
Parameters:
353
- depth: Clear depth (typically 1.0)
354
"""
355
356
def glDepthFunc(func):
357
"""
358
Set depth test function.
359
360
Parameters:
361
- func: Comparison function (GL_LESS, GL_LEQUAL, GL_GREATER, etc.)
362
"""
363
364
def glDepthMask(flag: bool):
365
"""Enable/disable depth buffer writing."""
366
```
367
368
### Viewport and Clipping
369
370
Viewport transformation and clipping plane management.
371
372
```python { .api }
373
def glViewport(x: int, y: int, width: int, height: int):
374
"""
375
Set viewport transformation.
376
377
Parameters:
378
- x, y: Lower-left corner coordinates
379
- width, height: Viewport dimensions
380
"""
381
382
def glScissor(x: int, y: int, width: int, height: int):
383
"""Set scissor test rectangle."""
384
385
def glClipPlane(plane, equation: list):
386
"""
387
Define clipping plane.
388
389
Parameters:
390
- plane: Plane identifier (GL_CLIP_PLANE0 through GL_CLIP_PLANE5)
391
- equation: Plane equation coefficients [A, B, C, D]
392
"""
393
```
394
395
## Constants
396
397
### Primitive Types
398
```python { .api }
399
GL_POINTS: int
400
GL_LINES: int
401
GL_LINE_STRIP: int
402
GL_LINE_LOOP: int
403
GL_TRIANGLES: int
404
GL_TRIANGLE_STRIP: int
405
GL_TRIANGLE_FAN: int
406
GL_QUADS: int
407
GL_QUAD_STRIP: int
408
GL_POLYGON: int
409
```
410
411
### Buffer Bits
412
```python { .api }
413
GL_COLOR_BUFFER_BIT: int
414
GL_DEPTH_BUFFER_BIT: int
415
GL_STENCIL_BUFFER_BIT: int
416
```
417
418
### Capabilities
419
```python { .api }
420
GL_DEPTH_TEST: int
421
GL_LIGHTING: int
422
GL_TEXTURE_2D: int
423
GL_BLEND: int
424
GL_CULL_FACE: int
425
GL_SCISSOR_TEST: int
426
```
427
428
### Matrix Modes
429
```python { .api }
430
GL_MODELVIEW: int
431
GL_PROJECTION: int
432
GL_TEXTURE: int
433
```
434
435
### Data Types
436
```python { .api }
437
GL_BYTE: int
438
GL_UNSIGNED_BYTE: int
439
GL_SHORT: int
440
GL_UNSIGNED_SHORT: int
441
GL_INT: int
442
GL_UNSIGNED_INT: int
443
GL_FLOAT: int
444
GL_DOUBLE: int
445
```