Main.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "gaming-core/input/Buttons.h"
  2. #include "gaming-core/utils/Clock.h"
  3. #include "gaming-core/wrapper/GL.h"
  4. #include "gaming-core/wrapper/GLEW.h"
  5. #include "gaming-core/wrapper/GLFW.h"
  6. #include "gaming-core/wrapper/Window.h"
  7. #include "gaming-core/wrapper/WindowOptions.h"
  8. void updateSize(const Window& window, Size& size) {
  9. Size newSize = window.getSize();
  10. if(newSize.width != size.width || newSize.height != size.height) {
  11. size = newSize;
  12. GL::setViewport(size.width, size.height);
  13. }
  14. }
  15. int main() {
  16. if(GLFW::init()) {
  17. return 0;
  18. }
  19. Size size(1024, 620);
  20. WindowOptions options(4, 0, size, false, "test");
  21. Window window(options);
  22. if(window.hasError() || GLEW::init()) {
  23. return 0;
  24. }
  25. Buttons buttons(window);
  26. Clock fps;
  27. window.show();
  28. GL::checkAndPrintError("setup error");
  29. const Clock::Nanos nanosPerTick = 50000000;
  30. Clock::Nanos lag = 0;
  31. while(!window.shouldClose()) {
  32. GL::checkAndPrintError("loop error");
  33. updateSize(window, size);
  34. // call render tick: static_cast<float> (lag) / nanosPerTick;
  35. window.swapBuffers();
  36. lag += fps.update();
  37. while(lag >= nanosPerTick) {
  38. lag -= nanosPerTick;
  39. buttons.tick();
  40. // call game tick
  41. }
  42. glfwPollEvents();
  43. }
  44. return 0;
  45. }