+static void renderBlockGrid(const BlockGrid grid) {
+ glMatrixMode(GL_MODELVIEW);
+ for (int z = 0; z < grid.depth; ++z) {
+ glLoadIdentity();
+ glTranslatef(0.0f, 0.0f, z * BLOCKGRID_CELL_SIZE);
+ for (int x = 0; x < grid.width; ++x) {
+ drawBlock(getBlockFromGrid(grid, x, z));
+ glTranslatef(BLOCKGRID_CELL_SIZE, 0.0f, 0.0f);
+ }
+ }
+ glLoadIdentity();
+}
+
+static void drawBlock(const Block* block) {
+ if (block->sceneData == NULL) {
+ return;
+ }
+
+ glColor3f(0.5f, 1.0f, 0.0f);
+
+ for (int i = 0; i < block->sceneData->mNumMeshes; ++i) {
+ glBindTexture(GL_TEXTURE_2D, block->textureIds[i]);
+ const AiMesh* mesh = block->sceneData->mMeshes[i];
+ bool hasNormals = mesh->mNormals != NULL;
+ bool hasTextureCoords = mesh->mTextureCoords[0] != NULL;
+
+ for (int k = 0; k < mesh->mNumFaces; ++k) {
+ const AiFace face = mesh->mFaces[k];
+
+ GLenum faceMode;
+ switch (face.mNumIndices) {
+ case 1: faceMode = GL_POINTS; break;
+ case 2: faceMode = GL_LINES; break;
+ case 3: faceMode = GL_TRIANGLES; break;
+ default: faceMode = GL_POLYGON; break;
+ }
+
+ glBegin(faceMode);
+
+ for (int l = 0; l < face.mNumIndices; ++l) {
+ unsigned int vertexIndex = face.mIndices[l];
+ if (hasNormals) {
+ if (hasTextureCoords) {
+ AiVector3D coords = mesh->mTextureCoords[0][vertexIndex];
+ glTexCoord2f(coords.x, coords.y);
+ }
+ glNormal3fv(&mesh->mNormals[vertexIndex].x);
+ }
+ glVertex3fv((const GLfloat*) &mesh->mVertices[vertexIndex]);
+ }
+
+ glEnd();
+ }
+ }
+ glBindTexture(GL_TEXTURE_2D, 0);
+}
+