commit
bc4af2a23d
|
|
@ -438,7 +438,7 @@ EXAMPLES = \
|
||||||
shaders/shaders_eratosthenes \
|
shaders/shaders_eratosthenes \
|
||||||
shaders/shaders_basic_lighting \
|
shaders/shaders_basic_lighting \
|
||||||
shaders/shaders_fog \
|
shaders/shaders_fog \
|
||||||
shaders/shaders_simple \
|
shaders/shaders_simple_mask \
|
||||||
audio/audio_module_playing \
|
audio/audio_module_playing \
|
||||||
audio/audio_music_stream \
|
audio/audio_music_stream \
|
||||||
audio/audio_raw_stream \
|
audio/audio_raw_stream \
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+
|
cmake_minimum_required(VERSION 3.11) # FetchContent is available in 3.11+
|
||||||
project(example)
|
project(example)
|
||||||
|
|
||||||
find_package(raylib 2.0 QUIET) # Let CMake search for a raylib-config.cmake
|
# Set this to the minimal version you want to support
|
||||||
|
find_package(raylib 2.5 QUIET) # Let CMake search for a raylib-config.cmake
|
||||||
|
|
||||||
# You could change the QUIET above to REQUIRED and remove this if() clause
|
# You could change the QUIET above to REQUIRED and remove this if() clause
|
||||||
# This part downloads raylib and builds it if it's not installed on your system
|
# This part downloads raylib and builds it if it's not installed on your system
|
||||||
|
|
|
||||||
25
src/core.c
25
src/core.c
|
|
@ -1796,30 +1796,19 @@ bool FileExists(const char *fileName)
|
||||||
bool IsFileExtension(const char *fileName, const char *ext)
|
bool IsFileExtension(const char *fileName, const char *ext)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
const char *fileExt;
|
const char *fileExt = GetExtension(fileName);
|
||||||
|
|
||||||
if ((fileExt = strrchr(fileName, '.')) != NULL)
|
int extCount = 0;
|
||||||
|
const char **checkExts = TextSplit(ext, ';', &extCount);
|
||||||
|
|
||||||
|
for (int i = 0; i < extCount; i++)
|
||||||
|
{
|
||||||
|
if (strcmp(fileExt, checkExts[i] + 1) == 0)
|
||||||
{
|
{
|
||||||
#if defined(_WIN32)
|
|
||||||
result = true;
|
result = true;
|
||||||
int extLen = strlen(ext);
|
|
||||||
|
|
||||||
if (strlen(fileExt) == extLen)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < extLen; i++)
|
|
||||||
{
|
|
||||||
if (tolower(fileExt[i]) != tolower(ext[i]))
|
|
||||||
{
|
|
||||||
result = false;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else result = false;
|
|
||||||
#else
|
|
||||||
if (strcmp(fileExt, ext) == 0) result = true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -809,6 +809,9 @@ Material *LoadMaterials(const char *fileName, int *materialCount)
|
||||||
tinyobj_material_t *mats;
|
tinyobj_material_t *mats;
|
||||||
|
|
||||||
int result = tinyobj_parse_mtl_file(&mats, &count, fileName);
|
int result = tinyobj_parse_mtl_file(&mats, &count, fileName);
|
||||||
|
if (result != TINYOBJ_SUCCESS) {
|
||||||
|
TraceLog(LOG_WARNING, "[%s] Could not parse Materials file", fileName);
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Process materials to return
|
// TODO: Process materials to return
|
||||||
|
|
||||||
|
|
@ -3499,6 +3502,9 @@ static Model LoadGLTF(const char *fileName)
|
||||||
|
|
||||||
// Read data buffers
|
// Read data buffers
|
||||||
result = cgltf_load_buffers(&options, data, fileName);
|
result = cgltf_load_buffers(&options, data, fileName);
|
||||||
|
if (result != cgltf_result_success) {
|
||||||
|
TraceLog(LOG_INFO, "[%s][%s] Error loading mesh/material buffers", fileName, (data->file_type == 2)? "glb" : "gltf");
|
||||||
|
}
|
||||||
|
|
||||||
int primitivesCount = 0;
|
int primitivesCount = 0;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1870,9 +1870,9 @@ static int SaveWAV(Wave wave, const char *fileName)
|
||||||
waveData.subChunkID[3] = 'a';
|
waveData.subChunkID[3] = 'a';
|
||||||
waveData.subChunkSize = dataSize;
|
waveData.subChunkSize = dataSize;
|
||||||
|
|
||||||
success = fwrite(&riffHeader, sizeof(RiffHeader), 1, wavFile);
|
fwrite(&riffHeader, sizeof(RiffHeader), 1, wavFile);
|
||||||
success = fwrite(&waveFormat, sizeof(WaveFormat), 1, wavFile);
|
fwrite(&waveFormat, sizeof(WaveFormat), 1, wavFile);
|
||||||
success = fwrite(&waveData, sizeof(WaveData), 1, wavFile);
|
fwrite(&waveData, sizeof(WaveData), 1, wavFile);
|
||||||
|
|
||||||
success = fwrite(wave.data, dataSize, 1, wavFile);
|
success = fwrite(wave.data, dataSize, 1, wavFile);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1189,8 +1189,8 @@ RLAPI void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontS
|
||||||
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
|
RLAPI int MeasureText(const char *text, int fontSize); // Measure string width for default font
|
||||||
RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font
|
RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font
|
||||||
RLAPI int GetGlyphIndex(Font font, int character); // Get index position for a unicode character on font
|
RLAPI int GetGlyphIndex(Font font, int character); // Get index position for a unicode character on font
|
||||||
RLAPI int GetNextCodepoint(const char *text, int *bytesProcessed); // Returns next codepoint in a UTF8 encoded string
|
RLAPI int GetNextCodepoint(const char *text, int *bytesProcessed); // Returns next codepoint in a UTF8 encoded string; 0x3f('?') is returned on failure
|
||||||
// NOTE: 0x3f('?') is returned on failure
|
RLAPI int *GetCodepoints(const char *text, int *count); // Get all codepoints in a string, codepoints count returned by parameters
|
||||||
|
|
||||||
// Text strings management functions
|
// Text strings management functions
|
||||||
// NOTE: Some strings allocate memory internally for returned strings, just be careful!
|
// NOTE: Some strings allocate memory internally for returned strings, just be careful!
|
||||||
|
|
|
||||||
41
src/text.c
41
src/text.c
|
|
@ -65,6 +65,8 @@
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers of some Text*() functions
|
#define MAX_TEXT_BUFFER_LENGTH 1024 // Size of internal static buffers of some Text*() functions
|
||||||
|
|
||||||
|
#define MAX_TEXT_UNICODE_CHARS 512 // Maximum number of unicode codepoints
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
// Types and Structures Definition
|
// Types and Structures Definition
|
||||||
//----------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------
|
||||||
|
|
@ -282,7 +284,7 @@ Font LoadFont(const char *fileName)
|
||||||
Font font = { 0 };
|
Font font = { 0 };
|
||||||
|
|
||||||
#if defined(SUPPORT_FILEFORMAT_TTF)
|
#if defined(SUPPORT_FILEFORMAT_TTF)
|
||||||
if (IsFileExtension(fileName, ".ttf") || IsFileExtension(fileName, ".otf")) font = LoadFontEx(fileName, DEFAULT_TTF_FONTSIZE, NULL, DEFAULT_TTF_NUMCHARS);
|
if (IsFileExtension(fileName, ".ttf;.otf")) font = LoadFontEx(fileName, DEFAULT_TTF_FONTSIZE, NULL, DEFAULT_TTF_NUMCHARS);
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
#if defined(SUPPORT_FILEFORMAT_FNT)
|
#if defined(SUPPORT_FILEFORMAT_FNT)
|
||||||
|
|
@ -869,6 +871,28 @@ int GetNextCodepoint(const char *text, int *bytesProcessed)
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get all codepoints in a string, codepoints count returned by parameters
|
||||||
|
int *GetCodepoints(const char *text, int *count)
|
||||||
|
{
|
||||||
|
static int codepoints[MAX_TEXT_UNICODE_CHARS] = { 0 };
|
||||||
|
memset(codepoints, 0, MAX_TEXT_UNICODE_CHARS*sizeof(int));
|
||||||
|
|
||||||
|
int bytesProcessed = 0;
|
||||||
|
int textLength = strlen(text);
|
||||||
|
int codepointsCount = 0;
|
||||||
|
|
||||||
|
for (int i = 0; i < textLength; codepointsCount++)
|
||||||
|
{
|
||||||
|
codepoints[codepointsCount] = GetNextCodepoint(text + i, &bytesProcessed);
|
||||||
|
i += bytesProcessed;
|
||||||
|
}
|
||||||
|
|
||||||
|
*count = codepointsCount;
|
||||||
|
|
||||||
|
return codepoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Draw text (using default font)
|
// Draw text (using default font)
|
||||||
// NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used
|
// NOTE: fontSize work like in any drawing program but if fontSize is lower than font-base-size, then font-base-size is used
|
||||||
|
|
@ -1572,18 +1596,15 @@ static Font LoadBMFont(const char *fileName)
|
||||||
TraceLog(LOG_DEBUG, "[%s] Font texture loading path: %s", fileName, texPath);
|
TraceLog(LOG_DEBUG, "[%s] Font texture loading path: %s", fileName, texPath);
|
||||||
|
|
||||||
Image imFont = LoadImage(texPath);
|
Image imFont = LoadImage(texPath);
|
||||||
Image imFontAlpha = ImageCopy(imFont);
|
|
||||||
|
|
||||||
if (imFont.format == UNCOMPRESSED_GRAYSCALE)
|
if (imFont.format == UNCOMPRESSED_GRAYSCALE)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < imFontAlpha.width*imFontAlpha.height; i++) ((unsigned char *)imFontAlpha.data)[i] = 0xff;
|
// Convert image to GRAYSCALE + ALPHA, using the mask as the alpha channel
|
||||||
|
ImageAlphaMask(&imFont, imFont);
|
||||||
ImageAlphaMask(&imFontAlpha, imFont);
|
for (int p = 0; p < (imFont.width*imFont.height*2); p += 2) ((unsigned char *)(imFont.data))[p] = 0xff;
|
||||||
font.texture = LoadTextureFromImage(imFontAlpha);
|
|
||||||
}
|
}
|
||||||
else font.texture = LoadTextureFromImage(imFont);
|
|
||||||
|
|
||||||
UnloadImage(imFont);
|
font.texture = LoadTextureFromImage(imFont);
|
||||||
|
|
||||||
RL_FREE(texPath);
|
RL_FREE(texPath);
|
||||||
|
|
||||||
|
|
@ -1611,10 +1632,10 @@ static Font LoadBMFont(const char *fileName)
|
||||||
font.chars[i].advanceX = charAdvanceX;
|
font.chars[i].advanceX = charAdvanceX;
|
||||||
|
|
||||||
// Fill character image data from imFont data
|
// Fill character image data from imFont data
|
||||||
font.chars[i].image = ImageFromImage(imFontAlpha, font.recs[i]);
|
font.chars[i].image = ImageFromImage(imFont, font.recs[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
UnloadImage(imFontAlpha);
|
UnloadImage(imFont);
|
||||||
|
|
||||||
fclose(fntFile);
|
fclose(fntFile);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1181,13 +1181,18 @@ void ImageAlphaMask(Image *image, Image alphaMask)
|
||||||
// In case image is only grayscale, we just add alpha channel
|
// In case image is only grayscale, we just add alpha channel
|
||||||
if (image->format == UNCOMPRESSED_GRAYSCALE)
|
if (image->format == UNCOMPRESSED_GRAYSCALE)
|
||||||
{
|
{
|
||||||
ImageFormat(image, UNCOMPRESSED_GRAY_ALPHA);
|
unsigned char *data = (unsigned char *)RL_MALLOC(image->width*image->height*2);
|
||||||
|
|
||||||
// Apply alpha mask to alpha channel
|
// Apply alpha mask to alpha channel
|
||||||
for (int i = 0, k = 1; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2)
|
for (int i = 0, k = 0; (i < mask.width*mask.height) || (i < image->width*image->height); i++, k += 2)
|
||||||
{
|
{
|
||||||
((unsigned char *)image->data)[k] = ((unsigned char *)mask.data)[i];
|
data[k] = ((unsigned char *)image->data)[i];
|
||||||
|
data[k + 1] = ((unsigned char *)mask.data)[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RL_FREE(image->data);
|
||||||
|
image->data = data;
|
||||||
|
image->format = UNCOMPRESSED_GRAY_ALPHA;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user