Main.cpp 1.6 KB

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