|
|
|
@ -4,13 +4,14 @@
@@ -4,13 +4,14 @@
|
|
|
|
|
(defparameter *vertex-shader-source* '(" |
|
|
|
|
#version 330 core |
|
|
|
|
layout (location = 0) in vec3 aPos; |
|
|
|
|
layout (location = 1) in vec3 aColor; |
|
|
|
|
|
|
|
|
|
out vec4 vertexColor; |
|
|
|
|
out vec3 ourColor; |
|
|
|
|
|
|
|
|
|
void main() |
|
|
|
|
{ |
|
|
|
|
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); |
|
|
|
|
vertexColor = vec4(0.5, 0.0, 0.0, 1.0); |
|
|
|
|
gl_Position = vec4(aPos, 1.0); |
|
|
|
|
ourColor = aColor; |
|
|
|
|
} |
|
|
|
|
")) |
|
|
|
|
|
|
|
|
@ -18,12 +19,11 @@ void main()
@@ -18,12 +19,11 @@ void main()
|
|
|
|
|
#version 330 core |
|
|
|
|
out vec4 FragColor; |
|
|
|
|
|
|
|
|
|
// in vec4 vertexColor; |
|
|
|
|
uniform vec4 ourColor; |
|
|
|
|
in vec3 ourColor; |
|
|
|
|
|
|
|
|
|
void main() |
|
|
|
|
{ |
|
|
|
|
FragColor = ourColor; |
|
|
|
|
FragColor = vec4(ourColor, 1.0); |
|
|
|
|
} |
|
|
|
|
")) |
|
|
|
|
|
|
|
|
@ -54,26 +54,30 @@ void main()
@@ -54,26 +54,30 @@ void main()
|
|
|
|
|
(gl:bind-buffer :array-buffer *vbo*) |
|
|
|
|
(gl:bind-buffer :element-array-buffer *ebo*) |
|
|
|
|
|
|
|
|
|
(let* ((vertices #( 0.5 0.5 0.0 |
|
|
|
|
0.5 -0.5 0.0 |
|
|
|
|
-0.5 -0.5 0.0 |
|
|
|
|
-0.5 0.5 0.0)) |
|
|
|
|
(let* ((vertices #( 0.5 -0.5 0.0 1.0 0.0 0.0 |
|
|
|
|
-0.5 -0.5 0.0 0.0 1.0 0.0 |
|
|
|
|
0.0 0.5 0.0 0.0 0.0 1.0)) |
|
|
|
|
(arr (gl:alloc-gl-array :float (length vertices)))) |
|
|
|
|
(dotimes (i (length vertices)) |
|
|
|
|
(setf (gl:glaref arr i) (aref vertices i))) |
|
|
|
|
(gl:buffer-data :array-buffer :static-draw arr) |
|
|
|
|
(gl:free-gl-array arr)) |
|
|
|
|
|
|
|
|
|
(let* ((indices #(0 1 3 |
|
|
|
|
1 2 3)) |
|
|
|
|
(let* ((indices #(0 1 2)) |
|
|
|
|
(arr (gl:alloc-gl-array :int (length indices)))) |
|
|
|
|
(dotimes (i (length indices)) |
|
|
|
|
(setf (gl:glaref arr i) (aref indices i))) |
|
|
|
|
(gl:buffer-data :element-array-buffer :static-draw arr) |
|
|
|
|
(gl:free-gl-array arr)) |
|
|
|
|
|
|
|
|
|
(gl:vertex-attrib-pointer 0 3 :float nil 0 (cffi:null-pointer)) |
|
|
|
|
(gl:enable-vertex-attrib-array 0))) |
|
|
|
|
(gl:vertex-attrib-pointer 0 3 :float nil |
|
|
|
|
(* 6 (cffi:foreign-type-size :float)) |
|
|
|
|
(cffi:null-pointer)) |
|
|
|
|
(gl:enable-vertex-attrib-array 0) |
|
|
|
|
(gl:vertex-attrib-pointer 1 3 :float nil |
|
|
|
|
(* 6 (cffi:foreign-type-size :float)) |
|
|
|
|
(cffi:make-pointer (* 3 (cffi:foreign-type-size :float)))) |
|
|
|
|
(gl:enable-vertex-attrib-array 1))) |
|
|
|
|
|
|
|
|
|
(defun enable-wireframe () |
|
|
|
|
(gl:polygon-mode :front-and-back :line)) |
|
|
|
@ -95,10 +99,8 @@ void main()
@@ -95,10 +99,8 @@ void main()
|
|
|
|
|
;; (gl:rect -25 -25 25 25)) |
|
|
|
|
|
|
|
|
|
(gl:use-program *shader-program*) |
|
|
|
|
(gl:uniformf (gl:get-uniform-location *shader-program* "ourColor") |
|
|
|
|
0.0 (+ (/ (sin (glfw:get-time)) 2) 0.5) 0.0 1.0) |
|
|
|
|
(gl:bind-vertex-array *vao*) |
|
|
|
|
(gl:draw-elements :triangles (gl:make-null-gl-array :unsigned-int) :count 6) |
|
|
|
|
(gl:draw-elements :triangles (gl:make-null-gl-array :unsigned-int) :count 3) |
|
|
|
|
(gl:bind-vertex-array 0) |
|
|
|
|
|
|
|
|
|
(glfw:swap-buffers)) |
|
|
|
|