#include <GL/gl.h>
-void init_render() {
+void initRender() {
// Set the clear colour to black
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
}
-void resize_stage(GLsizei width, GLsizei height) {
+void resizeStage(GLsizei width, GLsizei height) {
if (height == 0)
height = 1;
// Reset the projection matrix
glLoadIdentity();
- GLfloat aspect_ratio = (GLfloat)width / (GLfloat)height;
+ GLfloat aspectRatio = (GLfloat) width / (GLfloat) height;
- glOrtho(-10.0f, 10.0f, -10.0f/aspect_ratio, 10.0f/aspect_ratio, 128.0, -128.0);
+ glOrtho(-10.0, 10.0, -10.0/aspectRatio, 10.0/aspectRatio, 128.0, -128.0);
glRotatef(45.0f, 1.0f, 0.0f, 0.0f);
glRotatef(45.0f, 0.0f, 1.0f, 0.0f);
#include <GL/gl.h>
-void init_render();
-void resize_stage(GLsizei width, GLsizei height);
+void initRender();
+void resizeStage(GLsizei width, GLsizei height);
#endif
const Block BLOCK_EMPTY = 0;
const Block BLOCK_WALL01 = 1;
-TGAimage* level_image = NULL;
+TgaImage* levelImage = NULL;
-Block get_block(GLushort x, GLushort y) {
- if (level_image == NULL) {
+Block getBlock(GLushort x, GLushort y) {
+ if (levelImage == NULL) {
return BLOCK_EMPTY;
}
- return ((Block*) (*level_image).bytes)[x * (*level_image).header.image_width + y];
+ return ((Block*) (*levelImage).bytes)[x * (*levelImage).header.imageWidth + y];
}
-void set_image(TGAimage* image) {
- level_image = image;
+void setImage(TgaImage* image) {
+ levelImage = image;
}
-const struct aiScene* import_model(const char* path) {
+const struct aiScene* importModel(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
const Block BLOCK_EMPTY;
const Block BLOCK_WALL01;
-Block get_block(GLushort x, GLushort y);
-void set_image(TGAimage* image);
-const struct aiScene* import_model(const char* path);
+Block getBlock(GLushort x, GLushort y);
+void setImage(TgaImage* image);
+const struct aiScene* importModel(const char* path);
#endif
int main(int argc, char** argv) {
glutInit(&argc, argv);
- glutInitWindowSize(640, 480);
+ glutInitWindowSize(800, 600);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow(NULL);
glutSetWindowTitle(getGlInfoString());
- glutDisplayFunc(render_scene);
- glutReshapeFunc(resize_stage);
+ glutDisplayFunc(renderScene);
+ glutReshapeFunc(resizeStage);
//glutKeyboardFunc(key_pressed);
//glutMouseFunc(mouse_button_event);
//glutMotionFunc(mouse_motion_event);
- init_render();
+ initRender();
- model = import_model("out/assets/wall01.3ds");
+ model = importModel("out/assets/wall01.3ds");
/*
fprintf(stderr, "*model = ");
print_struct_aiScene(stderr, model);
const float AXIS_RADIUS = 5.0f;
-void render_scene() {
+void renderScene() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
- draw_axes();
- draw_model_recursive(model, (*model).mRootNode);
+ drawAxes();
+ drawModelRecursive(model, (*model).mRootNode);
glFlush();
glutSwapBuffers();
}
-void draw_axes() {
- point3f x_axis_start = { 0.0f, 0.0f, 0.0f };
- point3f x_axis_end = { AXIS_RADIUS, 0.0f, 0.0f };
- point3f y_axis_start = { 0.0f, 0.0f, 0.0f };
- point3f y_axis_end = { 0.0f, AXIS_RADIUS, 0.0f };
- point3f z_axis_start = { 0.0f, 0.0f, 0.0f };
- point3f z_axis_end = { 0.0f, 0.0f, AXIS_RADIUS };
+void drawAxes() {
+ point3f xAxisStart = { 0.0f, 0.0f, 0.0f };
+ point3f xAxisEnd = { AXIS_RADIUS, 0.0f, 0.0f };
+ point3f yAxisStart = { 0.0f, 0.0f, 0.0f };
+ point3f yAxisEnd = { 0.0f, AXIS_RADIUS, 0.0f };
+ point3f zAxisStart = { 0.0f, 0.0f, 0.0f };
+ point3f zAxisEnd = { 0.0f, 0.0f, AXIS_RADIUS };
glColor3f(1.0f, 0.0f, 0.0f);
glBegin(GL_LINES);
- glVertex3fv(x_axis_start);
- glVertex3fv(x_axis_end);
+ glVertex3fv(xAxisStart);
+ glVertex3fv(xAxisEnd);
glEnd();
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_LINES);
- glVertex3fv(y_axis_start);
- glVertex3fv(y_axis_end);
+ glVertex3fv(yAxisStart);
+ glVertex3fv(yAxisEnd);
glEnd();
glColor3f(0.0f, 0.0f, 1.0f);
glBegin(GL_LINES);
- glVertex3fv(z_axis_start);
- glVertex3fv(z_axis_end);
+ glVertex3fv(zAxisStart);
+ glVertex3fv(zAxisEnd);
glEnd();
}
-void draw_model_recursive(const struct aiScene* model, const struct aiNode* node) {
+void drawModelRecursive(const struct aiScene* model, const struct aiNode* node) {
if (((*model).mFlags & AI_SCENE_FLAGS_INCOMPLETE) == AI_SCENE_FLAGS_INCOMPLETE) {
return;
}
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;
+ 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(face_mode);
+ glBegin(faceMode);
glColor3f(1.0f, 1.0f, 1.0f);
for (int l = 0; l < face.mNumIndices; ++l) {
}
for (int i = 0; i < (*node).mNumChildren; ++i) {
- draw_model_recursive(model, (*node).mChildren[i]);
+ drawModelRecursive(model, (*node).mChildren[i]);
}
}
#ifndef RENDER_H_
#define RENDER_H_
-const struct aiScene* model;
+const struct aiScene* model; // TODO remove
-void render_scene();
-void draw_axes();
-void draw_model_recursive(const struct aiScene* model, const struct aiNode* node);
+void renderScene();
+void drawAxes();
+void drawModelRecursive(const struct aiScene* model, const struct aiNode* node);
#endif
#include "tga.h"
-TGAimage* read_tga(const char* path) {
- FILE* tga_file = fopen(path, "rb");
- if (tga_file == NULL) {
+TgaImage* readTga(const char* path) {
+ FILE* tgaFile = fopen(path, "rb");
+ if (tgaFile == NULL) {
return NULL;
}
- TGAheader header;
+ TgaHeader header;
- if (fread(&header, sizeof(TGAheader), 1, tga_file) != 1) {
- fclose(tga_file);
+ if (fread(&header, sizeof(TgaHeader), 1, tgaFile) != 1) {
+ fclose(tgaFile);
return NULL;
}
- GLenum image_format;
- GLint image_components;
+ GLenum imageFormat;
+ GLint imageComponents;
- if (header.image_bpp == 32) {
- image_format = GL_BGRA_EXT;
- image_components = GL_RGBA8;
- }
- else if (header.image_bpp == 24) {
- image_format = GL_BGR_EXT;
- image_components = GL_RGB8;
- }
- else if (header.image_bpp == 8) {
- image_format = GL_LUMINANCE;
- image_components = GL_LUMINANCE8;
- }
- else {
- fclose(tga_file);
- return NULL;
+ switch (header.imageBpp) {
+ case 32:
+ imageFormat = GL_BGRA_EXT;
+ imageComponents = GL_RGBA8;
+ break;
+ case 24:
+ imageFormat = GL_BGR_EXT;
+ imageComponents = GL_RGB8;
+ break;
+ case 8:
+ imageFormat = GL_LUMINANCE;
+ imageComponents = GL_LUMINANCE8;
+ break;
+ default:
+ fclose(tgaFile);
+ return NULL;
}
- unsigned long image_size = header.image_width * header.image_height * (header.image_bpp >> 3);
+ unsigned long imageSize = header.imageWidth * header.imageHeight * (header.imageBpp >> 3);
- GLbyte* bytes = malloc(image_size * sizeof(GLbyte));
+ GLbyte* bytes = malloc(imageSize * sizeof(GLbyte));
if (bytes == NULL) {
- fclose(tga_file);
+ fclose(tgaFile);
return NULL;
}
- if (fread(bytes, image_size, 1, tga_file) != 1) {
+ if (fread(bytes, imageSize, 1, tgaFile) != 1) {
free(bytes);
- fclose(tga_file);
+ fclose(tgaFile);
return NULL;
}
- fclose(tga_file);
+ fclose(tgaFile);
- TGAimage* image = malloc(sizeof(TGAimage));
+ TgaImage* image = malloc(sizeof(TgaImage));
if (image == NULL) {
return NULL;
}
(*image).header = header;
- (*image).image_format = image_format;
- (*image).image_components = image_components;
+ (*image).imageFormat = imageFormat;
+ (*image).imageComponents = imageComponents;
(*image).bytes = bytes;
return image;
#pragma pack(push, 1)
typedef struct {
- GLubyte id_length;
- GLbyte color_map_type;
- GLbyte image_type;
- GLushort color_map_start;
- GLushort color_map_length;
- GLubyte color_map_bpp;
- GLushort x_origin;
- GLushort y_origin;
- GLushort image_width;
- GLushort image_height;
- GLubyte image_bpp;
- GLbyte image_descriptor;
-} TGAheader;
+ GLubyte idLength;
+ GLbyte colorMapType;
+ GLbyte imageType;
+ GLushort colorMapStart;
+ GLushort colorMapLength;
+ GLubyte colorMapBpp;
+ GLushort originX;
+ GLushort originY;
+ GLushort imageWidth;
+ GLushort imageHeight;
+ GLubyte imageBpp;
+ GLbyte imageDescriptor;
+} TgaHeader;
#pragma pack(pop)
typedef struct {
- TGAheader header;
- GLenum image_format;
- GLint image_components;
+ TgaHeader header;
+ GLenum imageFormat;
+ GLint imageComponents;
GLbyte* bytes;
-} TGAimage;
+} TgaImage;
-TGAimage* read_tga(const char* path);
+TgaImage* readTga(const char* path);
#endif