glBindTexture(GL_TEXTURE_2D, 0);
}
+
+ buildLevelFromImage(readTga("out/assets/level01.tga"));
}
void buildLevelFromImage(TgaImage* image) {
+ if (image == NULL) {
+ logError("Null image received, cannot build level");
+ return;
+ }
+
if (image->header.imageBpp != 32) {
logError("Invalid level image format (%d bpp)", image->header.imageBpp);
return;
}
+
+ BlockGrid newGrid = { .width = image->header.imageWidth,
+ .depth = image->header.imageHeight,
+ .blocks = malloc(image->header.imageWidth
+ * image->header.imageHeight
+ * sizeof(Block*)) };
+
+ for (int z = 0; z < newGrid.depth; ++z) {
+ for (int x = 0; x < newGrid.width; ++x) {
+ uint32_t pixelColorARGB = ((uint32_t*) image->bytes)[(z * newGrid.width) + x];
+ Block* block;
+ switch (pixelColorARGB) {
+ case 0xFFFF0000:
+ block = &blockWall01;
+ break;
+ default:
+ block = &blockEmpty;
+ break;
+ }
+ setBlockInGrid(newGrid, x, z, block);
+ }
+ }
+
+ levelGrid = newGrid;
}
const AiScene* importScene(const char* path) {
return grid.blocks[(z * grid.width) + x];
}
+static inline void setBlockInGrid(BlockGrid grid, int x, int z, Block* block) {
+ grid.blocks[(z * grid.width) + x] = block;
+}
+
#endif
GLfloat light0_ambient[] = {0.1f, 0.1f, 0.1f, 1.0f};
GLfloat light0_diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};
GLfloat light0_specular[] = {1.0f, 1.0f, 1.0f, 1.0f};
- GLfloat light0_position[] = {5.0f, 10.0f, 5.0f, 1.0f};
+ GLfloat light0_position[] = {5.0f, 2.0f, 5.0f, 1.0f};
glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
GLfloat aspectRatio = (GLfloat) width / (GLfloat) height;
- glOrtho(-8.0, 8.0, -8.0/aspectRatio, 8.0/aspectRatio, -128.0, 128.0);
+ glOrtho(-8.0, 24.0, -16.0/aspectRatio, 16.0/aspectRatio, -128.0, 128.0);
glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);