added pause and debug mode
This commit is contained in:
parent
f1c722afe5
commit
b3bd9857a4
1 changed files with 59 additions and 15 deletions
72
main.c
72
main.c
|
@ -1,23 +1,64 @@
|
|||
#define APPNAMEVERSION "EnginPasTangible (alpha 0.2.4)"
|
||||
#include "./Libraries/glad/glad.h"
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#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,11 +124,22 @@ 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);
|
||||
if (DEBUG_MODE % 2 == 0)
|
||||
printf("FPS : %s\n",FPS);
|
||||
|
||||
glfwGetWindowSize(window, &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
|
||||
|
|
Loading…
Reference in a new issue