Main.cpp 1.9 KB

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