From b3bd9857a4e69e73fe75d5b47da1292afa9d79a8 Mon Sep 17 00:00:00 2001 From: MagicTINTIN Date: Tue, 14 Feb 2023 22:13:27 +0100 Subject: [PATCH] added pause and debug mode --- main.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 59 insertions(+), 15 deletions(-) diff --git a/main.c b/main.c index 17ed1a2..aabe447 100644 --- a/main.c +++ b/main.c @@ -1,23 +1,64 @@ +#define APPNAMEVERSION "EnginPasTangible (alpha 0.2.4)" #include "./Libraries/glad/glad.h" #include #include - +#include #include "./Libraries/GLFW/glfw3.h" #define STB_IMAGE_IMPLEMENTATION #include "./Libraries/stb/stb_image.h" #include "headers/shader.h" #define FULLSCREEN 0 +/* ## DEBUG MODE ## + * 0 for all + * 1 for nothing + * 2 for FPS + * 3 for cursor position + * + * For instance if you want fps and position set the value to 2*3=6 + */ +#define DEBUG_MODE 1 GLuint screenWidth = 720, screenHeight = 480; const GLFWvidmode* mode; GLFWwindow* window; +bool pause; + void setupVAO(); //GLuint getTextureHandle(char* path); unsigned int VAO; float currentTime, deltaTime, lastFrame,startTime; +static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) +{ + if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS) + { + //glfwSetWindowShouldClose(window, GLFW_TRUE); + pause=!pause; + printf(pause ? "En pause\n" : "En fonctionnement\n"); + if (pause) + { + glfwSetWindowTitle(window, "EnginPasTangible (En pause)"); + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL); + } + else + { + glfwSetWindowTitle(window, APPNAMEVERSION); + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); + } + } + /*if (key == GLFW_KEY_SPACE && action == GLFW_PRESS) + glfwSetCursorPos(window, 640/2, 480/2);*/ +} + + +static void cursor_position_callback(GLFWwindow* window, double xpos, double ypos) +{ + if (DEBUG_MODE % 3 == 0) + printf("x:%f | y:%f\n",xpos, ypos); +} + int main (){ // Window setup @@ -31,8 +72,8 @@ int main (){ glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);//##### //glfwWindowHint(GLFW_DECORATED,GL_FALSE); //glfwWindowHint(GLFW_CONTEXT_NO_ERROR,GL_FALSE); - - window = glfwCreateWindow(screenWidth, screenHeight, "EnginPasTangible (alpha 0.2.2)", NULL, NULL); + pause = false; + window = glfwCreateWindow(screenWidth, screenHeight, APPNAMEVERSION, NULL, NULL); if (window == NULL) { @@ -68,11 +109,9 @@ int main (){ // for alpha (opacity) //glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - // GLFWimage images[2]; - // images[0] = load_icon("assets/enginpastangible.png"); - // images[1] = load_icon("assets/icon.png"); - - // glfwSetWindowIcon(window, 2, images); + glfwSetKeyCallback(window, key_callback); + glfwSetCursorPosCallback(window, cursor_position_callback); + glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED); GLFWimage images[1]; images[0].pixels = stbi_load("./assets/icon.png", &images[0].width, &images[0].height, 0, 4); //rgba channels @@ -85,12 +124,23 @@ int main (){ startTime = glfwGetTime(); while (!glfwWindowShouldClose(window)) { + // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) + // ------------------------------------------------------------------------------- + glfwSwapBuffers(window); + glfwPollEvents(); + if (pause) + { + glClearColor(.1f, .2f, 0.3f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + continue; + } currentTime = glfwGetTime(); deltaTime = currentTime - lastFrame; lastFrame = currentTime; gcvt(1/deltaTime,4,FPS); - printf("FPS : %s\n",FPS); + if (DEBUG_MODE % 2 == 0) + printf("FPS : %s\n",FPS); glfwGetWindowSize(window, &window_width, &window_height); glViewport(0, 0, window_width, window_height); @@ -107,12 +157,6 @@ int main (){ glUniform3f(glGetUniformLocation(quad_shader, "iCamDir"), camDirX,camDirY,camDirZ); // glBindVertexArray(0); // no need to unbind it every time - - // glfw: swap buffers and poll IO events (keys pressed/released, mouse moved etc.) - // ------------------------------------------------------------------------------- - glfwSwapBuffers(window); - glfwPollEvents(); - } // Optional cleaning up bc OS will likely do it for us, but is a good practice. Note that shaders are deleted in shader.h