Working on C tooling
This commit is contained in:
@ -32,6 +32,29 @@ char * assetStringLoad(char *assetName) {
|
||||
return str;
|
||||
}
|
||||
|
||||
uint8_t * assetRawLoad(char *assetName) {
|
||||
// Open a buffer.
|
||||
assetbuffer_t *fptr = assetBufferOpen(assetName);
|
||||
if(fptr == NULL) return NULL;
|
||||
|
||||
// Read the count of bytes in the file
|
||||
fseek(fptr, 0, SEEK_END);// Seek to the end
|
||||
size_t length = ftell(fptr);// Get our current position (the end)
|
||||
fseek(fptr, 0, SEEK_SET);// Reset the seek
|
||||
|
||||
// Create the string buffer
|
||||
uint8_t *str = malloc(length);
|
||||
if(str == NULL) {
|
||||
assetBufferClose(fptr);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Read and seal the string.
|
||||
fread(str, 1, length, fptr);// Read all the bytes
|
||||
assetBufferClose(fptr); // Close the buffer.
|
||||
return str;
|
||||
}
|
||||
|
||||
assetbuffer_t * assetBufferOpen(char *assetName) {
|
||||
// Get the directory based on the raw input by creating a new string.
|
||||
FILE *fptr;
|
||||
|
@ -27,6 +27,8 @@ typedef FILE assetbuffer_t;
|
||||
*/
|
||||
char * assetStringLoad(char *assetName);
|
||||
|
||||
uint8_t * assetRawLoad(char *assetName);
|
||||
|
||||
/**
|
||||
* Platform-centric method to open a file buffer to an asset.
|
||||
* @param assetName The asset name to open a buffer for.
|
||||
|
@ -11,9 +11,6 @@ bool sandboxGameInit(sandboxgame_t *game) {
|
||||
quadInit(&game->quad, 0, 0,0,0,0, 500,500,1,1);
|
||||
|
||||
assetManagerInit(&game->manager);
|
||||
assetManagerLoadTexture(&game->manager, &game->texture,
|
||||
"textures/test_texture.png"
|
||||
);
|
||||
assetManagerLoadFont(&game->manager, &game->font,
|
||||
"fonts/opensans/OpenSans-Regular.ttf"
|
||||
);
|
||||
@ -24,6 +21,10 @@ bool sandboxGameInit(sandboxgame_t *game) {
|
||||
|
||||
assetManagerStart(&game->manager);
|
||||
|
||||
pixel_t *data = (pixel_t *)assetRawLoad("out/test.texture");
|
||||
textureInit(&game->texture, 4360, 1920, (pixel_t *)data);
|
||||
free(data);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user