Started error codes, working on bitmap loader
This commit is contained in:
parent
6249576d88
commit
fc47e35256
2
Makefile
2
Makefile
@ -17,7 +17,7 @@ CFLAGS = -Wall -Wextra -O3
|
|||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|
||||||
# add library linker commands here (start with -l)
|
# 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)
|
# add library search paths here (start with -L)
|
||||||
LDLIBS =
|
LDLIBS =
|
||||||
|
BIN
PlanetMiner
Executable file
BIN
PlanetMiner
Executable file
Binary file not shown.
BIN
assets/clover.bmp
Normal file
BIN
assets/clover.bmp
Normal file
Binary file not shown.
After Width: | Height: | Size: 29 KiB |
BIN
bin/main.o
BIN
bin/main.o
Binary file not shown.
8
errorcodes.md
Normal file
8
errorcodes.md
Normal file
@ -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.
|
||||||
|
|
61
src/imagefiles.c
Normal file
61
src/imagefiles.c
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
#include "imagefiles.h"
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
9
src/imagefiles.h
Normal file
9
src/imagefiles.h
Normal file
@ -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);
|
11
src/main.c
11
src/main.c
@ -165,6 +165,7 @@ int main()
|
|||||||
printf("Entering main loop\n");
|
printf("Entering main loop\n");
|
||||||
|
|
||||||
float theta = 0.0f;
|
float theta = 0.0f;
|
||||||
|
float radius = 5.0f;
|
||||||
|
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
@ -172,11 +173,11 @@ int main()
|
|||||||
|
|
||||||
if( glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS )
|
if( glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS )
|
||||||
{
|
{
|
||||||
//eye.z -= 0.05f;
|
radius -= 0.05f;
|
||||||
}
|
}
|
||||||
if( glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS )
|
if( glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS )
|
||||||
{
|
{
|
||||||
// eye.z += 0.05f;
|
radius += 0.05f;
|
||||||
}
|
}
|
||||||
if( glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS )
|
if( glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS )
|
||||||
{
|
{
|
||||||
@ -195,11 +196,9 @@ int main()
|
|||||||
// eye.y -= 0.05f;
|
// eye.y -= 0.05f;
|
||||||
}
|
}
|
||||||
|
|
||||||
eye.x = (float)sin((double)theta);
|
|
||||||
eye.z = (float)cos((double)theta);
|
|
||||||
|
|
||||||
|
|
||||||
// center = glms_vec3_add(eye, direction);
|
// 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 view = glms_lookat(eye, center, up);
|
||||||
mat4s model = glms_mat4_identity();
|
mat4s model = glms_mat4_identity();
|
||||||
|
@ -16,7 +16,7 @@ char* readTextFile(char* fname)
|
|||||||
if( inFile == NULL )
|
if( inFile == NULL )
|
||||||
{
|
{
|
||||||
fprintf( stderr, "Failed open file, [%s].\n", fname );
|
fprintf( stderr, "Failed open file, [%s].\n", fname );
|
||||||
exit(1);
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
fseek( inFile, 0, SEEK_END );
|
fseek( inFile, 0, SEEK_END );
|
||||||
@ -34,6 +34,7 @@ char* readTextFile(char* fname)
|
|||||||
result = fread( fileBuffer, 1, fileLength, inFile );
|
result = fread( fileBuffer, 1, fileLength, inFile );
|
||||||
if( result != fileLength )
|
if( result != fileLength )
|
||||||
{
|
{
|
||||||
|
free( fileBuffer );
|
||||||
fprintf( stderr, "Failed while reading [%s] into the file buffer.\n", fname);
|
fprintf( stderr, "Failed while reading [%s] into the file buffer.\n", fname);
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user