Compare commits

...

No commits in common. "master" and "gdx" have entirely different histories.
master ... gdx

4 changed files with 50 additions and 86 deletions

View File

@ -21,16 +21,16 @@
:target-dir class-dir})
(b/jar {:class-dir class-dir
:jar-file jar-file
:main 'ois.core}))
:main 'ois.launcher}))
(defn uber [_]
(clean nil)
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(b/compile-clj {:basis basis
:ns-compile '[ois.core]
:ns-compile '[ois.launcher]
:class-dir class-dir})
(b/uber {:class-dir class-dir
:uber-file uber-file
:basis basis
:main 'ois.core}))
:main 'ois.launcher}))

View File

@ -1,12 +1,15 @@
{
:paths ["src"]
:deps {
org.clojure/clojure { :mvn/version "1.11.1" }
metosin/malli { :mvn/version "0.13.0" }
org.lwjgl/lwjgl { :mvn/version "3.3.3" }
org.lwjgl/lwjgl-glfw { :mvn/version "3.3.3" }
org.lwjgl/lwjgl-opengl { :mvn/version "3.3.3" }
nrepl/nrepl { :mvn/version "0.4.0" }
com.badlogicgames.gdx/gdx { :mvn/version "1.11.0" }
com.badlogicgames.gdx/gdx-backend-lwjgl { :mvn/version "1.11.0" }
com.badlogicgames.gdx/gdx-box2d { :mvn/version "1.11.0" }
com.badlogicgames.gdx/gdx-box2d-platform$natives-desktop { :mvn/version "1.11.0" }
com.badlogicgames.gdx/gdx-bullet { :mvn/version "1.11.0" }
com.badlogicgames.gdx/gdx-bullet-platform$natives-desktop { :mvn/version "1.11.0" }
com.badlogicgames.gdx/gdx-platform$natives-desktop { :mvn/version "1.11.0" }
org.clojure/clojure { :mvn/version "1.7.0" }
play-clj/play-clj { :mvn/version "1.1.1" }
}
:aliases {
:build {

View File

@ -1,81 +1,33 @@
(ns ois.core
(:gen-class)
(:import (org.lwjgl Version)
(org.lwjgl.glfw GLFWErrorCallback GLFW GLFWKeyCallbackI Callbacks)
(org.lwjgl.opengl GL GL33)
(org.lwjgl.system MemoryStack)
(java.lang IllegalStateException)))
(:import [com.badlogic.gdx Game Gdx Graphics Screen]
[com.badlogic.gdx.graphics Color GL20]
[com.badlogic.gdx.graphics.g2d BitmapFont]
[com.badlogic.gdx.scenes.scene2d Stage]
[com.badlogic.gdx.scenes.scene2d.ui Label Label$LabelStyle]))
(require '[nrepl.server :refer [start-server stop-server]])
(defonce server (start-server :port 7888))
(gen-class
:name ois.core.Game
:extends com.badlogic.gdx.Game)
(declare window)
(def main-screen
(let [stage (atom nil)]
(proxy [Screen] []
(show []
(reset! stage (Stage.))
(let [style (Label$LabelStyle. (BitmapFont.) (Color. 0 1 0 1))
label (Label. "Hello world!" style)]
(.addActor @stage label)))
(render [delta]
(.glClearColor (Gdx/gl) 0 0 0 0)
(.glClear (Gdx/gl) GL20/GL_COLOR_BUFFER_BIT)
(doto @stage
(.act delta)
(.draw)))
(dispose[])
(hide [])
(pause [])
(resize [w h])
(resume []))))
(declare init main-loop draw)
(defn -main [& args]
(println (str "Hello LWJGL " (Version/getVersion) "!"))
(init)
(main-loop)
(Callbacks/glfwFreeCallbacks window)
(GLFW/glfwDestroyWindow window)
(GLFW/glfwTerminate)
(-> (GLFW/glfwSetErrorCallback nil) (.free)))
(defn init []
(-> (GLFWErrorCallback/createPrint System/err) (.set))
(when (not (GLFW/glfwInit))
(throw (IllegalStateException. "Failed to initialized GLFW.")))
(GLFW/glfwDefaultWindowHints)
(GLFW/glfwWindowHint GLFW/GLFW_VISIBLE GLFW/GLFW_FALSE)
(GLFW/glfwWindowHint GLFW/GLFW_RESIZABLE GLFW/GLFW_TRUE)
(def window (GLFW/glfwCreateWindow 300 300 "Hello World!" 0 0))
(when (zero? window)
(throw (RuntimeException. "Failed to create GLFW window.")))
(GLFW/glfwSetKeyCallback window
(reify GLFWKeyCallbackI
(invoke [this window key scancode action mods]
(when (and (= key GLFW/GLFW_KEY_ESCAPE)
(= action GLFW/GLFW_RELEASE))
(GLFW/glfwSetWindowShouldClose window true)))))
(let [stack (MemoryStack/stackPush)
p-width (.mallocInit stack 1)
p-height (.mallocInit stack 1)]
(GLFW/glfwGetWindowSize ^long window p-width p-height)
(let [vidmode (-> (GLFW/glfwGetPrimaryMonitor)
(GLFW/glfwGetVideoMode))
xpos (/ (- (.width vidmode)
(.get p-width 0))
2)
ypos (/ (- (.width vidmode)
(.get p-height 0))
2)]
(GLFW/glfwSetWindowPos window xpos ypos))
(MemoryStack/stackPop))
(GLFW/glfwMakeContextCurrent window)
(GLFW/glfwSwapInterval 1)
(GLFW/glfwShowWindow window))
(defn main-loop []
(GL/createCapabilities)
(GL33/glClearColor 1.0 0.0 0.0 0.0)
(while (not (GLFW/glfwWindowShouldClose window))
(draw)))
(defn draw []
(GL33/glClearColor 1.0 0.0 0.0 0.0)
(GL33/glClear (bit-or GL33/GL_COLOR_BUFFER_BIT
GL33/GL_DEPTH_BUFFER_BIT))
(GLFW/glfwSwapBuffers window)
(GLFW/glfwPollEvents))
(defn -create [^Game this]
(.setScreen this main-screen))

9
src/ois/launcher.clj Normal file
View File

@ -0,0 +1,9 @@
(ns ois.launcher
(:require [ois.core :refer :all])
(:import [com.badlogic.gdx.backends.lwjgl LwjglApplication]
[org.lwjgl.input Keyboard])
(:gen-class))
(defn -main []
(LwjglApplication. (ois.core.Game.) "demo" 800 600)
(Keyboard/enableRepeatEvents true))