Kajetan Johannes Hammerle 3 years ago
commit
e464ee8b8b
4 changed files with 77 additions and 0 deletions
  1. 3 0
      .gitmodules
  2. 52 0
      Main.cpp
  3. 1 0
      gaming-core
  4. 21 0
      meson.build

+ 3 - 0
.gitmodules

@@ -0,0 +1,3 @@
+[submodule "gaming-core"]
+	path = gaming-core
+	url = git@git.hammerle.me:kjhammerle/gaming-core.git

+ 52 - 0
Main.cpp

@@ -0,0 +1,52 @@
+#include "gaming-core/input/Buttons.h"
+#include "gaming-core/utils/Clock.h"
+#include "gaming-core/wrapper/GL.h"
+#include "gaming-core/wrapper/GLEW.h"
+#include "gaming-core/wrapper/GLFW.h"
+#include "gaming-core/wrapper/Window.h"
+#include "gaming-core/wrapper/WindowOptions.h"
+
+void updateSize(const Window& window, Size& size) {
+    Size newSize = window.getSize();
+    if(newSize.width != size.width || newSize.height != size.height) {
+        size = newSize;
+        GL::setViewport(size.width, size.height);
+    }
+}
+
+int main() {
+    if(GLFW::init()) {
+        return 0;
+    }
+
+    Size size(1024, 620);
+    WindowOptions options(4, 0, size, false, "test");
+    Window window(options);
+    if(window.hasError() || GLEW::init()) {
+        return 0;
+    }
+
+    Buttons buttons(window);
+    Clock fps;
+
+    window.show();
+
+    GL::checkAndPrintError("setup error");
+
+    const Clock::Nanos nanosPerTick = 50000000;
+    Clock::Nanos lag = 0;
+    while(!window.shouldClose()) {
+        GL::checkAndPrintError("loop error");
+        updateSize(window, size);
+        // call render tick: static_cast<float> (lag) / nanosPerTick;
+        window.swapBuffers();
+        lag += fps.update();
+        while(lag >= nanosPerTick) {
+            lag -= nanosPerTick;
+            buttons.tick();
+            // call game tick
+        }
+        glfwPollEvents();
+    }
+    return 0;
+}

+ 1 - 0
gaming-core

@@ -0,0 +1 @@
+Subproject commit ec1c9f1198e7e0b81f3134c2068dd6d90cd7f24a

+ 21 - 0
meson.build

@@ -0,0 +1,21 @@
+project('spg project', 'cpp')
+
+sources = ['Main.cpp',
+    'gaming-core/utils/Size.cpp',
+    'gaming-core/utils/Clock.cpp',
+    'gaming-core/wrapper/GLFW.cpp',
+    'gaming-core/wrapper/GL.cpp',
+    'gaming-core/wrapper/GLEW.cpp',
+    'gaming-core/wrapper/Window.cpp',
+    'gaming-core/wrapper/WindowOptions.cpp',
+    'gaming-core/input/Button.cpp',
+    'gaming-core/input/Buttons.cpp']
+
+glewDep = dependency('glew')
+glfwDep = dependency('glfw3')
+
+executable('demo', 
+    sources: sources,
+    dependencies : [glewDep, glfwDep],
+    include_directories : include_directories('gaming-core'),
+    cpp_args: ['-Wall', '-Wextra', '-pedantic', '-Werror'])