123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- #include <iostream>
- #include "rendering/wrapper/GLFWWrapper.h"
- #include "rendering/wrapper/GLWrapper.h"
- #include "rendering/WindowSize.h"
- #include "rendering/wrapper/Window.h"
- #include "utils/Clock.h"
- #include "rendering/wrapper/Shader.h"
- #include "input/Controller.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;
- }
- void initCallbacks(Window& w, WindowSize& size, Controller& controller) {
- static WindowSize& cSize = size;
- static Controller& cController = controller;
- (void) cController;
- w.setFramebufferSizeCallback([](GLFWwindow*, int newWidth, int newHeight) {
- glViewport(0, 0, newWidth, newHeight);
- cSize.width = newWidth;
- cSize.height = newHeight;
- });
- /*w.setKeyCallback([](GLFWwindow*, int key, int, int action, int) {
- if(action == GLFW_PRESS) {
- cControl.keys.press(key);
- } else if(action == GLFW_RELEASE) {
- cControl.keys.release(key);
- }
- });*/
- }
- int main() {
- if(GLFWWrapper::hasError()) {
- return 0;
- }
-
- WindowSize size(800, 480);
- Window window(size, "Test");
- 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);
-
- Controller controller;
- Clock fps;
- Clock tps;
-
- static Game game(controller, fps, tps);
-
- initCallbacks(window, size, controller);
- window.show();
-
- const u64 nanosPerTick = 50000000;
- u64 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.translate(-1.0f, 1.0f);
- view.scale(2.0f / size.width, -2.0f / size.height);
- shader.setMatrix("view", view.getValues());
-
- game.render((float) lag / nanosPerTick, renderer);
- window.swapBuffers();
-
- glfwPollEvents();
- }
-
- /*for(int i = GLFW_JOYSTICK_1; i <= GLFW_JOYSTICK_LAST; i++) {
- String s("Joystick ");
- int present = glfwJoystickPresent(i);
- s.append(i).append(": ").append(present);
- if(present) {
- s.append(" ");
- int count = 0;
- const u8* buttons = glfwGetJoystickButtons(i, &count);
- for(int k = 0; k < count; k++) {
- s.append(buttons[k] ? '1' : '0');
- }
- }
- r.drawString(0, i * 10 + 10, s);
- }*/
- return 0;
- }
|