added pause and debug mode
This commit is contained in:
parent
f1c722afe5
commit
b3bd9857a4
1 changed files with 59 additions and 15 deletions
74
main.c
74
main.c
|
@ -1,23 +1,64 @@
|
||||||
|
#define APPNAMEVERSION "EnginPasTangible (alpha 0.2.4)"
|
||||||
#include "./Libraries/glad/glad.h"
|
#include "./Libraries/glad/glad.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include "./Libraries/GLFW/glfw3.h"
|
#include "./Libraries/GLFW/glfw3.h"
|
||||||
#define STB_IMAGE_IMPLEMENTATION
|
#define STB_IMAGE_IMPLEMENTATION
|
||||||
#include "./Libraries/stb/stb_image.h"
|
#include "./Libraries/stb/stb_image.h"
|
||||||
#include "headers/shader.h"
|
#include "headers/shader.h"
|
||||||
#define FULLSCREEN 0
|
#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;
|
GLuint screenWidth = 720, screenHeight = 480;
|
||||||
const GLFWvidmode* mode;
|
const GLFWvidmode* mode;
|
||||||
GLFWwindow* window;
|
GLFWwindow* window;
|
||||||
|
|
||||||
|
bool pause;
|
||||||
|
|
||||||
void setupVAO();
|
void setupVAO();
|
||||||
//GLuint getTextureHandle(char* path);
|
//GLuint getTextureHandle(char* path);
|
||||||
unsigned int VAO;
|
unsigned int VAO;
|
||||||
|
|
||||||
float currentTime, deltaTime, lastFrame,startTime;
|
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 (){
|
int main (){
|
||||||
|
|
||||||
// Window setup
|
// Window setup
|
||||||
|
@ -31,8 +72,8 @@ int main (){
|
||||||
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);//#####
|
glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);//#####
|
||||||
//glfwWindowHint(GLFW_DECORATED,GL_FALSE);
|
//glfwWindowHint(GLFW_DECORATED,GL_FALSE);
|
||||||
//glfwWindowHint(GLFW_CONTEXT_NO_ERROR,GL_FALSE);
|
//glfwWindowHint(GLFW_CONTEXT_NO_ERROR,GL_FALSE);
|
||||||
|
pause = false;
|
||||||
window = glfwCreateWindow(screenWidth, screenHeight, "EnginPasTangible (alpha 0.2.2)", NULL, NULL);
|
window = glfwCreateWindow(screenWidth, screenHeight, APPNAMEVERSION, NULL, NULL);
|
||||||
|
|
||||||
if (window == NULL)
|
if (window == NULL)
|
||||||
{
|
{
|
||||||
|
@ -68,11 +109,9 @@ int main (){
|
||||||
// for alpha (opacity)
|
// for alpha (opacity)
|
||||||
//glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
//glEnable (GL_BLEND); glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
// GLFWimage images[2];
|
glfwSetKeyCallback(window, key_callback);
|
||||||
// images[0] = load_icon("assets/enginpastangible.png");
|
glfwSetCursorPosCallback(window, cursor_position_callback);
|
||||||
// images[1] = load_icon("assets/icon.png");
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||||
|
|
||||||
// glfwSetWindowIcon(window, 2, images);
|
|
||||||
|
|
||||||
GLFWimage images[1];
|
GLFWimage images[1];
|
||||||
images[0].pixels = stbi_load("./assets/icon.png", &images[0].width, &images[0].height, 0, 4); //rgba channels
|
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();
|
startTime = glfwGetTime();
|
||||||
while (!glfwWindowShouldClose(window))
|
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();
|
currentTime = glfwGetTime();
|
||||||
deltaTime = currentTime - lastFrame;
|
deltaTime = currentTime - lastFrame;
|
||||||
lastFrame = currentTime;
|
lastFrame = currentTime;
|
||||||
gcvt(1/deltaTime,4,FPS);
|
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);
|
glfwGetWindowSize(window, &window_width, &window_height);
|
||||||
glViewport(0, 0, 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);
|
glUniform3f(glGetUniformLocation(quad_shader, "iCamDir"), camDirX,camDirY,camDirZ);
|
||||||
|
|
||||||
// glBindVertexArray(0); // no need to unbind it every time
|
// 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
|
// 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