From 9a1658e9c7fff431724428ee082ee0e4f17ef42f Mon Sep 17 00:00:00 2001 From: outfrost Date: Tue, 13 Nov 2018 04:12:48 +0100 Subject: [PATCH] Refactor code style (not really naming convention) --- glut_janitor.c | 8 +++---- glut_janitor.h | 4 ++-- level.c | 14 +++++------ level.h | 6 ++--- main.c | 10 ++++---- render.c | 50 +++++++++++++++++++------------------- render.h | 8 +++---- tga.c | 65 +++++++++++++++++++++++++------------------------- tga.h | 36 ++++++++++++++-------------- 9 files changed, 101 insertions(+), 100 deletions(-) diff --git a/glut_janitor.c b/glut_janitor.c index 21b3d3c..0354a5e 100644 --- a/glut_janitor.c +++ b/glut_janitor.c @@ -1,11 +1,11 @@ #include -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; @@ -16,9 +16,9 @@ void resize_stage(GLsizei width, GLsizei height) { // 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); diff --git a/glut_janitor.h b/glut_janitor.h index 680b69c..42080c1 100644 --- a/glut_janitor.h +++ b/glut_janitor.h @@ -3,7 +3,7 @@ #include -void init_render(); -void resize_stage(GLsizei width, GLsizei height); +void initRender(); +void resizeStage(GLsizei width, GLsizei height); #endif diff --git a/level.c b/level.c index 29bee2c..0b344fe 100644 --- a/level.c +++ b/level.c @@ -11,20 +11,20 @@ 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 diff --git a/level.h b/level.h index fe27494..96fcb7a 100644 --- a/level.h +++ b/level.h @@ -10,8 +10,8 @@ typedef GLuint Block; 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 diff --git a/main.c b/main.c index 9f239c6..22e6831 100644 --- a/main.c +++ b/main.c @@ -8,22 +8,22 @@ 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); diff --git a/render.c b/render.c index c9aa5dc..3e29339 100644 --- a/render.c +++ b/render.c @@ -6,45 +6,45 @@ 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; } @@ -54,15 +54,15 @@ void draw_model_recursive(const struct aiScene* model, const struct aiNode* node 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) { @@ -74,6 +74,6 @@ void draw_model_recursive(const struct aiScene* model, const struct aiNode* node } for (int i = 0; i < (*node).mNumChildren; ++i) { - draw_model_recursive(model, (*node).mChildren[i]); + drawModelRecursive(model, (*node).mChildren[i]); } } diff --git a/render.h b/render.h index 86c3c95..6d87ffc 100644 --- a/render.h +++ b/render.h @@ -1,10 +1,10 @@ #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 diff --git a/tga.c b/tga.c index d53586c..11c8b5e 100644 --- a/tga.c +++ b/tga.c @@ -5,63 +5,64 @@ #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; diff --git a/tga.h b/tga.h index 0e4f29f..96be414 100644 --- a/tga.h +++ b/tga.h @@ -5,28 +5,28 @@ #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 -- 2.44.0