12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- #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;
- }
|