Main.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. "resources/geometry.gs");
  29. if(shader.hasError()) {
  30. return 0;
  31. }
  32. Buttons buttons(window);
  33. Clock fps;
  34. window.show();
  35. Game game(shader, buttons, size);
  36. GL::checkAndPrintError("setup error");
  37. GL::enableDepthTesting();
  38. const Clock::Nanos nanosPerTick = 50000000;
  39. Clock::Nanos lag = 0;
  40. while(!window.shouldClose()) {
  41. GL::checkAndPrintError("loop error");
  42. updateSize(window, size);
  43. game.render(static_cast<float>(lag) / nanosPerTick);
  44. window.swapBuffers();
  45. GL::clearFramebuffer();
  46. lag += fps.update();
  47. while(lag >= nanosPerTick) {
  48. lag -= nanosPerTick;
  49. buttons.tick();
  50. game.tick();
  51. }
  52. glfwPollEvents();
  53. }
  54. return 0;
  55. }