forked from LukasBanana/LLGL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android] Made C99 examples Android ready.
- Abstracted asset reading in C99/Texturing example just like in the C++ counterpart. - Added FileUtils.c/.h files to ExampleBase_C99 library. - Added llglSet/GetCanvasTitleUTF8 functions to C99 wrapper. - Added missing declaration of llglGetFormatAttribs() to C99 wrapper. - Link C99 example projects with C++ semantics to avoid issue with "libc++_shared.so" dependency on Android.
- Loading branch information
1 parent
6f269c8
commit e452ff5
Showing
16 changed files
with
373 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* FileUtils.c (C99) | ||
* | ||
* Copyright (c) 2015 Lukas Hermanns. All rights reserved. | ||
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt). | ||
*/ | ||
|
||
#include "FileUtils.h" | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <LLGL-C/Log.h> | ||
|
||
#if defined(ANDROID) || defined(__ANDROID__) | ||
# include "Android/AppUtils.h" | ||
#endif | ||
|
||
|
||
AssetContainer read_asset(const char* name) | ||
{ | ||
AssetContainer asset = { NULL, 0 }; | ||
|
||
char filename[512] = { '\0' }; | ||
#if defined(ANDROID) || defined(__ANDROID__) | ||
if (strncmp(name, "Textures/", 9) == 0) | ||
{ | ||
sprintf(filename, "%s", name + 9); | ||
} | ||
else if (strncmp(name, "Models/", 7) == 0) | ||
{ | ||
sprintf(filename, "%s", name + 7); | ||
} | ||
else | ||
{ | ||
llglLogErrorf("unrecognized base path for asset: %s\n", name); | ||
return asset; | ||
} | ||
#else | ||
sprintf(filename, "../../Shared/Assets/%s", name); | ||
#endif | ||
|
||
// Read file and all of its content | ||
FILE* file = fopen(filename, "rb"); | ||
if (file != NULL) | ||
{ | ||
fseek(file, 0, SEEK_END); | ||
size_t len = (size_t)ftell(file); | ||
fseek(file, 0, SEEK_SET); | ||
asset.data = (char*)malloc(len); | ||
if (asset.data != NULL) | ||
{ | ||
fread(asset.data, 1, len, file); | ||
asset.size = len; | ||
} | ||
else | ||
{ | ||
llglLogErrorf("failed to allocate %u byte(s) to read asset: %s\n", (unsigned)asset.size, name); | ||
} | ||
fclose(file); | ||
} | ||
else | ||
{ | ||
llglLogErrorf("failed to load asset: %s\n", name); | ||
return asset; | ||
} | ||
|
||
return asset; | ||
} | ||
|
||
void free_asset(AssetContainer asset) | ||
{ | ||
if (asset.data != NULL) | ||
{ | ||
free(asset.data); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* FileUtils.h (C99) | ||
* | ||
* Copyright (c) 2015 Lukas Hermanns. All rights reserved. | ||
* Licensed under the terms of the BSD 3-Clause license (see LICENSE.txt). | ||
*/ | ||
|
||
#ifndef LLGLEXAMPLES_C99_FILE_UTILS_H | ||
#define LLGLEXAMPLES_C99_FILE_UTILS_H | ||
|
||
|
||
#include <stdio.h> | ||
#include <stddef.h> | ||
|
||
|
||
typedef struct AssetContainer | ||
{ | ||
char* data; | ||
size_t size; | ||
} | ||
AssetContainer; | ||
|
||
// Reads an asset from the bundle. This is either from the examples/Shared/Assets/ folder or the mobile app package. | ||
AssetContainer read_asset(const char* name); | ||
|
||
// Frees the memory allocated for the specified asset. | ||
void free_asset(AssetContainer asset); | ||
|
||
|
||
#endif | ||
|
Oops, something went wrong.