source: project/wiki/eggref/4/opengl-glew @ 30707

Last change on this file since 30707 was 30707, checked in by acharlton, 7 years ago

Update example to take advantage of new glfw3 features

File size: 4.0 KB
Line 
1[[tags: egg]]
2[[toc:]]
3
4== opengl-glew
5
6Bindings to OpenGL with GLEW extension loading.
7
8Chicken's other [[opengl]] bindings are based on the old fixed function pipeline OpenGL. These bindings generated by [[bind]] with the OpenGL [[http://www.opengl.org/registry/api/GL/glcorearb.h|core header file]]. Additionally, bindings to [[http://glew.sourceforge.net/|GLEW]] are provided for extension management.
9
10=== Requirements
11* [[make]]
12* [[bind]]
13
14=== Documentation
15All functions and constants from the OpenGL [[http://www.opengl.org/registry/api/GL/glcorearb.h|core header file]] are exported. Scheme style names are provided (underscores and camelCase replaced with hyphens), the {{gl}} prefix is removed from names, {{is}} functions are given question marks, and constants are bookended by {{+}}s (e.g. {{tex-image2d}}, {{enabled?}}, {{+arb-viewport-array+}}).
16
17==== GLEW functions
18Two GLEW functions are exposed:
19
20===== init
21  (init)
22
23Required to initialize GLEW/OpenGL. An OpenGL context must be created before this is called.
24
25===== is-supported?
26  (supported? EXTENSION-NAME)
27
28Query whether the OpenGL extension, given as a string, is supported.
29
30==== GL helper functions
31
32===== make-shader
33  (make-shader TYPE SOURCE)
34
35Creates 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.
36
37===== make-program
38  (make-program SHADER-LIST)
39
40Creates 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.
41
42
43=== Example
44This example depends on the [[glfw3]] egg for window and context creation.
45
46<enscript highlight="scheme">
47(import chicken scheme)
48(use (prefix glfw3 glfw:) (prefix opengl-glew gl:))
49
50(define *vertex*
51#<<END
52#version 330
53in vec2 vertex;
54in vec3 color;
55out vec3 c;
56uniform mat4 viewMatrix;
57
58void main(){
59   gl_Position = (viewMatrix * vec4(vertex, 0.0, 1.0));
60   c = color;
61}
62END
63)
64
65(define *fragment*
66#<<END
67#version 330
68in vec3 c;
69out vec4 fragColor;
70void main(){
71  fragColor = vec4(c, 1.0);
72}
73END
74)
75
76(glfw:with-window (640 480 "Example" resizable: #f)
77  (print (gl:supported? "GL_ARB_framebuffer_object"))
78
79  (set! *vertex* (gl:make-shader gl:+vertex-shader+ *vertex*))
80  (set! *fragment* (gl:make-shader gl:+fragment-shader+ *fragment*))
81
82  ;;If this is not zero, then everything is working:
83  (print (gl:make-program (list *vertex* *fragment*))))
84</enscript>
85
86=== Author
87Alex Charlton
88
89=== Source
90Available on [[https://github.com/AlexCharlton/chicken-opengl-glew|GitHub]]
91
92=== Changelog
93* 0.2.0: Add glcorearb.h - no longer downloaded at install time
94* 0.1.0
95
96=== Licence
97Copyright (c) 2014, Alexander Charlton
98All rights reserved.
99
100Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
101
102Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
103Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
104THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Note: See TracBrowser for help on using the repository browser.