]> git.lizzy.rs Git - shadowclad.git/commitdiff
Refactor code style
authoroutfrost <kotlet.bahn@gmail.com>
Tue, 13 Nov 2018 03:12:48 +0000 (04:12 +0100)
committeroutfrost <kotlet.bahn@gmail.com>
Tue, 13 Nov 2018 03:12:48 +0000 (04:12 +0100)
(not really naming convention)

glut_janitor.c
glut_janitor.h
level.c
level.h
main.c
render.c
render.h
tga.c
tga.h

index 21b3d3c01c4bad388e3e3360a06081994cbcac7f..0354a5e48c25f785d16fff52b9ccac534f6a5b56 100644 (file)
@@ -1,11 +1,11 @@
 #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;
        
@@ -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);
index 680b69c04981a57995d324101cd96444ef934554..42080c100383549bd84615e150e3f3cb2536a89c 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <GL/gl.h>
 
-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 29bee2ca62f4b95251a47161639331b5c74194ad..0b344fe1965bea8033b5ce13ba25f3e8ef1a84cc 100644 (file)
--- a/level.c
+++ b/level.c
 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 fe274949add4ffc2b5e31d26ca40c1ba56c92fc5..96fcb7aa47b862de68d1378227bb4bf8e29940a2 100644 (file)
--- 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 9f239c67ae0161e7012a61aab9ecedb29231026b..22e6831d82005afab0dffaa210c9c51a280407d3 100644 (file)
--- 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);
index c9aa5dc1c05996d76cbfd5b7598bee6add17e59d..3e29339d966cf93f600555f1ac76ffeaddfc82fb 100644 (file)
--- 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]);
        }
 }
index 86c3c95b7e32ffafc11db7e8bef36e623b340894..6d87ffca34d12212ee02c4596f442bbd034729ea 100644 (file)
--- 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 d53586c4bdae0673bba282ce2924c4c8170a461c..11c8b5e8ef1518c1c0d9d740aab62ae7801a889e 100644 (file)
--- 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 0e4f29f74abeee837a6940baa03faeb93a51f270..96be414be5e54b36f5b00c915ce01665ad56f04a 100644 (file)
--- 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