]> git.lizzy.rs Git - shadowclad.git/commitdiff
Render loaded aiScene primitively
authoroutfrost <kotlet.bahn@gmail.com>
Mon, 5 Nov 2018 02:12:32 +0000 (03:12 +0100)
committeroutfrost <kotlet.bahn@gmail.com>
Mon, 5 Nov 2018 02:12:32 +0000 (03:12 +0100)
main.c
render.c
render.h

diff --git a/main.c b/main.c
index cec65b9fef048f4a0603432c7841a9bddd1c0876..7040978d9a08765391cb03d87bb82ae3109f7682 100644 (file)
--- a/main.c
+++ b/main.c
@@ -23,8 +23,14 @@ int main(int argc, char** argv) {
        
        init_render();
        
-       import_model("out/assets/wall01.3ds");
-       
+       model = import_model("out/assets/wall01.3ds");
+       /*
+       fprintf(stderr, "*model = ");
+       print_struct_aiScene(stderr, model);
+       fprintf(stderr, "\n*(*model).mRootNode = ");
+       print_struct_aiNode(stderr, (*model).mRootNode);
+       fprintf(stderr, "\n");
+       */
        glutMainLoop();
        return 0;
 }
index 425fc35517acd5178604e4a691e0ba4469b51d9d..c9aa5dc1c05996d76cbfd5b7598bee6add17e59d 100644 (file)
--- a/render.c
+++ b/render.c
@@ -1,4 +1,5 @@
 #include <GL/glut.h>
+#include <assimp/scene.h>
 
 #include "render.h"
 #include "typedefs.h"
@@ -10,6 +11,7 @@ void render_scene() {
        glLoadIdentity();
        
        draw_axes();
+       draw_model_recursive(model, (*model).mRootNode);
        
        glFlush();
        glutSwapBuffers();
@@ -41,3 +43,37 @@ void draw_axes() {
        glVertex3fv(z_axis_end);
        glEnd();
 }
+
+void draw_model_recursive(const struct aiScene* model, const struct aiNode* node) {
+       if (((*model).mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
+               return;
+       }
+       
+       for (int i = 0; i < (*node).mNumMeshes; ++i) {
+               const struct aiMesh* mesh = (*model).mMeshes[(*node).mMeshes[i]];
+               for (int k = 0; k < (*mesh).mNumFaces; ++k) {
+                       const struct aiFace face = (*mesh).mFaces[k];
+                       
+                       GLenum face_mode;
+                       switch(face.mNumIndices) {
+                               case 1: face_mode = GL_POINTS; break;
+                               case 2: face_mode = GL_LINES; break;
+                               case 3: face_mode = GL_TRIANGLES; break;
+                               default: face_mode = GL_POLYGON; break;
+                       }
+                       
+                       glBegin(face_mode);
+                       
+                       glColor3f(1.0f, 1.0f, 1.0f);
+                       for (int l = 0; l < face.mNumIndices; ++l) {
+                               glVertex3fv((const GLfloat*) &(*mesh).mVertices[face.mIndices[l]]);
+                       }
+                       
+                       glEnd();
+               }
+       }
+       
+       for (int i = 0; i < (*node).mNumChildren; ++i) {
+               draw_model_recursive(model, (*node).mChildren[i]);
+       }
+}
index 659c4b677997e85392445198a06709819a43bad6..86c3c95b7e32ffafc11db7e8bef36e623b340894 100644 (file)
--- a/render.h
+++ b/render.h
@@ -1,7 +1,10 @@
 #ifndef RENDER_H_
 #define RENDER_H_
 
+const struct aiScene* model;
+
 void render_scene();
 void draw_axes();
+void draw_model_recursive(const struct aiScene* model, const struct aiNode* node);
 
 #endif