]> git.lizzy.rs Git - shadowclad.git/blob - render.c
Remove ambiguity in render.*
[shadowclad.git] / render.c
1 #include <GL/glut.h>
2
3 #include "assimp_types.h"
4
5 #include "level.h"
6 #include "render.h"
7 #include "typedefs.h"
8 #include "performance.h"
9
10 const float AXIS_RADIUS = 5.0f;
11
12 void renderScene() {
13         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
14         glLoadIdentity();
15         
16         glEnable(GL_NORMALIZE);
17         glEnable(GL_CULL_FACE);
18         
19         glDisable(GL_LIGHTING);
20         drawAxes();
21         glEnable(GL_LIGHTING);
22         
23         glEnable(GL_LIGHT0);
24         drawSceneRecursive(levelScene, levelScene->mRootNode);
25         glDisable(GL_LIGHT0);
26         
27         glFlush();
28         glutSwapBuffers();
29         frameRendered();
30         glutPostRedisplay();
31 }
32
33 void drawAxes() {
34         point3f xAxisStart = { 0.0f, 0.0f, 0.0f };
35         point3f xAxisEnd = { AXIS_RADIUS, 0.0f, 0.0f };
36         point3f yAxisStart = { 0.0f, 0.0f, 0.0f };
37         point3f yAxisEnd = { 0.0f, AXIS_RADIUS, 0.0f };
38         point3f zAxisStart = { 0.0f, 0.0f, 0.0f };
39         point3f zAxisEnd = { 0.0f, 0.0f, AXIS_RADIUS };
40         
41         glColor3f(1.0f, 0.0f, 0.0f);
42         glBegin(GL_LINES);
43         glVertex3fv(xAxisStart);
44         glVertex3fv(xAxisEnd);
45         glEnd();
46         
47         glColor3f(0.0f, 1.0f, 0.0f);
48         glBegin(GL_LINES);
49         glVertex3fv(yAxisStart);
50         glVertex3fv(yAxisEnd);
51         glEnd();
52         
53         glColor3f(0.0f, 0.0f, 1.0f);
54         glBegin(GL_LINES);
55         glVertex3fv(zAxisStart);
56         glVertex3fv(zAxisEnd);
57         glEnd();
58 }
59
60 void drawSceneRecursive(const AiScene* scene, const AiNode* node) {
61         if (((*scene).mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
62                 return;
63         }
64         
65         for (int i = 0; i < (*node).mNumMeshes; ++i) {
66                 const AiMesh* mesh = (*scene).mMeshes[(*node).mMeshes[i]];
67                 for (int k = 0; k < (*mesh).mNumFaces; ++k) {
68                         const AiFace face = (*mesh).mFaces[k];
69                         
70                         GLenum faceMode;
71                         switch (face.mNumIndices) {
72                                 case 1: faceMode = GL_POINTS; break;
73                                 case 2: faceMode = GL_LINES; break;
74                                 case 3: faceMode = GL_TRIANGLES; break;
75                                 default: faceMode = GL_POLYGON; break;
76                         }
77                         
78                         glBegin(faceMode);
79                         
80                         glColor3f(1.0f, 1.0f, 1.0f);
81                         for (int l = 0; l < face.mNumIndices; ++l) {
82                                 glVertex3fv((const GLfloat*) &(*mesh).mVertices[face.mIndices[l]]);
83                         }
84                         
85                         glEnd();
86                 }
87         }
88         
89         for (int i = 0; i < (*node).mNumChildren; ++i) {
90                 drawSceneRecursive(scene, (*node).mChildren[i]);
91         }
92 }