source: project/wiki/eggref/4/gl-utils @ 34764

Last change on this file since 34764 was 34764, checked in by Kooda, 3 years ago

[wiki] gl-utils: fix the is-supported? call in the example

File size: 26.1 KB
Line 
1== gl-utils
2[[toc:]]
3Provides a higher level interface to OpenGL. The following modules are included:
4
5* gl-utils: Exports all of the modules in this egg
6* gl-utils-core: Convenience procedures for OpenGL, abstracting over common tasks
7* gl-utils-bytevector: OpenGL-safe R7RS style bytevectors with extended accessors
8* gl-utils-mesh: Convenient vertex array interface for creation, modification, and use
9* gl-utils-ply: [[http://paulbourke.net/dataformats/ply/|PLY]] file loading
10* gl-utils-srfi-4: OpenGL-safe numeric vectors
11
12gl-utils is known to work on Linux, Mac OS X, Windows, and with OpenGL ES. gl-utils will automatically compile with ES support on ARM hardware, or when {{gles}} is defined during compilation (e.g. {{chicken-install -D gles}}).
13
14
15=== Requirements
16* z3
17* matchable
18* miscmacros
19* srfi-42
20* opengl-glew
21* gl-math
22* make
23
24
25=== Documentation
26
27==== gl-utils-core
28<procedure> (check-error)</procedure>
29
30Performs {{get-error}} ({{glGetError}}) and prints the error type when an error is returned.
31
32<procedure> (make-shader TYPE SOURCE)</procedure>
33
34Creates and compiles a shader object given the shader's type (e.g. {{+vertex-shader+}}, {{+geometry-shader+}}, {{+fragment-shader+}}), and a string containing the GLSL source. Returns an integer representing the ID of the shader.
35
36<procedure> (make-program SHADER-LIST [PROGRAM-ID])</procedure>
37
38Creates and links a program object, given a list of shader objects (i.e. the integers returned by {{make-shader}}. Returns an integer representing the ID of the program.
39
40Accepts an optional {{PROGRAM-ID}} argument. If given, {{make-program}} will use this ID rather than generating a new one.
41
42<procedure> (gen-buffer)</procedure>
43<procedure> (gen-framebuffer)</procedure>
44<procedure> (gen-program-pipeline)</procedure>
45<procedure> (gen-query)</procedure>
46<procedure> (gen-renderbuffer)</procedure>
47<procedure> (gen-sampler)</procedure>
48<procedure> (gen-texture)</procedure>
49<procedure> (gen-transform-feedback)</procedure>
50<procedure> (gen-vertex-array)</procedure>
51
52Analogous to their pluralized counterparts, but only generates and returns one (integer) object.
53
54<procedure> (delete-buffer BUFFER)</procedure>
55<procedure> (delete-framebuffer FRAMEBUFFER)</procedure>
56<procedure> (delete-program-pipeline PROGRAM-PIPELINE)</procedure>
57<procedure> (delete-query QUERY)</procedure>
58<procedure> (delete-renderbuffer RENDERBUFFER)</procedure>
59<procedure> (delete-sampler SAMPLER)</procedure>
60<procedure> (delete-texture TEXTURE)</procedure>
61<procedure> (delete-transform-feedback TRANSFORM-FEEDBACK)</procedure>
62<procedure> (delete-vertex-array VERTEX-ARRAY)</procedure>
63
64Analogous to their pluralized counterparts, but only accepts and deletes one (integer) object.
65
66<macro> (with-buffer TYPE BUFFER BODY ...)</macro>
67<macro> (with-framebuffer FRAMEBUFFER BODY ...)</macro>
68<macro> (with-program-pipeline PROGRAM-PIPELINE BODY ...)</macro>
69<macro> (with-renderbuffer RENDERBUFFER BODY ...)</macro>
70<macro> (with-sampler UNIT SAMPLER BODY ...)</macro>
71<macro> (with-texture TYPE TEXTURE BODY ...)</macro>
72<macro> (with-transform-feedback TRANSFORM-FEEDBACK BODY ...)</macro>
73<macro> (with-vertex-array VERTEX-ARRAY BODY ...)</macro>
74
75Equivalent to binding the object, executing the body, then binding 0. E.g. {{(bind-texture TYPE TEXTURE) BODY ... (bind-texture TYPE 0)}}.
76
77<procedure> (set-texture-properties ID type: TYPE mag: MAG min: MIN wrap: WRAP wrap-s: WRAP-S wrap-t: WRAP-T wrap-r: WRAP-R)</procedure>
78
79Conveniently set the most common properties of the texture {{ID}}. {{TYPE}} is the texture type, defaulting to {{+texture-2d+}}. {{MAG}} and {{MIN}} are the texture magnify and minifying functions, which default to {{+linear+}}. {{WRAP-S}}, {{WRAP-T}}, and {{WRAP-R}} set the wrapping parameters which default to {{+repeat+}}. {{WRAP}} sets all three wrapping parameters to the same value.
80
81If {{ID}} is {{#f}}, no texture will be bound, and therefore properties of whatever texture is currently bound will be set.
82
83<procedure> (create-framebuffer WIDTH HEIGHT channels: CHANNELS type: TYPE)</procedure>
84
85Create a framebuffer with a texture and depth renderbuffer attached. The texture and renderbuffer are given the dimensions {{WITH}} and {{HEIGHT}}. {{CHANNELS}} is the number of channels that the texture has: 1, 2, 3, or 4, corresponding to {{+red+}}, {{+rg+}}, {{+rgb+, and}}+rgba+ respectively, defaulting to 4. {{TYPE}} is the type of the texture data which defaults to {{+unsigned-byte+}}. Returns three values: The framebuffer, the texture, and the renderbuffer.
86
87<procedure> (->pointer VECTOR)</procedure>
88
89Returns the pointer to a srfi-4 vector or blob.
90
91<procedure> (size VECTOR)</procedure>
92
93Returns the size, in bytes, of a srfi-4 vector or blob.
94
95<procedure> (type->bytes TYPE)</procedure>
96
97Returns the size of {{TYPE}} (as accepted by {{type->gl}}) in number of bytes.
98
99<procedure> (type->gl TYPE)</procedure>
100
101Converts the keyword {{TYPE}} into a OpenGL type enum value. Accepted types (grouped by synonyms) are:
102
103* {{char:}} {{int8:}} {{byte:}}
104* {{uchar:}} {{uint8:}} {{unsigned-byte:}}
105* {{short:}} {{int16:}}
106* {{ushort:}} {{uint16:}} {{unsigned-short:}}
107* {{int:}} {{int32:}} {{integer:}} {{integer32:}}
108* {{uint:}} {{uint32:}} {{unsigned-int:}} {{unsigned-int32:}} {{unsigned-integer:}} {{unsigned-integer32:}}
109* {{float:}} {{float32:}}
110* {{double:}} {{float64:}}
111
112Double is not, however, a valid type when using GL ES.
113
114
115==== gl-utils-bytevector
116r7rs style bytevectors with unsafe accessors.
117
118<procedure> (bytevector BYTE ...)</procedure>
119
120Returns a newly allocated bytevector containing its arguments. The resulting bytevector ''will'' be created in garbage-collected memory.
121
122<procedure> (make-bytevector K [BYTE] [NONGC] [FINALIZE])</procedure>
123
124Return a newly-allocated bytevector of length {{K}}. If the optional fill {{BYTE}} is specified, it specifies the initial value for each slot in the bytevector.
125
126The optional arguments {{NONGC}} and {{FINALIZE}} define whether the vector should be allocated in a memory area not subject to garbage collection and whether the associated storage should be automatically freed (using finalization) when there are no references from Scheme variables and data. {{NONGC}} defaults to #t (the vector will be located in non-garbage-collected memory) and {{FINALIZE}} defaults to #t. Note that the {{FINALIZE}} argument is only used when {{NONGC}} is true.
127
128<procedure> (bytevector-length BYTEVECTOR)</procedure>
129
130Return the length in bytes of {{BYTEVECTOR}}.
131
132<procedure> (bytevector? BYTEVECTOR)</procedure>
133
134Returns true if {{BYTEVECTOR}} is a bytevector, false otherwise.
135
136<procedure> (bytevector-u8-set! BYTEVECTOR K UNSIGNED-BYTE)</procedure>
137<procedure> (bytevector-s8-set! BYTEVECTOR K BYTE)</procedure>
138<procedure> (bytevector-u16-set! BYTEVECTOR K UNSIGNED-SHORT)</procedure>
139<procedure> (bytevector-s16-set! BYTEVECTOR K SHORT)</procedure>
140<procedure> (bytevector-u32-set! BYTEVECTOR K UNSIGNED-INT)</procedure>
141<procedure> (bytevector-s32-set! BYTEVECTOR K INT)</procedure>
142<procedure> (bytevector-u64-set! BYTEVECTOR K UNSIGNED-LONG)</procedure>
143<procedure> (bytevector-s64-set! BYTEVECTOR K LONG)</procedure>
144<procedure> (bytevector-f32-set! BYTEVECTOR K FLOAT)</procedure>
145<procedure> (bytevector-f64-set! BYTEVECTOR K DOUBLE)</procedure>
146
147Sets the byte {{K}} of the given bytevector to be the value of the given fixnum or flonum. These functions are unsafe, so be sure {{K}} is a valid location in the bytevector.
148
149<procedure> (bytevector-u8-ref BYTEVECTOR K)</procedure>
150<procedure> (bytevector-s8-ref BYTEVECTOR K)</procedure>
151<procedure> (bytevector-u16-ref BYTEVECTOR K)</procedure>
152<procedure> (bytevector-s16-ref BYTEVECTOR K)</procedure>
153<procedure> (bytevector-u32-ref BYTEVECTOR K)</procedure>
154<procedure> (bytevector-s32-ref BYTEVECTOR K)</procedure>
155<procedure> (bytevector-u64-ref BYTEVECTOR K)</procedure>
156<procedure> (bytevector-s64-ref BYTEVECTOR K)</procedure>
157<procedure> (bytevector-f32-ref BYTEVECTOR K)</procedure>
158<procedure> (bytevector-f64-ref BYTEVECTOR K)</procedure>
159
160Returns the fixnum or flonum of the given size located at byte {{K}} of the given bytevector. These functions are unsafe, so be sure {{K}} is a valid location in the bytevector.
161
162<procedure> (bytevector–>pointer BYTEVECTOR)</procedure>
163
164Returns the pointer to {{BYTEVECTOR}}’s data.usage
165
166<procedure> (bytevector-append BYTEVECTOR . BYTEVECTORSS)</procedure>
167
168Returns a newly allocated bytevector whose elements are the concatenation of the elements in the given bytevectors. If only one argument is passed to {{bytevector-append}}, it is assumed that it is a list of bytevectors.
169
170<procedure> (bytevector-copy BYTEVECTOR [START] [END])</procedure>
171
172Returns a newly allocated copy of the elements of the given bytevector between {{START}} and {{END}}.
173
174<procedure> (bytevector-copy! TO AT FROM [START] [END])</procedure>
175
176Copies the elements of bytevector {{FROM}} between {{START}} and {{END}} to bytevector {{TO}}, starting at {{AT}}. It is an error if {{AT}} is less than zero or greater than the length of {{TO}}. It is also an error if {{(- (bytevector-length TO) AT)}} is less than {{(- END START)}}.
177
178
179==== gl-utils-mesh
180<procedure> (make-mesh vertices: VERTICES [indices: INDICES] [mode: MODE])</procedure>
181
182Create a new mesh. {{VERTICES}} is a list of key value pairs that specifies the mesh’s vertex data. It should be in the form:
183
184    (attributes: ATTRIBUTES [initial-elements: INITIAL-ELEMENTS] [n-vertices: N-VERTICES])
185
186{{ATTRIBUTES}} is a list in the form:
187
188    (NAME TYPE N [normalized: NORMALIZED])
189
190where {{NAME}} is the attribute name (as a symbol), {{TYPE}} is the type of the attribute as accepted by {{type->gl}}, {{N}} is the number of elements in the attribute, {{NORMALIZED}} is a boolean value indicating whether the attribute’s values should be normalized (defaulting to {{#f}}).
191
192{{INITIAL-ELEMENTS}} is either a bytevector or a list of {{(NAME . VALUE)}} pairs where name is the name of the attribute to set (as per the name given in {{ATTRIBUTES}}) and {{VALUE}} is the initial contents of that attribute. When a list is given and more than one attribute is given initial-elements, the {{VALUE}}s should represent the same number of vertices. Values associated with attributes that are {{NORMALIZED}} should be provided as float between {{0.0}} and {{1.0}} (for unsigned types) or {{-1.0}} and {{1.0}}, which are then normalized. If {{INITIAL-ELEMENTS}} is given as a bytevector, that bytevector is used as the entire mesh’s vertex data and {{N-VERTICES}} – the number of vertices – must be provided, otherwise {{N-VERTICES}} is ignored.
193
194{{INDICES}} is an optional list of key value pairs that specifies the mesh’s index data, if it exists. It should be in the form:
195
196    (type: TYPE [initial-elements: INITIAL-ELEMENTS] [n-indices: N-INDICES])
197
198{{TYPE}} is a type keyword (as accepted by {{type->gl}}) that must be a valid type for an element array buffer (i.e. an unsigned fixnum). {{INITIAL-ELEMENTS}} is either a bytevector or a list of values. If {{INITIAL-ELEMENTS}} is given as a bytevector,  {{N-INDICES}} – the number of indices – must be provided, otherwise {{N-INDICES}} is ignored. When no {{INDICES}} list is provided, the number of indices (as returned by {{mesh-n-indices}}) is set to the number of vertices.
199
200{{MODE}} is the keyword (as accepted by {{mode->gl}}) that defines what the mesh is supposed to represent. Defaults to {{#:triangles}}.
201
202<record> (mesh VERTEX-ATTRIBUTES INDEX-TYPE VERTEX-DATA INDEX-DATA N-VERTICES N-INDICES VERTEX-BUFFER INDEX-BUFFER VAO STRIDE MODE USAGE)</record>
203
204The type of record returned by {{make-mesh}}. {{VERTEX-ATTRIBUTES}} is a list of {{vertex-attribute}} records. {{INDEX-TYPE}} is the type given to the {{indices:}} argument of {{make-mesh}}. {{VERTEX-DATA}} and {{INDEX-DATA}} are the bytevectors representing the vertex and index data. {{N-VERTICES}} and {{N-INDICES}} are the number of vertices and indices present in the data. {{VERTEX-BUFFER}}, {{INDEX-BUFFER}} and {{VAO}} are the vertex buffers and VAO created by {{mesh-make-vao!}}. {{STRIDE}} is the number of bytes between the start of consecutive vertices. {{MODE}} is the value of the {{mode:}} argument provided to {{make-mesh}}. {{USAGE}} is the buffer usage that is set with {{make-mesh-vao!}}.
205
206<record> (vertex-attribute name type number normalized)</record>
207
208The type of record returned by {{mesh-vertex-attributes}}. Getters for all of the fields are provided.
209
210<procedure> (mesh-make-vao! MESH LOCATIONS [USAGE])</procedure>
211
212Create a vertex attribute object (VAO) for {{MESH}}. {{LOCATIONS}} is a list of {{(ATTRIBUTE-NAME . LOCATION)}} pairs. {{USAGE}} is the buffer usage hint keyword as accepted by {{usage->gl}}, defaulting to {{#:static}}. Vertex buffer objects (VBOs) are created for the vertex and index data. The VAO binds these buffers, and sets the vertex attribute pointers of attributes for which locations have been given. If the usage is one of the static types, the vertex and index data of the mesh are deleted, as are the vertex and index buffers. The VBOs and VAO created by {{make-mesh-vao!}} are managed and should not be deleted.
213
214<procedure> (mesh-update! MESH VERTICES [INDICES])</procedure>
215
216Update the entirety of the vertex data and optionally the index data of the {{MESH}}. This can be used in order to reuse the memory and vertex buffers of a mesh. {{VERTICES}} should be the same sort of list of {{(NAME . VALUE)}} attribute pairs that is accepted as the {{initial-elements:}} argument to {{make-mesh}}’s {{vertices:}} (though not a bytevector). The data in {{VERTICES}} should match the attributes of the original vector. Similarly, {{INDICES}} should be the same kind of list of elements that is accepted to {{make-mesh}}’s {{indices}}’s {{initial-elements:}}. The data in both {{VERTICES}} and {{INDICES}} must fit within the vertex and index bytevectors of the {{MESH}}. This can be called before or after {{mesh-make-vao!}}. Do not call inside {{with-mesh}}.
217
218<procedure> (mesh-vertex-ref MESH ATTRIBUTE VERTEX)</procedure>
219
220Return a vector containing the values of the attribute named {{ATTRIBUTE}} corresponding to the {{VERTEX}}th vertex of the {{MESH}}. The result will be a srfi-4 numeric vector, corresponding to the type of the given attribute.
221
222<procedure> (mesh-vertex-set! MESH ATTRIBUTE VERTEX VALUE)</procedure>
223
224Set the {{VERTEX}}th vertex of the {{MESH}}’s attribute named {{ATTRIBUTE}} to the values provided by the srfi-4 numeric vector {{VALUE}}. {{VALUE}} must correspond to the type of the attribute, and should be the same length as the attribute. Using a {{VALUE}} that is too short is unsafe.
225
226If {{mesh-make-vao!}} has been called already, {{mesh-vertex-set!}} should be called inside a {{with-mesh}}. If {{mesh-make-vao!}} was called with a static usage, {{mesh-vertex-set!}} will result in an error, since there is no longer any vertex data to set.
227
228<procedure> (with-mesh MESH THUNK)</procedure>
229
230Calls {{THUNK}} with the VBO of the {{MESH}}’s vertex buffer bound. If the mesh has been modified by {{mesh-vertex-set!}}, the vertex buffer’s data will be updated before the VBO is unbound. When the usage hint given to {{mesh-make-vao!}} is dynamic, {{buffer-sub-data}} will be used to update the buffer data. When the usage hint is stream, {{buffer-data}} will be used.
231
232<procedure> (mesh-copy! TO AT FROM [START] [END])</procedure>
233
234Similar to {{bytevector-copy!}}, copies the vertices of mesh {{FROM}} between vertices {{START}} and {{END}} to mesh {{TO}}, starting at vertex {{AT}}.
235
236<procedure> (mesh-copy MESH)</procedure>
237
238Creates a fresh copy of {{MESH}}.
239
240<procedure> (mesh-append MESHES)</procedure>
241
242Creates a new mesh resulting from appending the vertices of the given meshes together. The indices are also appended and modified so they point to the same vertices. The attributes of all the meshes are assumed to be the same, otherwise bad things will probably happen.
243
244<procedure> (mesh-transform! MESH TRANSFORM [start: START] [end: END] [position-name: POSITION-NAME] [normal-name: NORMAL-NAME] [normal-transform: NORMAL-TRANSFORM])</procedure>
245
246Destructively modifies the {{POSITION-NAME}} attribute of {{MESH}} by the [[http://wiki.call-cc.org/eggref/4/gl-math|gl-math]] matrix {{TRANSFORM}}. {{POSITION-NAME}} defaults to {{'position}} and must be the name of a three element float attribute of {{MESH}}. If {{NORMAL-NAME}} (defaulting to {{'normal}}) is the name of an attribute in the given mesh, this attribute will be transformed by the inverse-transpose of the transform matrix. If {{NORMAL-TRANSFORM}} is present, it will be used instead of the {{TRANSFORM}} matrix for normal transformations.
247
248<procedure> (mesh-transform-append MESH-TRANSFORM-PAIRS [position-name: POSITION-NAME] [normal-name: NORMAL-NAME])</procedure>
249
250Creates a new mesh resulting by appending all the given meshes together, then transforming the attribute named by {{POSITION-NAME}} by the given [[http://wiki.call-cc.org/eggref/4/gl-math|gl-math]] transform matrices. {{MESH-TRANSFORM-PAIRS}} are {{(MESH TRANSFORM [NORMAL-TRANSFORM])}} tuples. {{POSITION-NAME}} defaults to {{'position}} and must be the name of a three element float attribute of {{MESH}}. If {{NORMAL-NAME}} (defaulting to {{'normal}}) is the name of an attribute in the given mesh, this attribute will be transformed by the inverse-transpose of the transform matrices. If {{NORMAL-TRANSFORM}} is present, it will be used instead of the {{TRANSFORM}} matrix for normal transformations. The attributes of all the meshes are assumed to be the same, otherwise bad things will probably happen.
251
252<procedure> (usage->gl USAGE)</procedure>
253
254Converts the keyword {{USAGE}} into a OpenGL usage enum value. Accepted usages (grouped by synonyms) are:
255
256* {{dynamic:}} {{dynamic-draw:}}
257* {{stream:}} {{stream-draw:}}
258* {{static:}} {{static-draw:}}
259* {{dynamic-read:}}
260* {{stream-read:}}
261* {{static-read:}}
262* {{dynamic-copy:}}
263* {{stream-copy:}}
264* {{static-copy:}}
265
266This line is here to prevent a Markdown parsing error :|
267
268<procedure> (mode->gl MODE)</procedure>
269
270Converts the keyword {{MODE}} into a OpenGL mode enum value. Accepted modes are:
271
272* {{points:}}
273* {{lines:}}
274* {{line-strip:}}
275* {{line-loop:}}
276* {{line-strip-adjacency:}}**
277* {{lines-adjacency:}}**
278* {{triangle-strip:}}
279* {{triangle-fan:}}
280* {{triangles:}}
281* {{triangle-strip-adjacency:}}**
282* {{triangles-adjacency:}}**
283* {{patches:}}**
284
285** Not available in GL ES
286
287
288==== gl-utils-ply
289<procedure> (load-ply FILE BUFFER-SPEC)</procedure>
290
291Loads a [[http://paulbourke.net/dataformats/ply/|PLY]] file. {{FILE}} is a path that may be pointing either to a gziped PLY file or a regular PLY file. {{BUFFER-SPEC}} is a list in the form {{((NAME VARS) ...)}} where {{NAME}} is the name of an element in the PLY file and {{VARS}} is either a list of property names or, in the case of a property list, a single name. Two values are returned: a list of bytevectors which correspond to the buffers named in {{BUFFER-SPEC}} and a list of the elements that are in the PLY file in the form of:
292
293    (element-name n-elements (property-name property-type))
294
295Or, when an element is a property list:
296
297    (element-name n-elements (property-name (list: list-length-type element-type)))
298
299The buffers returned are packed with the contents of the properties named in the {{BUFFER-SPEC}}. Thus, for a PLY file that has element {{vertex}} with properties {{float x}}, {{float y}}, {{float z}}, {{float confidence}}, {{uchar r}}, {{uchar g}}, and {{uchar b}}, as well as an element {{face}} with a property list {{uchar ushort vertex_index}}, the following {{BUFFER-SPEC}} could be used:
300
301    (load-ply "example.ply.gz" '((vertex: (x y z r g b)) (face: vertex_index)))
302
303This buffer spec would result in a list of two u8vectors being returned: one with the packed elements corresponding to properties {{x}}, {{y}}, {{z}}, {{r}}, {{g}}, and {{b}} (with the corresponding property types), and the second containing the vertex indices.
304
305<procedure> (load-ply-mesh FILE vertex: VERTEX face: FACE)</procedure>
306
307Similar to load-ply, but returns a mesh. {{FILE}} is a PLY file (which may be gziped). The PLY file must contain at least the elements {{vertex}} and {{face}} (other elements will be ignored). {{VERTEX}} is a list of {{(ATTRIBUTE-NAME PROPERTY-NAME ...)}} elements, which specifies which PLY properties are associate with which attribute, in which order. Attributes are all normalized. All properties named by each element of {{VERTEX}} must be of the same type. {{FACE}} is the name of the face property list.
308
309Again, for a PLY file that has element {{vertex}} with properties {{float x}}, {{float y}}, {{float z}}, {{float confidence}}, {{uchar r}}, {{uchar g}}, and {{uchar b}}, as well as a element {{face}} with a property list {{uchar ushort vertex_index}}, the following could be used:
310
311    (load-ply-mesh "example.ply" vertex: `((position x y z)
312                                          (color r g b))
313                                face: vertex_index)
314
315This would create a mesh with vertex attributes {{(position #:float 3)}} and {{(color #:unsigned-byte 3 normalized: #t)}} and the {{#:unsigned-short}} indices given by {{vertex_index}}.
316
317
318==== gl-utils-srfi-4
319'''This module has been deprecated. With gl-utils-mesh and gl-utils-bytevector, this functionality is better served by directly using srfi-4. This module may still be accessed by explicitly using gl-utils-srfi-4 for the time-being, but it will be removed in the future.'''
320
321gl-utils-srfi-4 reexports a version of [[http://api.call-cc.org/doc/srfi-4|srfi-4]] that gives preference to vectors being created in non-garbage collected memory. This is useful for use with OpenGL, since it is often desirable to pass vectors to OpenGL that will remain in one place. All srfi-4 functions not mentioned below are reexported without changes.
322
323The {{NNNvector}} and {{list->NNNvector}} constructors have been modified so that they return vectors in non-garbage collected memory. They will still be freed when no longer used.
324
325The {{make-NNNvector}} constructors act as their srfi-4 counterparts, except they return vectors in non-garbage collected memory by default. They will still be freed when non longer used.
326
327
328=== Examples
329This example depends on the [[http://wiki.call-cc.org/eggref/4/opengl-glew|opengl-glew]] egg, the [[http://wiki.call-cc.org/eggref/4/glfw3|glfw3]] egg for window and context creation, and the [[http://wiki.call-cc.org/eggref/4/gl-math|gl-math]] egg for matrix math.
330
331For more examples, check out the [[https://github.com/AlexCharlton/gl-utils/tree/master/examples|examples directory]].
332
333<enscript highlight="scheme">    
334(import chicken scheme)
335(use (prefix glfw3 glfw:) (prefix opengl-glew gl:) gl-math gl-utils)
336
337(define *vertex*
338#<<END
339#version 330
340in vec2 position;
341in vec3 color;
342out vec3 c;
343uniform mat4 MVP;
344
345void main(){
346   gl_Position = MVP * vec4(position, 0.0, 1.0);
347   c = color;
348}
349END
350)
351
352(define *fragment*
353#<<END
354#version 330
355in vec3 c;
356out vec4 fragColor;
357void main(){
358  fragColor = vec4(c, 1.0);
359}
360END
361)
362
363(define rect (make-mesh
364              vertices: '(attributes: ((position #:float 2)
365                                       (color #:unsigned-byte 3
366                                              normalized: #t))
367                          initial-elements: ((position . (-1 -1
368                                                           1 -1
369                                                           1  1
370                                                           -1  1))
371                                             (color . (255 0   0
372                                                       0   255 0
373                                                       0   0   255
374                                                       255 0   255))))
375              indices: '(type: #:ushort
376                         initial-elements: (0 1 2
377                                            0 2 3))))
378
379(define program (make-parameter #f))
380
381(define projection-matrix
382  (perspective 640 480 0.1 100 70))
383
384(define view-matrix
385  (look-at (make-point 1 0 3)
386           (make-point 0 0 0)
387           (make-point 0 1 0)))
388
389(define model-matrix (mat4-identity))
390
391(define (render)
392  (gl:use-program (program))
393  (gl:uniform-matrix4fv (gl:get-uniform-location (program) "MVP")
394                        1 #f
395                        (m* projection-matrix
396                            (m* view-matrix model-matrix)))
397  (gl:bind-vertex-array (mesh-vao rect))
398  (gl:draw-elements-base-vertex (mode->gl (mesh-mode rect))
399                                (mesh-n-indices rect)
400                                (type->gl (mesh-index-type rect))
401                                #f 0)
402
403  (check-error)
404  (gl:bind-vertex-array 0))
405
406(glfw:with-window (640 480 "Example" resizable: #f
407                       context-version-major: 3
408                       context-version-minor: 3)
409  (gl:init)
410
411  (print (gl:is-supported? "GL_ARB_framebuffer_object"))
412
413  (set! *vertex* (make-shader gl:+vertex-shader+ *vertex*))
414  (set! *fragment* (make-shader gl:+fragment-shader+ *fragment*))
415  (program (make-program (list *vertex* *fragment*)))
416
417  (mesh-make-vao! rect `((position . ,(gl:get-attrib-location
418                                       (program) "position"))
419                         (color . ,(gl:get-attrib-location
420                                    (program) "color"))))
421  (let loop ()
422    (glfw:swap-buffers (glfw:window))
423    (gl:clear (bitwise-ior gl:+color-buffer-bit+ gl:+depth-buffer-bit+))
424    (render)
425    (glfw:poll-events) ; Because of the context version, initializing GLEW results in a harmless invalid enum
426    (unless (glfw:window-should-close (glfw:window))
427      (loop))))
428</enscript>
429
430
431=== Version history
432
433==== Version 0.7.0
43424 April 2016
435
436* Make {{mesh-transform!}} and {{mesh-transform-append}} aware of normals
437
438
439==== Version 0.6.0
44016 January 2014
441
442* Deprecate gl-utils-srfi-4
443
444
445==== Version 0.5.0
44623 December 2014
447
448* Add {{mesh-update!}}
449
450
451==== Version 0.4.0
4528 December 2014
453
454* Add Windows, OS X, GL ES support
455* Bug fixes
456
457
458==== Version 0.3.0
45911 September 2014
460
461* Merge {{mesh-attribute-locations-set!}} with {{mesh-make-vao!}}
462
463
464==== Version 0.2.0
46510 September 2014
466
467* Add gl-utils-bytevector module
468* Add gl-utils-mesh module
469* Remove now-unneeded (and broken) {{make-vao}}, {{make-ply-vao}}
470
471
472==== Version 0.1.2
4732 September 2014
474
475* Update example for gl-math 0.5
476
477'''Version 0.1.1'''
478* Initial release
479
480
481=== Source repository
482Source available on [[https://github.com/AlexCharlton/gl-utils|GitHub]].
483
484Bug reports and patches welcome! Bugs can be reported via GitHub or to alex.n.charlton at gmail.
485
486
487=== Author
488Alex Charlton
489
490
491=== License
492BSD
Note: See TracBrowser for help on using the repository browser.