Update C sources
This commit is contained in:
parent
f2b720ea98
commit
0d9012a519
4 changed files with 21 additions and 16 deletions
|
@ -65,9 +65,9 @@
|
||||||
#else
|
#else
|
||||||
#include "AL/al.h" // OpenAL basic header
|
#include "AL/al.h" // OpenAL basic header
|
||||||
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
#include "AL/alc.h" // OpenAL context header (like OpenGL, OpenAL requires a context to work)
|
||||||
|
//#include "AL/alext.h" // OpenAL extensions header, required for AL_EXT_FLOAT32 and AL_EXT_MCFORMATS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//#include "AL/alext.h" // OpenAL extensions header, required for AL_EXT_FLOAT32 and AL_EXT_MCFORMATS
|
|
||||||
// OpenAL extension: AL_EXT_FLOAT32 - Support for 32bit float samples
|
// OpenAL extension: AL_EXT_FLOAT32 - Support for 32bit float samples
|
||||||
// OpenAL extension: AL_EXT_MCFORMATS - Support for multi-channel formats (Quad, 5.1, 6.1, 7.1)
|
// OpenAL extension: AL_EXT_MCFORMATS - Support for multi-channel formats (Quad, 5.1, 6.1, 7.1)
|
||||||
|
|
||||||
|
@ -1119,7 +1119,7 @@ static Wave LoadWAV(const char *fileName)
|
||||||
wave.data = malloc(wavData.subChunkSize);
|
wave.data = malloc(wavData.subChunkSize);
|
||||||
|
|
||||||
// Read in the sound data into the soundData variable
|
// Read in the sound data into the soundData variable
|
||||||
fread(wave.data, 1, wavData.subChunkSize, wavFile);
|
fread(wave.data, wavData.subChunkSize, 1, wavFile);
|
||||||
|
|
||||||
// Store wave parameters
|
// Store wave parameters
|
||||||
wave.sampleRate = wavFormat.sampleRate;
|
wave.sampleRate = wavFormat.sampleRate;
|
||||||
|
|
|
@ -1025,14 +1025,14 @@ int StorageLoadValue(int position)
|
||||||
{
|
{
|
||||||
// Get file size
|
// Get file size
|
||||||
fseek(storageFile, 0, SEEK_END);
|
fseek(storageFile, 0, SEEK_END);
|
||||||
int fileSize = ftell(storageFile); // Size in bytes
|
int fileSize = ftell(storageFile); // Size in bytes
|
||||||
rewind(storageFile);
|
rewind(storageFile);
|
||||||
|
|
||||||
if (fileSize < (position*4)) TraceLog(WARNING, "Storage position could not be found");
|
if (fileSize < (position*4)) TraceLog(WARNING, "Storage position could not be found");
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
fseek(storageFile, (position*4), SEEK_SET);
|
fseek(storageFile, (position*4), SEEK_SET);
|
||||||
fread(&value, 1, 4, storageFile);
|
fread(&value, 4, 1, storageFile); // Read 1 element of 4 bytes size
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(storageFile);
|
fclose(storageFile);
|
||||||
|
|
|
@ -928,6 +928,8 @@ static SpriteFont LoadBMFont(const char *fileName)
|
||||||
// TODO: Review texture packing method and generation (use oversampling)
|
// TODO: Review texture packing method and generation (use oversampling)
|
||||||
static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars)
|
static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars)
|
||||||
{
|
{
|
||||||
|
#define MAX_TTF_SIZE 16 // Maximum ttf file size in MB
|
||||||
|
|
||||||
// NOTE: Font texture size is predicted (being as much conservative as possible)
|
// NOTE: Font texture size is predicted (being as much conservative as possible)
|
||||||
// Predictive method consist of supposing same number of chars by line-column (sqrtf)
|
// Predictive method consist of supposing same number of chars by line-column (sqrtf)
|
||||||
// and a maximum character width of 3/4 of fontSize... it worked ok with all my tests...
|
// and a maximum character width of 3/4 of fontSize... it worked ok with all my tests...
|
||||||
|
@ -938,7 +940,7 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
|
||||||
|
|
||||||
TraceLog(INFO, "TTF spritefont loading: Predicted texture size: %ix%i", textureSize, textureSize);
|
TraceLog(INFO, "TTF spritefont loading: Predicted texture size: %ix%i", textureSize, textureSize);
|
||||||
|
|
||||||
unsigned char *ttfBuffer = (unsigned char *)malloc(1 << 25);
|
unsigned char *ttfBuffer = (unsigned char *)malloc(MAX_TTF_SIZE*1024*1024);
|
||||||
unsigned char *dataBitmap = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)); // One channel bitmap returned!
|
unsigned char *dataBitmap = (unsigned char *)malloc(textureSize*textureSize*sizeof(unsigned char)); // One channel bitmap returned!
|
||||||
stbtt_bakedchar *charData = (stbtt_bakedchar *)malloc(sizeof(stbtt_bakedchar)*charsCount);
|
stbtt_bakedchar *charData = (stbtt_bakedchar *)malloc(sizeof(stbtt_bakedchar)*charsCount);
|
||||||
|
|
||||||
|
@ -952,7 +954,8 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
fread(ttfBuffer, 1, 1 << 25, ttfFile);
|
// NOTE: We try reading up to 16 MB of elements of 1 byte
|
||||||
|
fread(ttfBuffer, 1, MAX_TTF_SIZE*1024*1024, ttfFile);
|
||||||
|
|
||||||
if (fontChars[0] != 32) TraceLog(WARNING, "TTF spritefont loading: first character is not SPACE(32) character");
|
if (fontChars[0] != 32) TraceLog(WARNING, "TTF spritefont loading: first character is not SPACE(32) character");
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,9 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int
|
||||||
default: TraceLog(WARNING, "Image format not suported"); break;
|
default: TraceLog(WARNING, "Image format not suported"); break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bytes = fread(image.data, size, 1, rawFile);
|
// NOTE: fread() returns num read elements instead of bytes,
|
||||||
|
// to get bytes we need to read (1 byte size, elements) instead of (x byte size, 1 element)
|
||||||
|
int bytes = fread(image.data, 1, size, rawFile);
|
||||||
|
|
||||||
// Check if data has been read successfully
|
// Check if data has been read successfully
|
||||||
if (bytes < size)
|
if (bytes < size)
|
||||||
|
@ -1591,7 +1593,7 @@ static Image LoadDDS(const char *fileName)
|
||||||
// Verify the type of file
|
// Verify the type of file
|
||||||
char filecode[4];
|
char filecode[4];
|
||||||
|
|
||||||
fread(filecode, 1, 4, ddsFile);
|
fread(filecode, 4, 1, ddsFile);
|
||||||
|
|
||||||
if (strncmp(filecode, "DDS ", 4) != 0)
|
if (strncmp(filecode, "DDS ", 4) != 0)
|
||||||
{
|
{
|
||||||
|
@ -1690,17 +1692,17 @@ static Image LoadDDS(const char *fileName)
|
||||||
}
|
}
|
||||||
else if (((ddsHeader.ddspf.flags == 0x04) || (ddsHeader.ddspf.flags == 0x05)) && (ddsHeader.ddspf.fourCC > 0)) // Compressed
|
else if (((ddsHeader.ddspf.flags == 0x04) || (ddsHeader.ddspf.flags == 0x05)) && (ddsHeader.ddspf.fourCC > 0)) // Compressed
|
||||||
{
|
{
|
||||||
int bufsize;
|
int size; // DDS image data size
|
||||||
|
|
||||||
// Calculate data size, including all mipmaps
|
// Calculate data size, including all mipmaps
|
||||||
if (ddsHeader.mipmapCount > 1) bufsize = ddsHeader.pitchOrLinearSize*2;
|
if (ddsHeader.mipmapCount > 1) size = ddsHeader.pitchOrLinearSize*2;
|
||||||
else bufsize = ddsHeader.pitchOrLinearSize;
|
else size = ddsHeader.pitchOrLinearSize;
|
||||||
|
|
||||||
TraceLog(DEBUG, "Pitch or linear size: %i", ddsHeader.pitchOrLinearSize);
|
TraceLog(DEBUG, "Pitch or linear size: %i", ddsHeader.pitchOrLinearSize);
|
||||||
|
|
||||||
image.data = (unsigned char*)malloc(bufsize*sizeof(unsigned char));
|
image.data = (unsigned char*)malloc(size*sizeof(unsigned char));
|
||||||
|
|
||||||
fread(image.data, 1, bufsize, ddsFile);
|
fread(image.data, size, 1, ddsFile);
|
||||||
|
|
||||||
image.mipmaps = ddsHeader.mipmapCount;
|
image.mipmaps = ddsHeader.mipmapCount;
|
||||||
|
|
||||||
|
@ -1803,7 +1805,7 @@ static Image LoadPKM(const char *fileName)
|
||||||
|
|
||||||
image.data = (unsigned char*)malloc(size*sizeof(unsigned char));
|
image.data = (unsigned char*)malloc(size*sizeof(unsigned char));
|
||||||
|
|
||||||
fread(image.data, 1, size, pkmFile);
|
fread(image.data, size, 1, pkmFile);
|
||||||
|
|
||||||
if (pkmHeader.format == 0) image.format = COMPRESSED_ETC1_RGB;
|
if (pkmHeader.format == 0) image.format = COMPRESSED_ETC1_RGB;
|
||||||
else if (pkmHeader.format == 1) image.format = COMPRESSED_ETC2_RGB;
|
else if (pkmHeader.format == 1) image.format = COMPRESSED_ETC2_RGB;
|
||||||
|
@ -1888,7 +1890,7 @@ static Image LoadKTX(const char *fileName)
|
||||||
|
|
||||||
if (ktxHeader.keyValueDataSize > 0)
|
if (ktxHeader.keyValueDataSize > 0)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < ktxHeader.keyValueDataSize; i++) fread(&unused, 1, 1, ktxFile);
|
for (int i = 0; i < ktxHeader.keyValueDataSize; i++) fread(&unused, sizeof(unsigned char), 1, ktxFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
int dataSize;
|
int dataSize;
|
||||||
|
@ -1896,7 +1898,7 @@ static Image LoadKTX(const char *fileName)
|
||||||
|
|
||||||
image.data = (unsigned char*)malloc(dataSize*sizeof(unsigned char));
|
image.data = (unsigned char*)malloc(dataSize*sizeof(unsigned char));
|
||||||
|
|
||||||
fread(image.data, 1, dataSize, ktxFile);
|
fread(image.data, dataSize, 1, ktxFile);
|
||||||
|
|
||||||
if (ktxHeader.glInternalFormat == 0x8D64) image.format = COMPRESSED_ETC1_RGB;
|
if (ktxHeader.glInternalFormat == 0x8D64) image.format = COMPRESSED_ETC1_RGB;
|
||||||
else if (ktxHeader.glInternalFormat == 0x9274) image.format = COMPRESSED_ETC2_RGB;
|
else if (ktxHeader.glInternalFormat == 0x9274) image.format = COMPRESSED_ETC2_RGB;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue