1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- #include <iostream>
- #include <bits/getopt_core.h>
- #include "rendering/wrapper/GLFW.h"
- #include "rendering/wrapper/GLWrapper.h"
- #include "rendering/wrapper/Window.h"
- #include "rendering/Options.h"
- #include "gaming-core/utils/Clock.h"
- #include "rendering/wrapper/Shader.h"
- #include "rendering/Renderer.h"
- #include "Game.h"
- bool initGLEW() {
- GLenum err = glewInit();
- if(err != GLEW_OK) {
- std::cout << "could not initialize GLEW: " << glewGetErrorString(err) << "\n";
- return true;
- }
- std::cout << "using GLEW " << glewGetString(GLEW_VERSION) << "\n";
- return false;
- }
- bool parseArgs(int argAmount, char* const* args, Options& options) {
- while(true) {
- switch(getopt(argAmount, args, "fv")) {
- case '?':
- return true;
- case 'f':
- options.fullscreen = true;
- break;
- case 'v':
- options.vsync = true;
- break;
- case -1:
- return false;
- }
- }
- }
- int main(int argAmount, char* const* args) {
- Options options("Pigine");
- if(parseArgs(argAmount, args, options)) {
- return 0;
- }
- if(GLFW::init()) {
- return 0;
- }
- Size size(800, 480);
- Controller controller;
- Window window(size, controller, options);
- if(window.hasError() || initGLEW()) {
- return 0;
- }
- Shader shader("resources/shader/vertex.vs", "resources/shader/fragment.fs");
- if(shader.hasError()) {
- return 0;
- }
- Renderer renderer(size, shader);
- Clock fps;
- Clock tps;
- static Game game(controller, fps, tps);
- window.show();
- const Clock::Nanos nanosPerTick = 10'000'000;
- Clock::Nanos lag = 0;
- while(!window.shouldClose() && game.isRunning()) {
- GLWrapper::checkAndPrintError("GL-Error");
- lag += fps.update();
- while(lag >= nanosPerTick) {
- lag -= nanosPerTick;
- tps.update();
- controller.tick();
- game.tick();
- }
- Matrix view;
- view.scale(Vector3(2.0f / size.width, -2.0f / size.height, 1.0f));
- view.translate(Vector3(-1.0f, 1.0f, 0.0f));
- shader.setMatrix("view", view.getValues());
- game.render(static_cast<float> (lag) / nanosPerTick, renderer);
- window.swapBuffers();
- glfwPollEvents();
- }
- return 0;
- }
|