]> git.lizzy.rs Git - shadowclad.git/commitdiff
Create keybinds for scene and render debug functionalities
authoroutfrost <kotlet.bahn@gmail.com>
Sat, 27 Jun 2020 01:34:57 +0000 (03:34 +0200)
committeroutfrost <kotlet.bahn@gmail.com>
Sat, 27 Jun 2020 01:34:57 +0000 (03:34 +0200)
src/engine/input.c
src/engine/render.c
src/engine/render.h

index 01d3c41173d893059257933fb0de2e57b932144e..b8431434ff2a1423726a99aaef1cdb13e4edb9ba 100644 (file)
@@ -2,15 +2,33 @@
 
 #include <stdbool.h>
 
+#include "render.h"
+
 static void (*keyboardInputCallback) (int, int, int, int);
 
 
 
 void onKeyboardEvent(GLFWwindow* window, int key, int scancode, int action, int mods) {
-       bool handled = false;
+       if (!(mods & GLFW_MOD_CONTROL)) {
+               if (keyboardInputCallback) {
+                       keyboardInputCallback(key, scancode, action, mods);
+               }
+               return;
+       }
 
-       if (!handled && keyboardInputCallback) {
-               keyboardInputCallback(key, scancode, action, mods);
+       switch (key) {
+               case GLFW_KEY_1:
+                       if (action == GLFW_PRESS) {
+                               debugScene = !debugScene;
+                       }
+                       break;
+               case GLFW_KEY_2:
+                       if (action == GLFW_PRESS) {
+                               debugRender = !debugRender;
+                       }
+                       break;
+               default:
+                       break;
        }
 }
 
index d09a1a53d2ce7dc6e2115b787eaaa716fc6e9fb0..c3ddb3a148cda9af5dc98c12fc82b9dfa535d520 100644 (file)
@@ -1,15 +1,12 @@
 #include "render.h"
 
-#include <stdbool.h>
-
 #include "geometry.h"
 #include "performance.h"
 
-#define SCENE_DEBUG_ 0
-#define RENDER_DEBUG_ 0
-
 float viewportAspectRatio = 1.0f;
 const Scene* cameraAnchor;
+bool debugScene = false;
+bool debugRender = false;
 
 static const float AXIS_RADIUS = 5.0f;
 
@@ -69,9 +66,11 @@ static void renderScene(const Scene* scene, const Transform baseTransform) {
        glLoadTransposeMatrixf((const GLfloat*) &transform);
 
        glDisable(GL_LIGHTING);
-#if SCENE_DEBUG_
-       drawAxes();
-#endif // SCENE_DEBUG_
+
+       if (debugScene) {
+               drawAxes();
+       }
+
        glEnable(GL_LIGHTING);
 
        if (scene->solid) {
@@ -128,11 +127,9 @@ static void drawAxes() {
        glEnd();
 }
 
-#if RENDER_DEBUG_
-static GLfloat ab(GLfloat a) {
+static GLfloat absolute(GLfloat a) {
        return a < 0 ? -a : a;
 }
-#endif // RENDER_DEBUG_
 
 static void drawSolid(const Solid* solid) {
        if (solid == NULL) {
@@ -150,8 +147,7 @@ static void drawSolid(const Solid* solid) {
                for (size_t faceIndex = 0; faceIndex < mesh.numFaces; ++faceIndex) {
                        const Face face = mesh.faces[faceIndex];
                        
-#if RENDER_DEBUG_
-                       if (face.normals) {
+                       if (debugRender && face.normals) {
                                glDisable(GL_LIGHTING);
                                glDisable(GL_TEXTURE_2D);
                                glBegin(GL_LINES);
@@ -159,7 +155,7 @@ static void drawSolid(const Solid* solid) {
                                        size_t vertIndex = face.indices[i];
                                        Vector3D vertex = mesh.vertices[vertIndex];
                                        Vector3D normal = face.normals[i];
-                                       glColor3f(ab(normal.x), ab(normal.y), ab(normal.z));
+                                       glColor3f(absolute(normal.x), absolute(normal.y), absolute(normal.z));
                                        glVertex3f(vertex.x, vertex.y, vertex.z);
                                        glVertex3f(vertex.x + normal.x, vertex.y + normal.y, vertex.z + normal.z);
                                }
@@ -167,7 +163,6 @@ static void drawSolid(const Solid* solid) {
                                glEnable(GL_TEXTURE_2D);
                                glEnable(GL_LIGHTING);
                        }
-#endif // RENDER_DEBUG_
                        
                        GLenum faceMode;
                        switch (face.numIndices) {
index f3be0a2fd4fc7cb2c10973543896395b41e64dd2..f1b40a1061c45b5690d8d6731540991950e6f9da 100644 (file)
@@ -1,12 +1,15 @@
 #ifndef ENGINE_RENDER_H_
 #define ENGINE_RENDER_H_
 
+#include <stdbool.h>
 #include <GLFW/glfw3.h>
 
 #include "scene.h"
 
 extern float viewportAspectRatio;
 extern const Scene* cameraAnchor;
+extern bool debugScene;
+extern bool debugRender;
 
 void initRender();
 void renderFrame(GLFWwindow* window);