Work on configuration flags
This commit is contained in:
parent
5387b45431
commit
b7a8a40e71
5 changed files with 159 additions and 55 deletions
92
src/audio.c
92
src/audio.c
|
@ -16,7 +16,7 @@
|
||||||
* Define to use the module as standalone library (independently of raylib).
|
* Define to use the module as standalone library (independently of raylib).
|
||||||
* Required types and functions are defined in the same module.
|
* Required types and functions are defined in the same module.
|
||||||
*
|
*
|
||||||
* #define SUPPORT_FILEFORMAT_WAV / SUPPORT_LOAD_WAV
|
* #define SUPPORT_FILEFORMAT_WAV
|
||||||
* #define SUPPORT_FILEFORMAT_OGG
|
* #define SUPPORT_FILEFORMAT_OGG
|
||||||
* #define SUPPORT_FILEFORMAT_XM
|
* #define SUPPORT_FILEFORMAT_XM
|
||||||
* #define SUPPORT_FILEFORMAT_MOD
|
* #define SUPPORT_FILEFORMAT_MOD
|
||||||
|
@ -24,9 +24,6 @@
|
||||||
* Selected desired fileformats to be supported for loading. Some of those formats are
|
* Selected desired fileformats to be supported for loading. Some of those formats are
|
||||||
* supported by default, to remove support, just comment unrequired #define in this module
|
* supported by default, to remove support, just comment unrequired #define in this module
|
||||||
*
|
*
|
||||||
* #define SUPPORT_RAW_AUDIO_BUFFERS
|
|
||||||
* Support creating raw audio buffers to send raw data. Buffers must be managed by the user,
|
|
||||||
* it means initialization, refilling and cleaning.
|
|
||||||
*
|
*
|
||||||
* LIMITATIONS:
|
* LIMITATIONS:
|
||||||
* Only up to two channels supported: MONO and STEREO (for additional channels, use AL_EXT_MCFORMATS)
|
* Only up to two channels supported: MONO and STEREO (for additional channels, use AL_EXT_MCFORMATS)
|
||||||
|
@ -70,6 +67,12 @@
|
||||||
|
|
||||||
//#define AUDIO_STANDALONE // NOTE: To use the audio module as standalone lib, just uncomment this line
|
//#define AUDIO_STANDALONE // NOTE: To use the audio module as standalone lib, just uncomment this line
|
||||||
|
|
||||||
|
// Default configuration flags (supported features)
|
||||||
|
//-------------------------------------------------
|
||||||
|
#define SUPPORT_FILEFORMAT_WAV
|
||||||
|
#define SUPPORT_FILEFORMAT_OGG
|
||||||
|
//-------------------------------------------------
|
||||||
|
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
#include "audio.h"
|
#include "audio.h"
|
||||||
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
#include <stdarg.h> // Required for: va_list, va_start(), vfprintf(), va_end()
|
||||||
|
@ -94,18 +97,26 @@
|
||||||
#include <string.h> // Required for: strcmp(), strncmp()
|
#include <string.h> // Required for: strcmp(), strncmp()
|
||||||
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
#include <stdio.h> // Required for: FILE, fopen(), fclose(), fread()
|
||||||
|
|
||||||
//#define STB_VORBIS_HEADER_ONLY
|
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||||
#include "external/stb_vorbis.h" // OGG loading functions
|
//#define STB_VORBIS_HEADER_ONLY
|
||||||
|
#include "external/stb_vorbis.h" // OGG loading functions
|
||||||
|
#endif
|
||||||
|
|
||||||
#define JAR_XM_IMPLEMENTATION
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
#include "external/jar_xm.h" // XM loading functions
|
#define JAR_XM_IMPLEMENTATION
|
||||||
|
#include "external/jar_xm.h" // XM loading functions
|
||||||
|
#endif
|
||||||
|
|
||||||
#define JAR_MOD_IMPLEMENTATION
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
#include "external/jar_mod.h" // MOD loading functions
|
#define JAR_MOD_IMPLEMENTATION
|
||||||
|
#include "external/jar_mod.h" // MOD loading functions
|
||||||
|
#endif
|
||||||
|
|
||||||
#define DR_FLAC_IMPLEMENTATION
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
#define DR_FLAC_NO_WIN32_IO
|
#define DR_FLAC_IMPLEMENTATION
|
||||||
#include "external/dr_flac.h" // FLAC loading functions
|
#define DR_FLAC_NO_WIN32_IO
|
||||||
|
#include "external/dr_flac.h" // FLAC loading functions
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#undef bool
|
#undef bool
|
||||||
|
@ -140,10 +151,18 @@ typedef enum { MUSIC_AUDIO_OGG = 0, MUSIC_AUDIO_FLAC, MUSIC_MODULE_XM, MUSIC_MOD
|
||||||
// Music type (file streaming from memory)
|
// Music type (file streaming from memory)
|
||||||
typedef struct MusicData {
|
typedef struct MusicData {
|
||||||
MusicContextType ctxType; // Type of music context (OGG, XM, MOD)
|
MusicContextType ctxType; // Type of music context (OGG, XM, MOD)
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||||
stb_vorbis *ctxOgg; // OGG audio context
|
stb_vorbis *ctxOgg; // OGG audio context
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
drflac *ctxFlac; // FLAC audio context
|
drflac *ctxFlac; // FLAC audio context
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
jar_xm_context_t *ctxXm; // XM chiptune context
|
jar_xm_context_t *ctxXm; // XM chiptune context
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
jar_mod_context_t ctxMod; // MOD chiptune context
|
jar_mod_context_t ctxMod; // MOD chiptune context
|
||||||
|
#endif
|
||||||
|
|
||||||
AudioStream stream; // Audio stream (double buffering)
|
AudioStream stream; // Audio stream (double buffering)
|
||||||
|
|
||||||
|
@ -164,9 +183,15 @@ typedef enum { INFO = 0, ERROR, WARNING, DEBUG, OTHER } TraceLogType;
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_WAV)
|
||||||
static Wave LoadWAV(const char *fileName); // Load WAV file
|
static Wave LoadWAV(const char *fileName); // Load WAV file
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||||
static Wave LoadOGG(const char *fileName); // Load OGG file
|
static Wave LoadOGG(const char *fileName); // Load OGG file
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
static Wave LoadFLAC(const char *fileName); // Load FLAC file
|
static Wave LoadFLAC(const char *fileName); // Load FLAC file
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
const char *GetExtension(const char *fileName); // Get the extension for a filename
|
const char *GetExtension(const char *fileName); // Get the extension for a filename
|
||||||
|
@ -261,8 +286,13 @@ Wave LoadWave(const char *fileName)
|
||||||
Wave wave = { 0 };
|
Wave wave = { 0 };
|
||||||
|
|
||||||
if (strcmp(GetExtension(fileName), "wav") == 0) wave = LoadWAV(fileName);
|
if (strcmp(GetExtension(fileName), "wav") == 0) wave = LoadWAV(fileName);
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||||
else if (strcmp(GetExtension(fileName), "ogg") == 0) wave = LoadOGG(fileName);
|
else if (strcmp(GetExtension(fileName), "ogg") == 0) wave = LoadOGG(fileName);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
else if (strcmp(GetExtension(fileName), "flac") == 0) wave = LoadFLAC(fileName);
|
else if (strcmp(GetExtension(fileName), "flac") == 0) wave = LoadFLAC(fileName);
|
||||||
|
#endif
|
||||||
|
#if !defined(AUDIO_STANDALONE)
|
||||||
else if (strcmp(GetExtension(fileName),"rres") == 0)
|
else if (strcmp(GetExtension(fileName),"rres") == 0)
|
||||||
{
|
{
|
||||||
RRES rres = LoadResource(fileName, 0);
|
RRES rres = LoadResource(fileName, 0);
|
||||||
|
@ -274,7 +304,8 @@ Wave LoadWave(const char *fileName)
|
||||||
|
|
||||||
UnloadResource(rres);
|
UnloadResource(rres);
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[%s] File extension not recognized, it can't be loaded", fileName);
|
#endif
|
||||||
|
else TraceLog(WARNING, "[%s] Audio fileformat not supported, it can't be loaded", fileName);
|
||||||
|
|
||||||
return wave;
|
return wave;
|
||||||
}
|
}
|
||||||
|
@ -664,6 +695,7 @@ Music LoadMusicStream(const char *fileName)
|
||||||
TraceLog(DEBUG, "[%s] OGG memory required: %i", fileName, info.temp_memory_required);
|
TraceLog(DEBUG, "[%s] OGG memory required: %i", fileName, info.temp_memory_required);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
else if (strcmp(GetExtension(fileName), "flac") == 0)
|
else if (strcmp(GetExtension(fileName), "flac") == 0)
|
||||||
{
|
{
|
||||||
music->ctxFlac = drflac_open_file(fileName);
|
music->ctxFlac = drflac_open_file(fileName);
|
||||||
|
@ -683,6 +715,8 @@ Music LoadMusicStream(const char *fileName)
|
||||||
TraceLog(DEBUG, "[%s] FLAC channels: %i", fileName, music->ctxFlac->channels);
|
TraceLog(DEBUG, "[%s] FLAC channels: %i", fileName, music->ctxFlac->channels);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
else if (strcmp(GetExtension(fileName), "xm") == 0)
|
else if (strcmp(GetExtension(fileName), "xm") == 0)
|
||||||
{
|
{
|
||||||
int result = jar_xm_create_context_from_file(&music->ctxXm, 48000, fileName);
|
int result = jar_xm_create_context_from_file(&music->ctxXm, 48000, fileName);
|
||||||
|
@ -703,6 +737,8 @@ Music LoadMusicStream(const char *fileName)
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[%s] XM file could not be opened", fileName);
|
else TraceLog(WARNING, "[%s] XM file could not be opened", fileName);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
else if (strcmp(GetExtension(fileName), "mod") == 0)
|
else if (strcmp(GetExtension(fileName), "mod") == 0)
|
||||||
{
|
{
|
||||||
jar_mod_init(&music->ctxMod);
|
jar_mod_init(&music->ctxMod);
|
||||||
|
@ -720,7 +756,8 @@ Music LoadMusicStream(const char *fileName)
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[%s] MOD file could not be opened", fileName);
|
else TraceLog(WARNING, "[%s] MOD file could not be opened", fileName);
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[%s] Music extension not recognized, it can't be loaded", fileName);
|
#endif
|
||||||
|
else TraceLog(WARNING, "[%s] Audio fileformat not supported, it can't be loaded", fileName);
|
||||||
|
|
||||||
return music;
|
return music;
|
||||||
}
|
}
|
||||||
|
@ -731,9 +768,15 @@ void UnloadMusicStream(Music music)
|
||||||
CloseAudioStream(music->stream);
|
CloseAudioStream(music->stream);
|
||||||
|
|
||||||
if (music->ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close(music->ctxOgg);
|
if (music->ctxType == MUSIC_AUDIO_OGG) stb_vorbis_close(music->ctxOgg);
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
else if (music->ctxType == MUSIC_AUDIO_FLAC) drflac_free(music->ctxFlac);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
else if (music->ctxType == MUSIC_MODULE_XM) jar_xm_free_context(music->ctxXm);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
else if (music->ctxType == MUSIC_MODULE_MOD) jar_mod_unload(&music->ctxMod);
|
else if (music->ctxType == MUSIC_MODULE_MOD) jar_mod_unload(&music->ctxMod);
|
||||||
|
#endif
|
||||||
|
|
||||||
free(music);
|
free(music);
|
||||||
}
|
}
|
||||||
|
@ -778,8 +821,15 @@ void StopMusicStream(Music music)
|
||||||
switch (music->ctxType)
|
switch (music->ctxType)
|
||||||
{
|
{
|
||||||
case MUSIC_AUDIO_OGG: stb_vorbis_seek_start(music->ctxOgg); break;
|
case MUSIC_AUDIO_OGG: stb_vorbis_seek_start(music->ctxOgg); break;
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
|
case MUSIC_MODULE_FLAC: /* TODO: Restart FLAC context */ break;
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
case MUSIC_MODULE_XM: /* TODO: Restart XM context */ break;
|
case MUSIC_MODULE_XM: /* TODO: Restart XM context */ break;
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
case MUSIC_MODULE_MOD: jar_mod_seek_start(&music->ctxMod); break;
|
case MUSIC_MODULE_MOD: jar_mod_seek_start(&music->ctxMod); break;
|
||||||
|
#endif
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -821,14 +871,20 @@ void UpdateMusicStream(Music music)
|
||||||
int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, samplesCount*music->stream.channels);
|
int numSamplesOgg = stb_vorbis_get_samples_short_interleaved(music->ctxOgg, music->stream.channels, (short *)pcm, samplesCount*music->stream.channels);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
case MUSIC_AUDIO_FLAC:
|
case MUSIC_AUDIO_FLAC:
|
||||||
{
|
{
|
||||||
// NOTE: Returns the number of samples to process
|
// NOTE: Returns the number of samples to process
|
||||||
unsigned int numSamplesFlac = (unsigned int)drflac_read_s16(music->ctxFlac, samplesCount*music->stream.channels, (short *)pcm);
|
unsigned int numSamplesFlac = (unsigned int)drflac_read_s16(music->ctxFlac, samplesCount*music->stream.channels, (short *)pcm);
|
||||||
|
|
||||||
} break;
|
} break;
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_XM)
|
||||||
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
case MUSIC_MODULE_XM: jar_xm_generate_samples_16bit(music->ctxXm, pcm, samplesCount); break;
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MOD)
|
||||||
case MUSIC_MODULE_MOD: jar_mod_fillbuffer(&music->ctxMod, pcm, samplesCount, 0); break;
|
case MUSIC_MODULE_MOD: jar_mod_fillbuffer(&music->ctxMod, pcm, samplesCount, 0); break;
|
||||||
|
#endif
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1067,6 +1123,7 @@ void StopAudioStream(AudioStream stream)
|
||||||
// Module specific Functions Definition
|
// Module specific Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_WAV)
|
||||||
// Load WAV file into Wave structure
|
// Load WAV file into Wave structure
|
||||||
static Wave LoadWAV(const char *fileName)
|
static Wave LoadWAV(const char *fileName)
|
||||||
{
|
{
|
||||||
|
@ -1183,7 +1240,9 @@ static Wave LoadWAV(const char *fileName)
|
||||||
|
|
||||||
return wave;
|
return wave;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_OGG)
|
||||||
// Load OGG file into Wave structure
|
// Load OGG file into Wave structure
|
||||||
// NOTE: Using stb_vorbis library
|
// NOTE: Using stb_vorbis library
|
||||||
static Wave LoadOGG(const char *fileName)
|
static Wave LoadOGG(const char *fileName)
|
||||||
|
@ -1223,7 +1282,9 @@ static Wave LoadOGG(const char *fileName)
|
||||||
|
|
||||||
return wave;
|
return wave;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FLAC)
|
||||||
// Load FLAC file into Wave structure
|
// Load FLAC file into Wave structure
|
||||||
// NOTE: Using dr_flac library
|
// NOTE: Using dr_flac library
|
||||||
static Wave LoadFLAC(const char *fileName)
|
static Wave LoadFLAC(const char *fileName)
|
||||||
|
@ -1245,6 +1306,7 @@ static Wave LoadFLAC(const char *fileName)
|
||||||
|
|
||||||
return wave;
|
return wave;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Some required functions for audio standalone module version
|
// Some required functions for audio standalone module version
|
||||||
#if defined(AUDIO_STANDALONE)
|
#if defined(AUDIO_STANDALONE)
|
||||||
|
|
26
src/audio.h
26
src/audio.h
|
@ -2,22 +2,24 @@
|
||||||
*
|
*
|
||||||
* raylib.audio - Basic funtionality to work with audio
|
* raylib.audio - Basic funtionality to work with audio
|
||||||
*
|
*
|
||||||
* DESCRIPTION:
|
* FEATURES:
|
||||||
|
* - Manage audio device (init/close)
|
||||||
|
* - Load and unload audio files
|
||||||
|
* - Format wave data (sample rate, size, channels)
|
||||||
|
* - Play/Stop/Pause/Resume loaded audio
|
||||||
|
* - Manage mixing channels
|
||||||
|
* - Manage raw audio context
|
||||||
*
|
*
|
||||||
* This module provides basic functionality to:
|
* LIMITATIONS:
|
||||||
* - Manage audio device (init/close)
|
* Only up to two channels supported: MONO and STEREO (for additional channels, use AL_EXT_MCFORMATS)
|
||||||
* - Load and unload audio files
|
* Only the following sample sizes supported: 8bit PCM, 16bit PCM, 32-bit float PCM (using AL_EXT_FLOAT32)
|
||||||
* - Format wave data (sample rate, size, channels)
|
|
||||||
* - Play/Stop/Pause/Resume loaded audio
|
|
||||||
* - Manage mixing channels
|
|
||||||
* - Manage raw audio context
|
|
||||||
*
|
*
|
||||||
* DEPENDENCIES:
|
* DEPENDENCIES:
|
||||||
* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html)
|
* OpenAL Soft - Audio device management (http://kcat.strangesoft.net/openal.html)
|
||||||
* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/)
|
* stb_vorbis - OGG audio files loading (http://www.nothings.org/stb_vorbis/)
|
||||||
* jar_xm - XM module file loading
|
* jar_xm - XM module file loading (#define SUPPORT_FILEFORMAT_XM)
|
||||||
* jar_mod - MOD audio file loading
|
* jar_mod - MOD audio file loading (#define SUPPORT_FILEFORMAT_MOD)
|
||||||
* dr_flac - FLAC audio file loading
|
* dr_flac - FLAC audio file loading (#define SUPPORT_FILEFORMAT_FLAC)
|
||||||
*
|
*
|
||||||
* CONTRIBUTORS:
|
* CONTRIBUTORS:
|
||||||
* Joshua Reisenauer (github: @kd7tck):
|
* Joshua Reisenauer (github: @kd7tck):
|
||||||
|
@ -152,7 +154,7 @@ float GetMusicTimePlayed(Music music); // Get current m
|
||||||
AudioStream InitAudioStream(unsigned int sampleRate,
|
AudioStream InitAudioStream(unsigned int sampleRate,
|
||||||
unsigned int sampleSize,
|
unsigned int sampleSize,
|
||||||
unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
unsigned int channels); // Init audio stream (to stream raw audio pcm data)
|
||||||
void UpdateAudioStream(AudioStream stream, void *data, int samplesCount); // Update audio stream buffers with data
|
void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
|
||||||
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
|
void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
|
||||||
bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
|
bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill
|
||||||
void PlayAudioStream(AudioStream stream); // Play audio stream
|
void PlayAudioStream(AudioStream stream); // Play audio stream
|
||||||
|
|
26
src/models.c
26
src/models.c
|
@ -4,7 +4,7 @@
|
||||||
*
|
*
|
||||||
* CONFIGURATION:
|
* CONFIGURATION:
|
||||||
*
|
*
|
||||||
* #define SUPPORT_FILEFORMAT_OBJ / SUPPORT_LOAD_OBJ
|
* #define SUPPORT_FILEFORMAT_OBJ
|
||||||
* Selected desired fileformats to be supported for loading.
|
* Selected desired fileformats to be supported for loading.
|
||||||
*
|
*
|
||||||
* #define SUPPORT_FILEFORMAT_MTL
|
* #define SUPPORT_FILEFORMAT_MTL
|
||||||
|
@ -32,6 +32,12 @@
|
||||||
*
|
*
|
||||||
**********************************************************************************************/
|
**********************************************************************************************/
|
||||||
|
|
||||||
|
// Default configuration flags (supported features)
|
||||||
|
//-------------------------------------------------
|
||||||
|
#define SUPPORT_FILEFORMAT_OBJ
|
||||||
|
#define SUPPORT_FILEFORMAT_MTL
|
||||||
|
//-------------------------------------------------
|
||||||
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
|
@ -63,8 +69,12 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Declaration
|
// Module specific Functions Declaration
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_OBJ)
|
||||||
static Mesh LoadOBJ(const char *fileName); // Load OBJ mesh data
|
static Mesh LoadOBJ(const char *fileName); // Load OBJ mesh data
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MTL)
|
||||||
static Material LoadMTL(const char *fileName); // Load MTL material data
|
static Material LoadMTL(const char *fileName); // Load MTL material data
|
||||||
|
#endif
|
||||||
|
|
||||||
static Mesh GenMeshHeightmap(Image image, Vector3 size);
|
static Mesh GenMeshHeightmap(Image image, Vector3 size);
|
||||||
static Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize);
|
static Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize);
|
||||||
|
@ -582,8 +592,11 @@ Mesh LoadMesh(const char *fileName)
|
||||||
{
|
{
|
||||||
Mesh mesh = { 0 };
|
Mesh mesh = { 0 };
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_OBJ)
|
||||||
if (strcmp(GetExtension(fileName), "obj") == 0) mesh = LoadOBJ(fileName);
|
if (strcmp(GetExtension(fileName), "obj") == 0) mesh = LoadOBJ(fileName);
|
||||||
else TraceLog(WARNING, "[%s] Mesh extension not recognized, it can't be loaded", fileName);
|
#else
|
||||||
|
TraceLog(WARNING, "[%s] Mesh fileformat not supported, it can't be loaded", fileName);
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mesh.vertexCount == 0) TraceLog(WARNING, "Mesh could not be loaded");
|
if (mesh.vertexCount == 0) TraceLog(WARNING, "Mesh could not be loaded");
|
||||||
else rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh)
|
else rlglLoadMesh(&mesh, false); // Upload vertex data to GPU (static mesh)
|
||||||
|
@ -692,8 +705,11 @@ Material LoadMaterial(const char *fileName)
|
||||||
{
|
{
|
||||||
Material material = { 0 };
|
Material material = { 0 };
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MTL)
|
||||||
if (strcmp(GetExtension(fileName), "mtl") == 0) material = LoadMTL(fileName);
|
if (strcmp(GetExtension(fileName), "mtl") == 0) material = LoadMTL(fileName);
|
||||||
else TraceLog(WARNING, "[%s] Material extension not recognized, it can't be loaded", fileName);
|
#else
|
||||||
|
TraceLog(WARNING, "[%s] Material fileformat not supported, it can't be loaded", fileName);
|
||||||
|
#endif
|
||||||
|
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
@ -1590,6 +1606,7 @@ BoundingBox CalculateBoundingBox(Mesh mesh)
|
||||||
// Module specific Functions Definition
|
// Module specific Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_OBJ)
|
||||||
// Load OBJ mesh data
|
// Load OBJ mesh data
|
||||||
static Mesh LoadOBJ(const char *fileName)
|
static Mesh LoadOBJ(const char *fileName)
|
||||||
{
|
{
|
||||||
|
@ -1838,7 +1855,9 @@ static Mesh LoadOBJ(const char *fileName)
|
||||||
|
|
||||||
return mesh;
|
return mesh;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_MTL)
|
||||||
// Load MTL material data (specs: http://paulbourke.net/dataformats/mtl/)
|
// Load MTL material data (specs: http://paulbourke.net/dataformats/mtl/)
|
||||||
// NOTE: Texture map parameters are not supported
|
// NOTE: Texture map parameters are not supported
|
||||||
static Material LoadMTL(const char *fileName)
|
static Material LoadMTL(const char *fileName)
|
||||||
|
@ -2002,3 +2021,4 @@ static Material LoadMTL(const char *fileName)
|
||||||
|
|
||||||
return material;
|
return material;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
29
src/text.c
29
src/text.c
|
@ -5,8 +5,7 @@
|
||||||
* CONFIGURATION:
|
* CONFIGURATION:
|
||||||
*
|
*
|
||||||
* #define SUPPORT_FILEFORMAT_FNT
|
* #define SUPPORT_FILEFORMAT_FNT
|
||||||
* #define SUPPORT_FILEFORMAT_TTF / INCLUDE_STB_TRUETYPE
|
* #define SUPPORT_FILEFORMAT_TTF
|
||||||
* #define SUPPORT_FILEFORMAT_IMAGE_FONT
|
|
||||||
* Selected desired fileformats to be supported for loading. Some of those formats are
|
* Selected desired fileformats to be supported for loading. Some of those formats are
|
||||||
* supported by default, to remove support, just comment unrequired #define in this module
|
* supported by default, to remove support, just comment unrequired #define in this module
|
||||||
*
|
*
|
||||||
|
@ -51,10 +50,12 @@
|
||||||
|
|
||||||
#include "utils.h" // Required for: GetExtension()
|
#include "utils.h" // Required for: GetExtension()
|
||||||
|
|
||||||
// Following libs are used on LoadTTF()
|
#if defined(SUPPORT_FILEFORMAT_TTF)
|
||||||
#define STBTT_STATIC // Define stb_truetype functions static to this module
|
// Following libs are used on LoadTTF()
|
||||||
#define STB_TRUETYPE_IMPLEMENTATION
|
#define STBTT_STATIC // Define stb_truetype functions static to this module
|
||||||
#include "external/stb_truetype.h" // Required for: stbtt_BakeFontBitmap()
|
#define STB_TRUETYPE_IMPLEMENTATION
|
||||||
|
#include "external/stb_truetype.h" // Required for: stbtt_BakeFontBitmap()
|
||||||
|
#endif
|
||||||
|
|
||||||
// Rectangle packing functions (not used at the moment)
|
// Rectangle packing functions (not used at the moment)
|
||||||
//#define STB_RECT_PACK_IMPLEMENTATION
|
//#define STB_RECT_PACK_IMPLEMENTATION
|
||||||
|
@ -91,8 +92,12 @@ static int GetCharIndex(SpriteFont font, int letter);
|
||||||
|
|
||||||
static SpriteFont LoadImageFont(Image image, Color key, int firstChar); // Load a Image font file (XNA style)
|
static SpriteFont LoadImageFont(Image image, Color key, int firstChar); // Load a Image font file (XNA style)
|
||||||
static SpriteFont LoadRBMF(const char *fileName); // Load a rBMF font file (raylib BitMap Font)
|
static SpriteFont LoadRBMF(const char *fileName); // Load a rBMF font file (raylib BitMap Font)
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FNT)
|
||||||
static SpriteFont LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file)
|
static SpriteFont LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file)
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_TTF)
|
||||||
static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load spritefont from TTF data
|
static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load spritefont from TTF data
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(SUPPORT_DEFAULT_FONT)
|
#if defined(SUPPORT_DEFAULT_FONT)
|
||||||
extern void LoadDefaultFont(void);
|
extern void LoadDefaultFont(void);
|
||||||
|
@ -284,8 +289,12 @@ SpriteFont LoadSpriteFont(const char *fileName)
|
||||||
|
|
||||||
// Check file extension
|
// Check file extension
|
||||||
if (strcmp(GetExtension(fileName),"rbmf") == 0) spriteFont = LoadRBMF(fileName); // TODO: DELETE... SOON...
|
if (strcmp(GetExtension(fileName),"rbmf") == 0) spriteFont = LoadRBMF(fileName); // TODO: DELETE... SOON...
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_TTF)
|
||||||
else if (strcmp(GetExtension(fileName),"ttf") == 0) spriteFont = LoadSpriteFontTTF(fileName, DEFAULT_TTF_FONTSIZE, 0, NULL);
|
else if (strcmp(GetExtension(fileName),"ttf") == 0) spriteFont = LoadSpriteFontTTF(fileName, DEFAULT_TTF_FONTSIZE, 0, NULL);
|
||||||
|
#endif
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FNT)
|
||||||
else if (strcmp(GetExtension(fileName),"fnt") == 0) spriteFont = LoadBMFont(fileName);
|
else if (strcmp(GetExtension(fileName),"fnt") == 0) spriteFont = LoadBMFont(fileName);
|
||||||
|
#endif
|
||||||
else if (strcmp(GetExtension(fileName),"rres") == 0)
|
else if (strcmp(GetExtension(fileName),"rres") == 0)
|
||||||
{
|
{
|
||||||
// TODO: Read multiple resource blocks from file (RRES_FONT_IMAGE, RRES_FONT_CHARDATA)
|
// TODO: Read multiple resource blocks from file (RRES_FONT_IMAGE, RRES_FONT_CHARDATA)
|
||||||
|
@ -336,6 +345,7 @@ SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int charsCount,
|
||||||
{
|
{
|
||||||
SpriteFont spriteFont = { 0 };
|
SpriteFont spriteFont = { 0 };
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_TTF)
|
||||||
if (strcmp(GetExtension(fileName),"ttf") == 0)
|
if (strcmp(GetExtension(fileName),"ttf") == 0)
|
||||||
{
|
{
|
||||||
if ((fontChars == NULL) || (charsCount == 0))
|
if ((fontChars == NULL) || (charsCount == 0))
|
||||||
|
@ -350,6 +360,7 @@ SpriteFont LoadSpriteFontTTF(const char *fileName, int fontSize, int charsCount,
|
||||||
}
|
}
|
||||||
else spriteFont = LoadTTF(fileName, fontSize, charsCount, fontChars);
|
else spriteFont = LoadTTF(fileName, fontSize, charsCount, fontChars);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (spriteFont.texture.id == 0)
|
if (spriteFont.texture.id == 0)
|
||||||
{
|
{
|
||||||
|
@ -845,6 +856,7 @@ static SpriteFont LoadRBMF(const char *fileName)
|
||||||
return spriteFont;
|
return spriteFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_FNT)
|
||||||
// Load a BMFont file (AngelCode font file)
|
// Load a BMFont file (AngelCode font file)
|
||||||
static SpriteFont LoadBMFont(const char *fileName)
|
static SpriteFont LoadBMFont(const char *fileName)
|
||||||
{
|
{
|
||||||
|
@ -962,7 +974,9 @@ static SpriteFont LoadBMFont(const char *fileName)
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(SUPPORT_FILEFORMAT_TTF)
|
||||||
// Generate a sprite font from TTF file data (font size required)
|
// Generate a sprite font from TTF file data (font size required)
|
||||||
// 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)
|
||||||
|
@ -1054,4 +1068,5 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
|
||||||
free(charData);
|
free(charData);
|
||||||
|
|
||||||
return font;
|
return font;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
41
src/utils.c
41
src/utils.c
|
@ -153,6 +153,29 @@ void SavePNG(const char *fileName, unsigned char *imgData, int width, int height
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Keep track of memory allocated
|
||||||
|
// NOTE: mallocType defines the type of data allocated
|
||||||
|
/*
|
||||||
|
void RecordMalloc(int mallocType, int mallocSize, const char *msg)
|
||||||
|
{
|
||||||
|
// TODO: Investigate how to record memory allocation data...
|
||||||
|
// Maybe creating my own malloc function...
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool IsFileExtension(const char *fileName, const char *ext)
|
||||||
|
{
|
||||||
|
return (strcmp(GetExtension(fileName), ext) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the extension for a filename
|
||||||
|
const char *GetExtension(const char *fileName)
|
||||||
|
{
|
||||||
|
const char *dot = strrchr(fileName, '.');
|
||||||
|
if (!dot || dot == fileName) return "";
|
||||||
|
return (dot + 1);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID)
|
#if defined(PLATFORM_ANDROID)
|
||||||
// Initialize asset manager from android app
|
// Initialize asset manager from android app
|
||||||
void InitAssetManager(AAssetManager *manager)
|
void InitAssetManager(AAssetManager *manager)
|
||||||
|
@ -173,24 +196,6 @@ FILE *android_fopen(const char *fileName, const char *mode)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Keep track of memory allocated
|
|
||||||
// NOTE: mallocType defines the type of data allocated
|
|
||||||
/*
|
|
||||||
void RecordMalloc(int mallocType, int mallocSize, const char *msg)
|
|
||||||
{
|
|
||||||
// TODO: Investigate how to record memory allocation data...
|
|
||||||
// Maybe creating my own malloc function...
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
// Get the extension for a filename
|
|
||||||
const char *GetExtension(const char *fileName)
|
|
||||||
{
|
|
||||||
const char *dot = strrchr(fileName, '.');
|
|
||||||
if (!dot || dot == fileName) return "";
|
|
||||||
return (dot + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Module specific Functions Definition
|
// Module specific Functions Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue