Clean
This commit is contained in:
parent
0f8dae0943
commit
10e37cc33f
@ -1,9 +1,9 @@
|
|||||||
(ns nol.core
|
(ns nol.core
|
||||||
(:require [clojure.math])
|
(:require [clojure.math])
|
||||||
(:import [org.lwjgl.assimp Assimp AIScene AIMesh AIVector3D AIFace]
|
(:import [org.lwjgl.assimp Assimp AIFace AIMaterial AIMesh AIScene AIVector3D]
|
||||||
[org.lwjgl.glfw GLFW GLFWKeyCallbackI GLFWErrorCallbackI]
|
[org.lwjgl.glfw GLFW GLFWErrorCallbackI GLFWKeyCallbackI]
|
||||||
[org.lwjgl.opengl GL GL45 GL33 GL20 GL15 GL11 GL30]
|
[org.lwjgl.opengl GL GL11 GL15 GL20 GL33 GL30 GL45]
|
||||||
[org.lwjgl.system MemoryStack MemoryUtil]
|
[org.lwjgl.system MemoryUtil MemoryStack]
|
||||||
[org.joml Matrix4f]
|
[org.joml Matrix4f]
|
||||||
[java.nio FloatBuffer]))
|
[java.nio FloatBuffer]))
|
||||||
|
|
||||||
@ -63,21 +63,9 @@
|
|||||||
|
|
||||||
(swap! state assoc :last-time t)
|
(swap! state assoc :last-time t)
|
||||||
|
|
||||||
(GL45/glUseProgram (:program data))
|
|
||||||
(let [loc (GL45/glGetUniformLocation (:program data) "uColor")
|
|
||||||
t (* t 2)]
|
|
||||||
(GL45/glUniform4f loc
|
|
||||||
(* 0.5 (+ 1.0 (clojure.math/sin t)))
|
|
||||||
(* 0.5 (+ 1.0 (clojure.math/sin (+ t 2.094))))
|
|
||||||
(* 0.5 (+ 1.0 (clojure.math/sin (+ t 4.189))))
|
|
||||||
1.0))
|
|
||||||
(GL45/glBindVertexArray (:vao data))
|
|
||||||
(GL45/glDrawArrays GL45/GL_TRIANGLES 0 3)
|
|
||||||
|
|
||||||
(GLFW/glfwSwapBuffers window)))
|
(GLFW/glfwSwapBuffers window)))
|
||||||
|
|
||||||
(defn stop! []
|
(defn stop! []
|
||||||
;; signal the window to close
|
|
||||||
(with-gl
|
(with-gl
|
||||||
(GLFW/glfwSetWindowShouldClose
|
(GLFW/glfwSetWindowShouldClose
|
||||||
(:window @state) true)))
|
(:window @state) true)))
|
||||||
@ -90,7 +78,7 @@
|
|||||||
(GLFW/glfwWindowHint GLFW/GLFW_CONTEXT_VERSION_MINOR 5)
|
(GLFW/glfwWindowHint GLFW/GLFW_CONTEXT_VERSION_MINOR 5)
|
||||||
(GLFW/glfwWindowHint GLFW/GLFW_OPENGL_PROFILE GLFW/GLFW_OPENGL_CORE_PROFILE)
|
(GLFW/glfwWindowHint GLFW/GLFW_OPENGL_PROFILE GLFW/GLFW_OPENGL_CORE_PROFILE)
|
||||||
|
|
||||||
(let [window (GLFW/glfwCreateWindow 960 592 "NOL" MemoryUtil/NULL MemoryUtil/NULL)]
|
(let [window (GLFW/glfwCreateWindow 960 300 #_592 "NOL" MemoryUtil/NULL MemoryUtil/NULL)]
|
||||||
(when (= window MemoryUtil/NULL)
|
(when (= window MemoryUtil/NULL)
|
||||||
(GLFW/glfwTerminate)
|
(GLFW/glfwTerminate)
|
||||||
(throw (RuntimeException. "Failed to create window")))
|
(throw (RuntimeException. "Failed to create window")))
|
||||||
@ -108,22 +96,7 @@
|
|||||||
(when (and (= key GLFW/GLFW_KEY_ESCAPE) (= action GLFW/GLFW_PRESS))
|
(when (and (= key GLFW/GLFW_KEY_ESCAPE) (= action GLFW/GLFW_PRESS))
|
||||||
(swap! state assoc :should-close true)))))
|
(swap! state assoc :should-close true)))))
|
||||||
|
|
||||||
(let [vbo (GL45/glCreateBuffers)
|
(let []
|
||||||
vao (GL45/glCreateVertexArrays)
|
|
||||||
data (try
|
|
||||||
(let [vert (compile-shader GL20/GL_VERTEX_SHADER vertex-shader-text)
|
|
||||||
frag (compile-shader GL20/GL_FRAGMENT_SHADER fragment-shader-text)
|
|
||||||
program (link-program vert frag)]
|
|
||||||
(GL45/glNamedBufferStorage vbo vertices GL45/GL_DYNAMIC_STORAGE_BIT)
|
|
||||||
(GL45/glVertexArrayVertexBuffer vao 0 vbo 0 12)
|
|
||||||
(GL45/glEnableVertexArrayAttrib vao 0)
|
|
||||||
(GL45/glVertexArrayAttribFormat vao 0 3 GL45/GL_FLOAT false 0)
|
|
||||||
(GL45/glVertexArrayAttribBinding vao 0 0)
|
|
||||||
{:vbo vbo :vao vao :program program})
|
|
||||||
(catch Exception e
|
|
||||||
(println "Setup error:" (.getMessage e))
|
|
||||||
nil))]
|
|
||||||
(swap! state merge data)
|
|
||||||
(loop []
|
(loop []
|
||||||
(while (not (.isEmpty render-queue))
|
(while (not (.isEmpty render-queue))
|
||||||
((.take render-queue)))
|
((.take render-queue)))
|
||||||
@ -132,7 +105,7 @@
|
|||||||
(GLFW/glfwPollEvents)
|
(GLFW/glfwPollEvents)
|
||||||
(let [stack (MemoryStack/stackPush)]
|
(let [stack (MemoryStack/stackPush)]
|
||||||
(try
|
(try
|
||||||
(update-loop window stack data)
|
(update-loop window stack {})
|
||||||
(finally
|
(finally
|
||||||
(MemoryStack/stackPop))))
|
(MemoryStack/stackPop))))
|
||||||
(recur))))
|
(recur))))
|
||||||
@ -159,6 +132,7 @@
|
|||||||
(def ^AIScene scene (load-model "assets/model.glb"))
|
(def ^AIScene scene (load-model "assets/model.glb"))
|
||||||
(.mNumMeshes scene) ;; 54
|
(.mNumMeshes scene) ;; 54
|
||||||
(.mNumMaterials scene) ;; 17
|
(.mNumMaterials scene) ;; 17
|
||||||
|
|
||||||
(with-gl
|
(with-gl
|
||||||
(GL11/glClearColor 0.392 0.584 0.929 1.0))
|
(GL11/glClearColor 0.392 0.584 0.929 1.0))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user