diff --git a/Makefile b/Makefile index 26511c5..3bb3f39 100644 --- a/Makefile +++ b/Makefile @@ -17,7 +17,7 @@ CFLAGS = -Wall -Wextra -O3 LDFLAGS = # add library linker commands here (start with -l) -LOADLIBS = -lglfw -lGLEW -lGL +LOADLIBS = -lglfw -lGLEW -lGL -lm # add library search paths here (start with -L) LDLIBS = diff --git a/PlanetMiner b/PlanetMiner new file mode 100755 index 0000000..3e8c029 Binary files /dev/null and b/PlanetMiner differ diff --git a/assets/clover.bmp b/assets/clover.bmp new file mode 100644 index 0000000..b64e710 Binary files /dev/null and b/assets/clover.bmp differ diff --git a/bin/main.o b/bin/main.o index 7dcfd37..f89d254 100644 Binary files a/bin/main.o and b/bin/main.o differ diff --git a/errorcodes.md b/errorcodes.md new file mode 100644 index 0000000..ffebce4 --- /dev/null +++ b/errorcodes.md @@ -0,0 +1,8 @@ +# Error Code Key For Planet Miner + +All error codes in Planet Miner are a 5 or 6 digit sequence. + +## 1XXXX Series + +All error codes in the 1XXXX series have to do with file loading. + diff --git a/src/imagefiles.c b/src/imagefiles.c new file mode 100644 index 0000000..d42409d --- /dev/null +++ b/src/imagefiles.c @@ -0,0 +1,61 @@ +#include "imagefiles.h" +#include +#include + +bmp loadBitmapImage(char* path) +{ + FILE* inFile; + bmp image; + + inFile = fopen(path, "rb"); + if( !inFile ) + { + fprintf(stderr, "Could not open bitmap image file [%s].\n", path); + exit(4); + } + + if( fread(image.header, 1, 54, inFile) != 54 ) + { + fprintf(stderr, "Could not read bitmap image header for [%s].\n", path); + exit(5); + } + + // All bitmap images begin their header with "BM". + // This check just validates this + if( image.header[0] != 'B' || image.header[1] != 'M' ) + { + fprintf(stderr, "Bitmap image at [%s] has improper header.\n", path); + exit(6); + } + + // Cast the char pointer of the header to an int pointer and dereference it to get an int out + image.dataPos = *(int*) &(image.header[0x0A]); // Pointer casting to get the data start position information from the header + image.imageSize = *(int*) &(image.header[0x22]); // Extract image size information from the header + image.width = *(int*) &(image.header[0x12]); + image.height = *(int*) &(image.header[0x16]); + + // Correct for any misformatted data start information + if( image.dataPos == 0 ) + { + image.dataPos = 54; + } + + // Correct for missing image size (in bytes) information + if( image.imageSize == 0 ) + { + image.imageSize = 3*image.width*image.height; + } + + // Allocate the image buffer + image.data = (unsigned char*) malloc(sizeof(char) * imageSize); + + if( image.data == NULL ) + { + fprintf(stderr, "Failed to allocate memory while attempting to open bitmap image at [%s].\n", path); + exit(7); + } + + fread(data, 1, imageSize, inFile); + + fclose(inFile); +} diff --git a/src/imagefiles.h b/src/imagefiles.h new file mode 100644 index 0000000..7e5c827 --- /dev/null +++ b/src/imagefiles.h @@ -0,0 +1,9 @@ +typedef struct bmp { + unsigned char header[54]; + unsigned int dataPos; + unsigned int width, height; + unsigned int imageSize; // width*height*3 + unsigned char* data; +} bmp; + +bmp loadBitmapImage(char* path); diff --git a/src/main.c b/src/main.c index b350be0..fb61c1e 100644 --- a/src/main.c +++ b/src/main.c @@ -165,6 +165,7 @@ int main() printf("Entering main loop\n"); float theta = 0.0f; + float radius = 5.0f; do { @@ -172,11 +173,11 @@ int main() if( glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS ) { - //eye.z -= 0.05f; + radius -= 0.05f; } if( glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS ) { - // eye.z += 0.05f; + radius += 0.05f; } if( glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS ) { @@ -195,11 +196,9 @@ int main() // eye.y -= 0.05f; } - eye.x = (float)sin((double)theta); - eye.z = (float)cos((double)theta); - - // center = glms_vec3_add(eye, direction); + eye.x = radius * (float) sin((double) theta); + eye.z = radius * (float) cos((double) theta); mat4s view = glms_lookat(eye, center, up); mat4s model = glms_mat4_identity(); diff --git a/src/textfiles.c b/src/textfiles.c index de6edf8..7bd8c61 100644 --- a/src/textfiles.c +++ b/src/textfiles.c @@ -16,7 +16,7 @@ char* readTextFile(char* fname) if( inFile == NULL ) { fprintf( stderr, "Failed open file, [%s].\n", fname ); - exit(1); + exit(); } fseek( inFile, 0, SEEK_END ); @@ -34,6 +34,7 @@ char* readTextFile(char* fname) result = fread( fileBuffer, 1, fileLength, inFile ); if( result != fileLength ) { + free( fileBuffer ); fprintf( stderr, "Failed while reading [%s] into the file buffer.\n", fname); exit(3); }