#include #include #include "rms.hpp" APP_CONTEXT *AppContext=nullptr; void OnWindowResize(GLFWwindow* window, int width, int height){ AppContext->renderer.AjustViewport(width,height); } void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) { if (key == GLFW_KEY_R && action == GLFW_PRESS) AppContext->renderer.RefreshShader(); } int main(int argc, char *argv[]) { GLFWwindow* window; /* Initialize the library */ if (!glfwInit()) return -1; /* Create a windowed mode window and its OpenGL context */ window = glfwCreateWindow(WIDTH, HEIGHT, "SFML/OpenGL Ray Marching", NULL, NULL); if (!window) { glfwTerminate(); return -1; } /* Make the window's context current */ glfwMakeContextCurrent(window); // Init Renderer/OpenGL APP_CONTEXT InitContext={ Renderer(WIDTH,HEIGHT,"main.frag"), HUD(window) }; AppContext=&InitContext; InitContext.renderer.RefreshShader(); glfwSetWindowSizeCallback(window, OnWindowResize); glfwSetKeyCallback(window, key_callback); /* Loop until the user closes the window */ double InitTime = glfwGetTime(); double LastTime = InitTime; while (!glfwWindowShouldClose(window)) { double CurrentTime = glfwGetTime(); AppContext->hud.m_Context->time=CurrentTime-InitTime; /* Render here */ glClear(GL_COLOR_BUFFER_BIT); if(CurrentTime-LastTime >= 1){ AppContext->hud.m_Context->fps=AppContext->hud.m_Context->fps_frame_counter; AppContext->hud.m_Context->fps_frame_counter=0; LastTime=CurrentTime; } AppContext->renderer.Render(); AppContext->hud.Render(); /* Swap front and back buffers */ glfwSwapBuffers(window); /* Poll for and process events */ glfwPollEvents(); AppContext->hud.m_Context->fps_frame_counter++; } glfwTerminate(); return 0; }