|
|
@ -5,9 +5,12 @@ |
|
|
|
#version 330 core |
|
|
|
#version 330 core |
|
|
|
layout (location = 0) in vec3 aPos; |
|
|
|
layout (location = 0) in vec3 aPos; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
out vec4 vertexColor; |
|
|
|
|
|
|
|
|
|
|
|
void main() |
|
|
|
void main() |
|
|
|
{ |
|
|
|
{ |
|
|
|
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); |
|
|
|
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0); |
|
|
|
|
|
|
|
vertexColor = vec4(0.5, 0.0, 0.0, 1.0); |
|
|
|
} |
|
|
|
} |
|
|
|
")) |
|
|
|
")) |
|
|
|
|
|
|
|
|
|
|
@ -15,15 +18,19 @@ void main() |
|
|
|
#version 330 core |
|
|
|
#version 330 core |
|
|
|
out vec4 FragColor; |
|
|
|
out vec4 FragColor; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// in vec4 vertexColor; |
|
|
|
|
|
|
|
uniform vec4 ourColor; |
|
|
|
|
|
|
|
|
|
|
|
void main() |
|
|
|
void main() |
|
|
|
{ |
|
|
|
{ |
|
|
|
FragColor = vec4(1.0f, 0.5f, 0.2f, 1.0f); |
|
|
|
FragColor = ourColor; |
|
|
|
} |
|
|
|
} |
|
|
|
")) |
|
|
|
")) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defparameter *vbo* 0) |
|
|
|
(defparameter *vbo* 0) |
|
|
|
(defparameter *vao* 0) |
|
|
|
(defparameter *vao* 0) |
|
|
|
|
|
|
|
(defparameter *ebo* 0) |
|
|
|
(defparameter *shader-program* 0) |
|
|
|
(defparameter *shader-program* 0) |
|
|
|
|
|
|
|
|
|
|
|
(defun init-renderer () |
|
|
|
(defun init-renderer () |
|
|
@ -40,23 +47,47 @@ void main() |
|
|
|
(gl:delete-shader vertex-shader) |
|
|
|
(gl:delete-shader vertex-shader) |
|
|
|
(gl:delete-shader fragment-shader) |
|
|
|
(gl:delete-shader fragment-shader) |
|
|
|
(setf *vbo* (gl:gen-buffer)) |
|
|
|
(setf *vbo* (gl:gen-buffer)) |
|
|
|
|
|
|
|
(setf *ebo* (gl:gen-buffer)) |
|
|
|
(setf *vao* (gl:gen-vertex-array)) |
|
|
|
(setf *vao* (gl:gen-vertex-array)) |
|
|
|
|
|
|
|
|
|
|
|
(gl:bind-vertex-array *vao*) |
|
|
|
(gl:bind-vertex-array *vao*) |
|
|
|
(gl:bind-buffer :array-buffer *vbo*) |
|
|
|
(gl:bind-buffer :array-buffer *vbo*) |
|
|
|
|
|
|
|
(gl:bind-buffer :element-array-buffer *ebo*) |
|
|
|
|
|
|
|
|
|
|
|
(let ((arr (gl:alloc-gl-array :float 12)) |
|
|
|
(let* ((vertices #( 0.5 0.5 0.0 |
|
|
|
(vertices #(-0.5 -0.5 0.0 |
|
|
|
|
|
|
|
0.5 -0.5 0.0 |
|
|
|
0.5 -0.5 0.0 |
|
|
|
0.0 0.5 0.0))) |
|
|
|
-0.5 -0.5 0.0 |
|
|
|
|
|
|
|
-0.5 0.5 0.0)) |
|
|
|
|
|
|
|
(arr (gl:alloc-gl-array :float (length vertices)))) |
|
|
|
(dotimes (i (length vertices)) |
|
|
|
(dotimes (i (length vertices)) |
|
|
|
(setf (gl:glaref arr i) (aref vertices i))) |
|
|
|
(setf (gl:glaref arr i) (aref vertices i))) |
|
|
|
(gl:buffer-data :array-buffer :static-draw arr) |
|
|
|
(gl:buffer-data :array-buffer :static-draw arr) |
|
|
|
(gl:free-gl-array arr)) |
|
|
|
(gl:free-gl-array arr)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let* ((indices #(0 1 3 |
|
|
|
|
|
|
|
1 2 3)) |
|
|
|
|
|
|
|
(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:vertex-attrib-pointer 0 3 :float nil 0 (cffi:null-pointer)) |
|
|
|
(gl:enable-vertex-attrib-array 0))) |
|
|
|
(gl:enable-vertex-attrib-array 0))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun enable-wireframe () |
|
|
|
|
|
|
|
(gl:polygon-mode :front-and-back :line)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(defun disable-wireframe () |
|
|
|
|
|
|
|
(gl:polygon-mode :front-and-back :fill)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(let ((wireframe nil)) |
|
|
|
|
|
|
|
(defun toggle-wireframe () |
|
|
|
|
|
|
|
(if wireframe |
|
|
|
|
|
|
|
(disable-wireframe) |
|
|
|
|
|
|
|
(enable-wireframe)) |
|
|
|
|
|
|
|
(setf wireframe (not wireframe)))) |
|
|
|
|
|
|
|
|
|
|
|
(defun render () |
|
|
|
(defun render () |
|
|
|
(gl:clear :color-buffer) |
|
|
|
(gl:clear :color-buffer) |
|
|
|
;; (gl:with-pushed-matrix |
|
|
|
;; (gl:with-pushed-matrix |
|
|
@ -64,7 +95,10 @@ void main() |
|
|
|
;; (gl:rect -25 -25 25 25)) |
|
|
|
;; (gl:rect -25 -25 25 25)) |
|
|
|
|
|
|
|
|
|
|
|
(gl:use-program *shader-program*) |
|
|
|
(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:bind-vertex-array *vao*) |
|
|
|
(gl:draw-arrays :triangles 0 3) |
|
|
|
(gl:draw-elements :triangles (gl:make-null-gl-array :unsigned-int) :count 6) |
|
|
|
|
|
|
|
(gl:bind-vertex-array 0) |
|
|
|
|
|
|
|
|
|
|
|
(glfw:swap-buffers)) |
|
|
|
(glfw:swap-buffers)) |
|
|
|