--- /dev/null
+#ifndef ASSIMP_TYPES_H_
+#define ASSIMP_TYPES_H_
+
+#include <assimp/scene.h>
+
+typedef struct aiScene AiScene;
+typedef struct aiNode AiNode;
+typedef struct aiMesh AiMesh;
+typedef struct aiFace AiFace;
+
+#endif
#include <GL/gl.h>
#include <assimp/cimport.h>
-#include <assimp/scene.h>
-#include <stdlib.h>
#include <stdio.h> // TODO remove
#include "level.h"
-#include "tga.h"
-const Block BLOCK_EMPTY = 0;
-const Block BLOCK_WALL01 = 1;
+const AiScene* levelScene = NULL;
-TgaImage* levelImage = NULL;
+static const Block BLOCK_EMPTY = 0;
+static const Block BLOCK_WALL01 = 0xFF0000FF; // red
-Block getBlock(GLushort x, GLushort y) {
- if (levelImage == NULL) {
- return BLOCK_EMPTY;
- }
- return ((Block*) (*levelImage).bytes)[x * (*levelImage).header.imageWidth + y];
+static const AiScene* blockWall01 = NULL;
+
+static TgaImage* levelImage = NULL;
+
+void initLevel() {
+ blockWall01 = importScene("out/assets/wall01.3ds");
+ levelScene = blockWall01;
}
void setImage(TgaImage* image) {
levelImage = image;
}
-const struct aiScene* importModel(const char* path) {
+const AiScene* importScene(const char* path) {
const struct aiScene* scene = aiImportFile(path, 0u);
if (scene == NULL) {
fprintf(stderr, "Asset import failed at file %s\n", path); // TODO factor logging the heck outta here
#ifndef LEVEL_H_
#define LEVEL_H_
-#include <GL/gl.h>
+#include <stdint.h>
+
+#include "assimp_types.h"
#include "tga.h"
-typedef GLuint Block;
+typedef uint32_t Block;
-const Block BLOCK_EMPTY;
-const Block BLOCK_WALL01;
+const AiScene* levelScene;
-Block getBlock(GLushort x, GLushort y);
+void initLevel();
void setImage(TgaImage* image);
-const struct aiScene* importModel(const char* path);
+const AiScene* importScene(const char* path);
#endif
initRender();
initPerformanceMetering();
+ initLevel();
- model = importModel("out/assets/wall01.3ds");
/*
fprintf(stderr, "*model = ");
print_struct_aiScene(stderr, model);
#include <GL/glut.h>
-#include <assimp/scene.h>
+#include "assimp_types.h"
+
+#include "level.h"
#include "render.h"
#include "typedefs.h"
#include "performance.h"
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
- drawModelRecursive(model, (*model).mRootNode);
+ drawModelRecursive(levelScene, levelScene->mRootNode);
glDisable(GL_LIGHT0);
glFlush();
glEnd();
}
-void drawModelRecursive(const struct aiScene* model, const struct aiNode* node) {
+void drawModelRecursive(const AiScene* model, const 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]];
+ const AiMesh* mesh = (*model).mMeshes[(*node).mMeshes[i]];
for (int k = 0; k < (*mesh).mNumFaces; ++k) {
- const struct aiFace face = (*mesh).mFaces[k];
+ const AiFace face = (*mesh).mFaces[k];
GLenum faceMode;
switch (face.mNumIndices) {