From 2080a58b66f7bf4b30120ce35ccad2ad113a6c66 Mon Sep 17 00:00:00 2001 From: Ross W Date: Thu, 14 Aug 2025 21:29:21 +0100 Subject: [PATCH] Initial commit --- .classpath | 57 +++++++++ .gitignore | 5 + .project | 34 +++++ pom.xml | 153 +++++++++++++++++++++++ src/main/java/org/hirw/game/App.java | 74 +++++++++++ src/test/java/org/hirw/game/AppTest.java | 38 ++++++ 6 files changed, 361 insertions(+) create mode 100644 .classpath create mode 100644 .gitignore create mode 100644 .project create mode 100644 pom.xml create mode 100644 src/main/java/org/hirw/game/App.java create mode 100644 src/test/java/org/hirw/game/AppTest.java diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..653dfd7 --- /dev/null +++ b/.classpath @@ -0,0 +1,57 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d2b86f8 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +target/ +.settings/ +.mvn/ +flake.nix +flake.lock diff --git a/.project b/.project new file mode 100644 index 0000000..a25fc79 --- /dev/null +++ b/.project @@ -0,0 +1,34 @@ + + + game + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.m2e.core.maven2Builder + + + + + + org.eclipse.jdt.core.javanature + org.eclipse.m2e.core.maven2Nature + + + + 1755198526799 + + 30 + + org.eclipse.core.resources.regexFilterMatcher + node_modules|\.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__ + + + + diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..01a4cfd --- /dev/null +++ b/pom.xml @@ -0,0 +1,153 @@ + + + + 4.0.0 + + org.hirw.game + game + 1.0-SNAPSHOT + + game + A simple game. + + http://www.hirw.org + + + UTF-8 + 8 + 8 + 3.3.6 + natives-linux + + + + + + org.lwjgl + lwjgl-bom + ${lwjgl.version} + import + pom + + + + + + + junit + junit + 3.8.1 + + + org.lwjgl + lwjgl + + + org.lwjgl + lwjgl-assimp + + + org.lwjgl + lwjgl-glfw + + + org.lwjgl + lwjgl-openal + + + org.lwjgl + lwjgl-opengl + + + org.lwjgl + lwjgl-stb + + + org.lwjgl + lwjgl + ${lwjgl.natives} + + + org.lwjgl + lwjgl-assimp + ${lwjgl.natives} + + + org.lwjgl + lwjgl-glfw + ${lwjgl.natives} + + + org.lwjgl + lwjgl-openal + ${lwjgl.natives} + + + org.lwjgl + lwjgl-opengl + ${lwjgl.natives} + + + org.lwjgl + lwjgl-stb + ${lwjgl.natives} + + + + + + + + maven-clean-plugin + 3.4.0 + + + maven-project-info-reports-plugin + 3.6.1 + + + + maven-resources-plugin + 3.3.1 + + + maven-compiler-plugin + 3.13.0 + + + maven-surefire-plugin + 3.3.0 + + + maven-jar-plugin + 3.4.2 + + + maven-install-plugin + 3.1.2 + + + maven-deploy-plugin + 3.1.2 + + + org.codehaus.mojo + exec-maven-plugin + 3.1.0 + + org.hirw.game.App + + + + + + + + + + maven-project-info-reports-plugin + + + + diff --git a/src/main/java/org/hirw/game/App.java b/src/main/java/org/hirw/game/App.java new file mode 100644 index 0000000..f9a8b44 --- /dev/null +++ b/src/main/java/org/hirw/game/App.java @@ -0,0 +1,74 @@ +package org.hirw.game; + +import static org.lwjgl.glfw.Callbacks.*; +import static org.lwjgl.glfw.GLFW.*; +import static org.lwjgl.opengl.GL11.*; +import static org.lwjgl.system.MemoryStack.*; +import static org.lwjgl.system.MemoryUtil.*; + +import java.nio.*; +import org.lwjgl.*; +import org.lwjgl.glfw.*; +import org.lwjgl.opengl.*; +import org.lwjgl.system.*; + +public class App { + private long window; + + public void run() { + System.out.println("Hello LWJGL " + Version.getVersion() + "!"); + init(); + loop(); + glfwFreeCallbacks(window); + glfwDestroyWindow(window); + glfwTerminate(); + glfwSetErrorCallback(null).free(); + } + + private void init() { + GLFWErrorCallback.createPrint(System.err).set(); + if (!glfwInit()) throw new IllegalStateException("Unable to initialize GLFW"); + + glfwDefaultWindowHints(); + glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); + glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); + + window = glfwCreateWindow(300, 300, "Hello World!", NULL, NULL); + if (window == NULL) throw new RuntimeException("Failed to create the GLFW window"); + + glfwSetKeyCallback( + window, + (window, key, scancode, action, mods) -> { + if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) + glfwSetWindowShouldClose(window, true); + }); + + try (MemoryStack stack = stackPush()) { + IntBuffer pWidth = stack.mallocInt(1); + IntBuffer pHeight = stack.mallocInt(1); + glfwGetWindowSize(window, pWidth, pHeight); + GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + glfwSetWindowPos( + window, (vidmode.width() - pWidth.get(0)) / 2, (vidmode.height() - pHeight.get(0)) / 2); + } + + glfwMakeContextCurrent(window); + glfwSwapInterval(1); + glfwShowWindow(window); + } + + private void loop() { + GL.createCapabilities(); + glClearColor(1.0f, 0.0f, 0.0f, 0.0f); + + while (!glfwWindowShouldClose(window)) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glfwSwapBuffers(window); + glfwPollEvents(); + } + } + + public static void main(String[] args) { + new App().run(); + } +} diff --git a/src/test/java/org/hirw/game/AppTest.java b/src/test/java/org/hirw/game/AppTest.java new file mode 100644 index 0000000..e9c5c37 --- /dev/null +++ b/src/test/java/org/hirw/game/AppTest.java @@ -0,0 +1,38 @@ +package org.hirw.game; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +/** + * Unit test for simple App. + */ +public class AppTest + extends TestCase +{ + /** + * Create the test case + * + * @param testName name of the test case + */ + public AppTest( String testName ) + { + super( testName ); + } + + /** + * @return the suite of tests being tested + */ + public static Test suite() + { + return new TestSuite( AppTest.class ); + } + + /** + * Rigourous Test :-) + */ + public void testApp() + { + assertTrue( true ); + } +}