]> git.lizzy.rs Git - shadowclad.git/blobdiff - src/engine/render.c
Add minimal, wonky scene tree system
[shadowclad.git] / src / engine / render.c
index 68385b07919af5a40cf14e00ece7d3c5b3b57034..99586f5147b319eebac0af3d6b730c2abab4db6d 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "geometry.h"
 #include "performance.h"
+#include "scene.h"
 
 const float AXIS_RADIUS = 5.0f;
 
@@ -18,8 +19,6 @@ static void drawSolid(const Solid* solid);
 
 float viewportAspectRatio = 1.0f;
 
-
-
 void initRender() {
        glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        
@@ -38,6 +37,55 @@ void initRender() {
        glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.005f);
 }
 
+
+
+void renderSceneNew(const Scene*);
+
+void renderFrame() {
+       glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+       
+       glEnable(GL_NORMALIZE);
+       glEnable(GL_CULL_FACE);
+       glEnable(GL_DEPTH_TEST);
+       
+       setupCamera();
+       moveCameraTo(playerPos);
+       
+       renderSceneNew(currentScene);
+       
+       glFlush();
+       glutSwapBuffers();
+       frameRendered();
+       glutPostRedisplay();
+}
+
+void renderSceneNew(const Scene* scene) {
+       if (!scene) {
+               return;
+       }
+
+       glMatrixMode(GL_MODELVIEW);
+       glLoadMatrixf((const GLfloat*) &scene->transform);
+
+       glDisable(GL_LIGHTING);
+       drawAxes();
+       glEnable(GL_LIGHTING);
+
+       if (scene->solid) {
+               glEnable(GL_LIGHT0);
+               glEnable(GL_TEXTURE_2D);
+               drawSolid(scene->solid);
+               glDisable(GL_TEXTURE_2D);
+               glDisable(GL_LIGHT0);
+       }
+
+       for (size_t i = 0; i < scene->numChildren; ++i) {
+               renderSceneNew(scene->children[i]);
+       }
+}
+
+
+
 void renderScene() {
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);