BREAKING CHANGE: Renamed SpriteFont type to Font

- Preparing MP3 files support
- Jumped version to raylib 2.0-dev (too many breaking changes...)
This commit is contained in:
Ray San 2018-05-04 16:59:48 +02:00
parent 6045062a05
commit ec33e7d705
34 changed files with 3027 additions and 179 deletions

View file

@ -1,6 +1,6 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib [text] example - BMFont and TTF SpriteFonts loading * raylib [text] example - BMFont and TTF Fonts loading
* *
* This example has been created using raylib 1.4 (www.raylib.com) * This example has been created using raylib 1.4 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@ -24,8 +24,8 @@ int main()
const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF"; const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
SpriteFont fontBm = LoadSpriteFont("resources/bmfont.fnt"); // BMFont (AngelCode) Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode)
SpriteFont fontTtf = LoadSpriteFont("resources/pixantiqua.ttf"); // TTF font Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font
Vector2 fontPosition; Vector2 fontPosition;
@ -58,8 +58,8 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadSpriteFont(fontBm); // AngelCode SpriteFont unloading UnloadFont(fontBm); // AngelCode Font unloading
UnloadSpriteFont(fontTtf); // TTF SpriteFont unloading UnloadFont(fontTtf); // TTF Font unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -25,7 +25,7 @@ int main()
const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"; const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ";
// NOTE: Loaded font has an unordered list of characters (chars in the range 32..255) // NOTE: Loaded font has an unordered list of characters (chars in the range 32..255)
SpriteFont font = LoadSpriteFont("resources/pixantiqua.fnt"); // BMFont (AngelCode) Font font = LoadFont("resources/pixantiqua.fnt"); // BMFont (AngelCode)
SetTargetFPS(60); SetTargetFPS(60);
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -56,7 +56,7 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadSpriteFont(font); // AngelCode SpriteFont unloading UnloadFont(font); // AngelCode Font unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -26,16 +26,16 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts"); InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
SpriteFont fonts[MAX_FONTS]; Font fonts[MAX_FONTS];
fonts[0] = LoadSpriteFont("resources/fonts/alagard.png"); fonts[0] = LoadFont("resources/fonts/alagard.png");
fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.png"); fonts[1] = LoadFont("resources/fonts/pixelplay.png");
fonts[2] = LoadSpriteFont("resources/fonts/mecha.png"); fonts[2] = LoadFont("resources/fonts/mecha.png");
fonts[3] = LoadSpriteFont("resources/fonts/setback.png"); fonts[3] = LoadFont("resources/fonts/setback.png");
fonts[4] = LoadSpriteFont("resources/fonts/romulus.png"); fonts[4] = LoadFont("resources/fonts/romulus.png");
fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.png"); fonts[5] = LoadFont("resources/fonts/pixantiqua.png");
fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.png"); fonts[6] = LoadFont("resources/fonts/alpha_beta.png");
fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.png"); fonts[7] = LoadFont("resources/fonts/jupiter_crash.png");
const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi", const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi",
"PIXELPLAY FONT designed by Aleksander Shevchuk", "PIXELPLAY FONT designed by Aleksander Shevchuk",
@ -93,8 +93,8 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// SpriteFonts unloading // Fonts unloading
for (int i = 0; i < MAX_FONTS; i++) UnloadSpriteFont(fonts[i]); for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -1,6 +1,6 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib [text] example - SpriteFont loading and usage * raylib [text] example - Font loading and usage
* *
* This example has been created using raylib 1.0 (www.raylib.com) * This example has been created using raylib 1.0 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
@ -25,9 +25,9 @@ int main()
const char msg3[50] = "...and a THIRD one! GREAT! :D"; const char msg3[50] = "...and a THIRD one! GREAT! :D";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
SpriteFont font1 = LoadSpriteFont("resources/custom_mecha.png"); // SpriteFont loading Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading
SpriteFont font2 = LoadSpriteFont("resources/custom_alagard.png"); // SpriteFont loading Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading
SpriteFont font3 = LoadSpriteFont("resources/custom_jupiter_crash.png"); // SpriteFont loading Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading
Vector2 fontPosition1, fontPosition2, fontPosition3; Vector2 fontPosition1, fontPosition2, fontPosition3;
@ -66,9 +66,9 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadSpriteFont(font1); // SpriteFont unloading UnloadFont(font1); // Font unloading
UnloadSpriteFont(font2); // SpriteFont unloading UnloadFont(font2); // Font unloading
UnloadSpriteFont(font3); // SpriteFont unloading UnloadFont(font3); // Font unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -20,12 +20,12 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading"); InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading");
const char msg[50] = "TTF SpriteFont"; const char msg[50] = "TTF Font";
// NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required)
// TTF SpriteFont loading with custom generation parameters // TTF Font loading with custom generation parameters
SpriteFont font = LoadSpriteFontEx("resources/KAISG.ttf", 96, 0, 0); Font font = LoadFontEx("resources/KAISG.ttf", 96, 0, 0);
// Generate mipmap levels to use trilinear filtering // Generate mipmap levels to use trilinear filtering
// NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR // NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR
@ -85,8 +85,8 @@ int main()
if (count == 1) // Only support one ttf file dropped if (count == 1) // Only support one ttf file dropped
{ {
UnloadSpriteFont(font); UnloadFont(font);
font = LoadSpriteFontEx(droppedFiles[0], fontSize, 0, 0); font = LoadFontEx(droppedFiles[0], fontSize, 0, 0);
ClearDroppedFiles(); ClearDroppedFiles();
} }
} }
@ -127,7 +127,7 @@ int main()
#if defined(PLATFORM_DESKTOP) #if defined(PLATFORM_DESKTOP)
ClearDroppedFiles(); // Clear internal buffers ClearDroppedFiles(); // Clear internal buffers
#endif #endif
UnloadSpriteFont(font); // SpriteFont unloading UnloadFont(font); // Font unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -38,12 +38,12 @@ int main()
UnloadImage(cat); // Unload image from RAM UnloadImage(cat); // Unload image from RAM
// Load custom font for frawing on image // Load custom font for frawing on image
SpriteFont font = LoadSpriteFont("resources/custom_jupiter_crash.png"); Font font = LoadFont("resources/custom_jupiter_crash.png");
// Draw over image using custom font // Draw over image using custom font
ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE); ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE);
UnloadSpriteFont(font); // Unload custom spritefont (already drawn used on image) UnloadFont(font); // Unload custom spritefont (already drawn used on image)
Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM)
UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM

View file

@ -20,8 +20,8 @@ int main()
InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing"); InitWindow(screenWidth, screenHeight, "raylib [texture] example - image text drawing");
// TTF SpriteFont loading with custom generation parameters // TTF Font loading with custom generation parameters
SpriteFont font = LoadSpriteFontEx("resources/KAISG.ttf", 64, 0, 0); Font font = LoadFontEx("resources/KAISG.ttf", 64, 0, 0);
Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM) Image parrots = LoadImage("resources/parrots.png"); // Load image in CPU memory (RAM)
@ -74,7 +74,7 @@ int main()
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading UnloadTexture(texture); // Texture unloading
UnloadSpriteFont(font); // Unload custom spritefont UnloadFont(font); // Unload custom spritefont
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -49,7 +49,7 @@ int main()
Texture2D gframe = LoadTexture("resources/gframe.png"); Texture2D gframe = LoadTexture("resources/gframe.png");
// Load game resources: fonts // Load game resources: fonts
SpriteFont font = LoadSpriteFont("resources/komika.png"); Font font = LoadFont("resources/komika.png");
// Define scrolling variables // Define scrolling variables
int backScrolling = 0; int backScrolling = 0;
@ -438,7 +438,7 @@ int main()
UnloadTexture(gamera); UnloadTexture(gamera);
// Unload font texture // Unload font texture
UnloadSpriteFont(font); UnloadFont(font);
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

View file

@ -52,7 +52,7 @@ int main()
Texture2D gframe = LoadTexture("resources/gframe.png"); Texture2D gframe = LoadTexture("resources/gframe.png");
// Load game resources: fonts // Load game resources: fonts
SpriteFont font = LoadSpriteFont("resources/komika.png"); Font font = LoadFont("resources/komika.png");
// Load game resources: sounds // Load game resources: sounds
Sound eat = LoadSound("resources/eat.wav"); Sound eat = LoadSound("resources/eat.wav");
@ -454,7 +454,7 @@ int main()
UnloadTexture(gamera); UnloadTexture(gamera);
// Unload font texture // Unload font texture
UnloadSpriteFont(font); UnloadFont(font);
// Unload sounds // Unload sounds
UnloadSound(eat); UnloadSound(eat);

View file

@ -55,7 +55,7 @@ int main()
Texture2D gframe = LoadTexture("resources/gframe.png"); Texture2D gframe = LoadTexture("resources/gframe.png");
// Load game resources: fonts // Load game resources: fonts
SpriteFont font = LoadSpriteFont("resources/komika.png"); Font font = LoadFont("resources/komika.png");
// Load game resources: sounds // Load game resources: sounds
Sound eat = LoadSound("resources/eat.wav"); Sound eat = LoadSound("resources/eat.wav");
@ -479,7 +479,7 @@ int main()
UnloadTexture(gamera); UnloadTexture(gamera);
// Unload font texture // Unload font texture
UnloadSpriteFont(font); UnloadFont(font);
// Unload sounds // Unload sounds
UnloadSound(eat); UnloadSound(eat);

View file

@ -48,7 +48,7 @@ Texture2D swhale;
Texture2D fish; Texture2D fish;
Texture2D gframe; Texture2D gframe;
SpriteFont font; Font font;
Sound eat; Sound eat;
Sound die; Sound die;
@ -119,7 +119,7 @@ int main()
gframe = LoadTexture("resources/gframe.png"); gframe = LoadTexture("resources/gframe.png");
// Load game resources: fonts // Load game resources: fonts
font = LoadSpriteFont("resources/komika.png"); font = LoadFont("resources/komika.png");
// Load game resources: sounds // Load game resources: sounds
eat = LoadSound("resources/eat.wav"); eat = LoadSound("resources/eat.wav");
@ -186,7 +186,7 @@ int main()
UnloadTexture(gamera); UnloadTexture(gamera);
// Unload font texture // Unload font texture
UnloadSpriteFont(font); UnloadFont(font);
// Unload sounds // Unload sounds
UnloadSound(eat); UnloadSound(eat);

View file

@ -57,7 +57,7 @@ int main(void) {
InitWindow(screenWidth, screenHeight, windowTitle); InitWindow(screenWidth, screenHeight, windowTitle);
// Load global data here (assets that must be available in all screens, i.e. fonts) // Load global data here (assets that must be available in all screens, i.e. fonts)
font = LoadSpriteFont("resources/graphics/mainfont.png"); font = LoadFont("resources/graphics/mainfont.png");
atlas01 = LoadTexture("resources/graphics/atlas01.png"); atlas01 = LoadTexture("resources/graphics/atlas01.png");
atlas02 = LoadTexture("resources/graphics/atlas02.png"); atlas02 = LoadTexture("resources/graphics/atlas02.png");
@ -114,7 +114,7 @@ int main(void) {
UnloadTexture(atlas01); UnloadTexture(atlas01);
UnloadTexture(atlas02); UnloadTexture(atlas02);
UnloadSpriteFont(font); UnloadFont(font);
UnloadShader(colorBlend); // Unload color overlay blending shader UnloadShader(colorBlend); // Unload color overlay blending shader

View file

@ -42,7 +42,7 @@ typedef enum GameScreen { LOGO, TITLE, OPTIONS, GAMEPLAY, ENDING } GameScreen;
GameScreen currentScreen; GameScreen currentScreen;
// NOTE: This is all the data used in the game // NOTE: This is all the data used in the game
SpriteFont font; Font font;
Shader colorBlend; Shader colorBlend;
Texture2D atlas01; Texture2D atlas01;
Texture2D atlas02; Texture2D atlas02;

View file

@ -68,7 +68,7 @@ int main(void)
UnloadImage(image); // Unload image from CPU memory (RAM) UnloadImage(image); // Unload image from CPU memory (RAM)
font = LoadSpriteFont("resources/font_arcadian.png"); font = LoadFont("resources/font_arcadian.png");
//doors = LoadTexture("resources/textures/doors.png"); //doors = LoadTexture("resources/textures/doors.png");
//sndDoor = LoadSound("resources/audio/door.ogg"); //sndDoor = LoadSound("resources/audio/door.ogg");
@ -106,7 +106,7 @@ int main(void)
} }
// Unload all global loaded data (i.e. fonts) here! // Unload all global loaded data (i.e. fonts) here!
UnloadSpriteFont(font); UnloadFont(font);
//UnloadSound(sndDoor); //UnloadSound(sndDoor);
UnloadMusicStream(music); UnloadMusicStream(music);

View file

@ -35,7 +35,7 @@ typedef enum GameScreen { LOGO_RL = 0, TITLE, GAMEPLAY } GameScreen;
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
GameScreen currentScreen; GameScreen currentScreen;
SpriteFont font; Font font;
Color *lightsMap; Color *lightsMap;
int lightsMapWidth, lightsMapHeight; int lightsMapWidth, lightsMapHeight;

View file

@ -47,7 +47,7 @@ typedef struct Door {
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
GameScreen currentScreen; GameScreen currentScreen;
SpriteFont font; Font font;
Texture2D doors; Texture2D doors;
Sound sndDoor; Sound sndDoor;

View file

@ -60,7 +60,7 @@ int main(void)
music = LoadMusicStream("resources/audio/come_play_with_me.ogg"); music = LoadMusicStream("resources/audio/come_play_with_me.ogg");
PlayMusicStream(music); PlayMusicStream(music);
font = LoadSpriteFont("resources/textures/alagard.png"); font = LoadFont("resources/textures/alagard.png");
doors = LoadTexture("resources/textures/doors.png"); doors = LoadTexture("resources/textures/doors.png");
sndDoor = LoadSound("resources/audio/door.ogg"); sndDoor = LoadSound("resources/audio/door.ogg");
sndScream = LoadSound("resources/audio/scream.ogg"); sndScream = LoadSound("resources/audio/scream.ogg");
@ -89,7 +89,7 @@ int main(void)
// Unload all global loaded data (i.e. fonts) here! // Unload all global loaded data (i.e. fonts) here!
UnloadPlayer(); UnloadPlayer();
UnloadSpriteFont(font); UnloadFont(font);
UnloadTexture(doors); UnloadTexture(doors);
UnloadSound(sndDoor); UnloadSound(sndDoor);
UnloadSound(sndScream); UnloadSound(sndScream);

View file

@ -68,7 +68,7 @@ static Mission *missions = NULL;
static char headline[MAX_TITLE_CHAR] = "\0"; static char headline[MAX_TITLE_CHAR] = "\0";
SpriteFont fontNews; Font fontNews;
// String (const char *) replacement function // String (const char *) replacement function
static char *StringReplace(char *orig, char *rep, char *with); static char *StringReplace(char *orig, char *rep, char *with);
@ -121,11 +121,11 @@ void InitEndingScreen(void)
// Generate newspaper with title and subtitle // Generate newspaper with title and subtitle
Image imNewspaper = LoadImage("resources/textures/ending_newspaper.png"); Image imNewspaper = LoadImage("resources/textures/ending_newspaper.png");
fontNews = LoadSpriteFontEx("resources/fonts/Lora-Bold.ttf", 32, 250, 0); fontNews = LoadFontEx("resources/fonts/Lora-Bold.ttf", 32, 250, 0);
ImageDrawTextEx(&imNewspaper, (Vector2){ 50, 220 }, fontNews, headline, fontNews.baseSize, 0, DARKGRAY); ImageDrawTextEx(&imNewspaper, (Vector2){ 50, 220 }, fontNews, headline, fontNews.baseSize, 0, DARKGRAY);
texNewspaper = LoadTextureFromImage(imNewspaper); texNewspaper = LoadTextureFromImage(imNewspaper);
//UnloadSpriteFont(fontNews); //UnloadFont(fontNews);
UnloadImage(imNewspaper); UnloadImage(imNewspaper);
} }

View file

@ -95,7 +95,7 @@ static int framesCounter;
static int finishScreen; static int finishScreen;
static Texture2D texBackground; static Texture2D texBackground;
static SpriteFont fontMessage; static Font fontMessage;
static Texture2D texWordsAtlas; static Texture2D texWordsAtlas;
static Texture2D texVignette; static Texture2D texVignette;
@ -126,7 +126,7 @@ void InitGameplayScreen(void)
framesCounter = 0; framesCounter = 0;
finishScreen = 0; finishScreen = 0;
fontMessage = LoadSpriteFontEx("resources/fonts/traveling_typewriter.ttf", 30, 250, 0); fontMessage = LoadFontEx("resources/fonts/traveling_typewriter.ttf", 30, 250, 0);
texBackground = LoadTexture("resources/textures/message_background.png"); texBackground = LoadTexture("resources/textures/message_background.png");
texVignette = LoadTexture("resources/textures/message_vignette.png"); texVignette = LoadTexture("resources/textures/message_vignette.png");

View file

@ -36,7 +36,7 @@ static int framesCounter;
static int finishScreen; static int finishScreen;
static Texture2D texBackground; static Texture2D texBackground;
static SpriteFont fontTitle; static Font fontTitle;
static Sound fxTyping; static Sound fxTyping;
static float titleSize; static float titleSize;
@ -71,7 +71,7 @@ void InitTitleScreen(void)
texBackground = LoadTexture("resources/textures/title_background.png"); texBackground = LoadTexture("resources/textures/title_background.png");
fxTyping = LoadSound("resources/audio/fx_typing.ogg"); fxTyping = LoadSound("resources/audio/fx_typing.ogg");
fontTitle = LoadSpriteFontEx("resources/fonts/mom_typewritter.ttf", 96, 0, 0); fontTitle = LoadFontEx("resources/fonts/mom_typewritter.ttf", 96, 0, 0);
titleSize = 44; titleSize = 44;
transmissionPosition = (Vector2){519, 221}; transmissionPosition = (Vector2){519, 221};
@ -148,7 +148,7 @@ void UnloadTitleScreen(void)
{ {
UnloadTexture(texBackground); UnloadTexture(texBackground);
UnloadSound(fxTyping); UnloadSound(fxTyping);
UnloadSpriteFont(fontTitle); UnloadFont(fontTitle);
} }
// Title Screen should finish? // Title Screen should finish?

View file

@ -76,7 +76,7 @@ Color textColorButton;
int currentMission; int currentMission;
int totalMissions; int totalMissions;
SpriteFont fontMission; Font fontMission;
Word messageWords[MAX_MISSION_WORDS]; Word messageWords[MAX_MISSION_WORDS];

View file

@ -70,7 +70,7 @@ int main(void)
SetMusicVolume(music, 1.0f); SetMusicVolume(music, 1.0f);
PlayMusicStream(music); PlayMusicStream(music);
fontMission = LoadSpriteFontEx("resources/fonts/traveling_typewriter.ttf", 64, 250, 0); fontMission = LoadFontEx("resources/fonts/traveling_typewriter.ttf", 64, 250, 0);
texButton = LoadTexture("resources/textures/title_ribbon.png"); texButton = LoadTexture("resources/textures/title_ribbon.png");
// UI BUTTON // UI BUTTON
@ -122,7 +122,7 @@ int main(void)
UnloadMusicStream(music); UnloadMusicStream(music);
UnloadSound(fxButton); UnloadSound(fxButton);
UnloadSpriteFont(fontMission); UnloadFont(fontMission);
UnloadTexture(texButton); UnloadTexture(texButton);
CloseAudioDevice(); // Close audio context CloseAudioDevice(); // Close audio context

View file

@ -35,7 +35,7 @@ typedef enum GameScreen { LOGO = 0, TITLE, GAMEPLAY, ENDING } GameScreen;
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
GameScreen currentScreen; GameScreen currentScreen;
SpriteFont font; Font font;
Music music; Music music;
int endingStatus; // 1 - Win, 2 - Lose int endingStatus; // 1 - Win, 2 - Lose

View file

@ -90,7 +90,7 @@ int main(int argc, char *argv[])
// Global data loading (assets that must be available in all screens, i.e. fonts) // Global data loading (assets that must be available in all screens, i.e. fonts)
InitAudioDevice(); InitAudioDevice();
font = LoadSpriteFont("resources/font.fnt"); font = LoadFont("resources/font.fnt");
music = LoadMusicStream("resources/audio/wave.ogg"); music = LoadMusicStream("resources/audio/wave.ogg");
SetMusicVolume(music, 1.0f); SetMusicVolume(music, 1.0f);
@ -127,7 +127,7 @@ int main(int argc, char *argv[])
} }
// Unload all global loaded data (i.e. fonts) here! // Unload all global loaded data (i.e. fonts) here!
UnloadSpriteFont(font); UnloadFont(font);
UnloadMusicStream(music); UnloadMusicStream(music);
CloseAudioDevice(); // Close audio context CloseAudioDevice(); // Close audio context

View file

@ -1,14 +1,12 @@
/********************************************************************************************** /**********************************************************************************************
* *
* raylib v1.9.6-dev * raylib - A simple and easy-to-use library to learn videogames programming (www.raylib.com)
*
* A simple and easy-to-use library to learn videogames programming (www.raylib.com)
* *
* FEATURES: * FEATURES:
* - Written in plain C code (C99) in PascalCase/camelCase notation * - Written in plain C code (C99) in PascalCase/camelCase notation
* - Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2 - choose at compile) * - Hardware accelerated with OpenGL (1.1, 2.1, 3.3 or ES2 - choose at compile)
* - Unique OpenGL abstraction layer (usable as standalone module): [rlgl] * - Unique OpenGL abstraction layer (usable as standalone module): [rlgl]
* - Powerful fonts module with SpriteFonts support (XNA fonts, AngelCode fonts, TTF) * - Powerful fonts module with Fonts support (XNA fonts, AngelCode fonts, TTF)
* - Outstanding texture formats support, including compressed formats (DXT, ETC, ASTC) * - Outstanding texture formats support, including compressed formats (DXT, ETC, ASTC)
* - Full 3d support for 3d Shapes, Models, Billboards, Heightmaps and more! * - Full 3d support for 3d Shapes, Models, Billboards, Heightmaps and more!
* - Flexible Materials system, supporting classic maps and PBR maps * - Flexible Materials system, supporting classic maps and PBR maps
@ -138,6 +136,9 @@
#define KEY_RIGHT_SHIFT 344 #define KEY_RIGHT_SHIFT 344
#define KEY_RIGHT_CONTROL 345 #define KEY_RIGHT_CONTROL 345
#define KEY_RIGHT_ALT 346 #define KEY_RIGHT_ALT 346
#define KEY_GRAVE 96
#define KEY_SLASH 47
#define KEY_BACKSLASH 92
// Keyboard Alpha Numeric Keys // Keyboard Alpha Numeric Keys
#define KEY_ZERO 48 #define KEY_ZERO 48
@ -348,10 +349,10 @@ typedef struct Color {
// Rectangle type // Rectangle type
typedef struct Rectangle { typedef struct Rectangle {
int x; float x;
int y; float y;
int width; float width;
int height; float height;
} Rectangle; } Rectangle;
// Image type, bpp always RGBA (32bit) // Image type, bpp always RGBA (32bit)
@ -381,7 +382,7 @@ typedef struct RenderTexture2D {
Texture2D depth; // Depth buffer attachment texture Texture2D depth; // Depth buffer attachment texture
} RenderTexture2D; } RenderTexture2D;
// SpriteFont character info // Font character info
typedef struct CharInfo { typedef struct CharInfo {
int value; // Character value (Unicode) int value; // Character value (Unicode)
Rectangle rec; // Character rectangle in sprite font Rectangle rec; // Character rectangle in sprite font
@ -390,28 +391,26 @@ typedef struct CharInfo {
int advanceX; // Character advance position X int advanceX; // Character advance position X
} CharInfo; } CharInfo;
// SpriteFont type, includes texture and charSet array data // Font type, includes texture and charSet array data
typedef struct SpriteFont { typedef struct Font {
Texture2D texture; // Font texture Texture2D texture; // Font texture
int baseSize; // Base size (default chars height) int baseSize; // Base size (default chars height)
int charsCount; // Number of characters int charsCount; // Number of characters
CharInfo *chars; // Characters info data CharInfo *chars; // Characters info data
} SpriteFont; } Font;
// Camera projection modes #define SpriteFont Font // SpriteFont type fallback, defaults to Font
typedef enum {
CAMERA_PERSPECTIVE = 0,
CAMERA_ORTHOGRAPHIC
} CameraType;
// Camera type, defines a camera position/orientation in 3d space // Camera type, defines a camera position/orientation in 3d space
typedef struct Camera { typedef struct Camera3D {
Vector3 position; // Camera position Vector3 position; // Camera position
Vector3 target; // Camera target it looks-at Vector3 target; // Camera target it looks-at
Vector3 up; // Camera up vector (rotation over its axis) Vector3 up; // Camera up vector (rotation over its axis)
float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic float fovy; // Camera field-of-view apperture in Y (degrees) in perspective, used as near plane width in orthographic
CameraType type; // Camera type, controlling projection type, either CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC. int type; // Camera type, defines projection type: CAMERA_PERSPECTIVE or CAMERA_ORTHOGRAPHIC
} Camera; } Camera3D;
#define Camera Camera3D // Camera type fallback, defaults to Camera3D
// Camera2D type, defines a 2d camera // Camera2D type, defines a 2d camera
typedef struct Camera2D { typedef struct Camera2D {
@ -675,6 +674,12 @@ typedef enum {
CAMERA_THIRD_PERSON CAMERA_THIRD_PERSON
} CameraMode; } CameraMode;
// Camera projection modes
typedef enum {
CAMERA_PERSPECTIVE = 0,
CAMERA_ORTHOGRAPHIC
} CameraType;
// Head Mounted Display devices // Head Mounted Display devices
typedef enum { typedef enum {
HMD_DEFAULT_DEVICE = 0, HMD_DEFAULT_DEVICE = 0,
@ -725,10 +730,10 @@ RLAPI void DisableCursor(void); // Disables cu
RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color) RLAPI void ClearBackground(Color color); // Set background color (framebuffer clear color)
RLAPI void BeginDrawing(void); // Setup canvas (framebuffer) to start drawing RLAPI void BeginDrawing(void); // Setup canvas (framebuffer) to start drawing
RLAPI void EndDrawing(void); // End canvas drawing and swap buffers (double buffering) RLAPI void EndDrawing(void); // End canvas drawing and swap buffers (double buffering)
RLAPI void Begin2dMode(Camera2D camera); // Initialize 2D mode with custom camera (2D) RLAPI void BeginMode2D(Camera2D camera); // Initialize 2D mode with custom camera (2D)
RLAPI void End2dMode(void); // Ends 2D mode with custom camera RLAPI void EndMode2D(void); // Ends 2D mode with custom camera
RLAPI void Begin3dMode(Camera camera); // Initializes 3D mode with custom camera (3D) RLAPI void BeginMode3D(Camera3D camera); // Initializes 3D mode with custom camera (3D)
RLAPI void End3dMode(void); // Ends 3D mode and returns to default 2D orthographic mode RLAPI void EndMode3D(void); // Ends 3D mode and returns to default 2D orthographic mode
RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing RLAPI void BeginTextureMode(RenderTexture2D target); // Initializes render texture for drawing
RLAPI void EndTextureMode(void); // Ends drawing to render texture RLAPI void EndTextureMode(void); // Ends drawing to render texture
@ -744,8 +749,8 @@ RLAPI float GetFrameTime(void); // Returns tim
RLAPI double GetTime(void); // Returns elapsed time in seconds since InitWindow() RLAPI double GetTime(void); // Returns elapsed time in seconds since InitWindow()
// Color-related functions // Color-related functions
RLAPI float *ColorToFloat(Color color); // Returns normalized float array for a Color
RLAPI int ColorToInt(Color color); // Returns hexadecimal value for a Color RLAPI int ColorToInt(Color color); // Returns hexadecimal value for a Color
RLAPI Vector4 ColorNormalize(Color color); // Returns color normalized as float [0..1]
RLAPI Vector3 ColorToHSV(Color color); // Returns HSV values for a Color RLAPI Vector3 ColorToHSV(Color color); // Returns HSV values for a Color
RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value RLAPI Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value
RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f RLAPI Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f
@ -836,9 +841,7 @@ RLAPI void UpdateCamera(Camera *camera); // Update came
RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera) RLAPI void SetCameraPanControl(int panKey); // Set camera pan key to combine with mouse movement (free camera)
RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera) RLAPI void SetCameraAltControl(int altKey); // Set camera alt key to combine with mouse movement (free camera)
RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera) RLAPI void SetCameraSmoothZoomControl(int szKey); // Set camera smooth zoom key to combine with mouse (free camera)
RLAPI void SetCameraMoveControls(int frontKey, int backKey, RLAPI void SetCameraMoveControls(int frontKey, int backKey, int rightKey, int leftKey, int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
int rightKey, int leftKey,
int upKey, int downKey); // Set camera move controls (1st person and 3rd person cameras)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Basic Shapes Drawing Functions (Module: shapes) // Basic Shapes Drawing Functions (Module: shapes)
@ -888,6 +891,7 @@ RLAPI Image LoadImage(const char *fileName);
RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image from Color array data (RGBA - 32bit) RLAPI Image LoadImageEx(Color *pixels, int width, int height); // Load image from Color array data (RGBA - 32bit)
RLAPI Image LoadImagePro(void *data, int width, int height, int format); // Load image from raw data with parameters RLAPI Image LoadImagePro(void *data, int width, int height, int format); // Load image from raw data with parameters
RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data RLAPI Image LoadImageRaw(const char *fileName, int width, int height, int format, int headerSize); // Load image from RAW file data
RLAPI void ExportImage(const char *fileName, Image image); // Export image as a PNG file
RLAPI Texture2D LoadTexture(const char *fileName); // Load texture from file into GPU memory (VRAM) RLAPI Texture2D LoadTexture(const char *fileName); // Load texture from file into GPU memory (VRAM)
RLAPI Texture2D LoadTextureFromImage(Image image); // Load texture from image data RLAPI Texture2D LoadTextureFromImage(Image image); // Load texture from image data
RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load texture for rendering (framebuffer) RLAPI RenderTexture2D LoadRenderTexture(int width, int height); // Load texture for rendering (framebuffer)
@ -898,7 +902,6 @@ RLAPI Color *GetImageData(Image image);
RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture) RLAPI int GetPixelDataSize(int width, int height, int format); // Get pixel data size in bytes (image or texture)
RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image RLAPI Image GetTextureData(Texture2D texture); // Get pixel data from GPU texture and return an Image
RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data RLAPI void UpdateTexture(Texture2D texture, const void *pixels); // Update GPU texture with new data
RLAPI void SaveImageAs(const char *fileName, Image image); // Save image to a PNG file
// Image manipulation functions // Image manipulation functions
RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations) RLAPI Image ImageCopy(Image image); // Create an image duplicate (useful for transformations)
@ -914,11 +917,11 @@ RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight);
RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image
RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font)
RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, int spacing, Color tint); // Create an image from text (custom sprite font) RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font)
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image
RLAPI void ImageDrawRectangle(Image *dst, Vector2 position, Rectangle rec, Color color); // Draw rectangle within an image
RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination)
RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color color); // Draw text (custom sprite font) within an image (destination)
float fontSize, int spacing, Color color); // Draw text (custom sprite font) within an image (destination)
RLAPI void ImageFlipVertical(Image *image); // Flip image vertically RLAPI void ImageFlipVertical(Image *image); // Flip image vertically
RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally
RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint
@ -947,31 +950,30 @@ RLAPI void DrawTexture(Texture2D texture, int posX, int posY, Color tint);
RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2 RLAPI void DrawTextureV(Texture2D texture, Vector2 position, Color tint); // Draw a Texture2D with position defined as Vector2
RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters RLAPI void DrawTextureEx(Texture2D texture, Vector2 position, float rotation, float scale, Color tint); // Draw a Texture2D with extended parameters
RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle RLAPI void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Color tint); // Draw a part of a texture defined by a rectangle
RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, // Draw a part of a texture defined by a rectangle with 'pro' parameters RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters
float rotation, Color tint);
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Font Loading and Text Drawing Functions (Module: text) // Font Loading and Text Drawing Functions (Module: text)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// SpriteFont loading/unloading functions // Font loading/unloading functions
RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont RLAPI Font GetDefaultFont(void); // Get the default Font
RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load SpriteFont from file into GPU memory (VRAM) RLAPI Font LoadFont(const char *fileName); // Load Font from file into GPU memory (VRAM)
RLAPI SpriteFont LoadSpriteFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load SpriteFont from file with extended parameters RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load Font from file with extended parameters
RLAPI void UnloadSpriteFont(SpriteFont font); // Unload SpriteFont from GPU memory (VRAM) RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM)
// Text drawing functions // Text drawing functions
RLAPI void DrawFPS(int posX, int posY); // Shows current FPS RLAPI void DrawFPS(int posX, int posY); // Shows current FPS
RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
RLAPI void DrawTextEx(SpriteFont font, const char* text, Vector2 position, // Draw text using SpriteFont and additional parameters RLAPI void DrawTextEx(Font font, const char* text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using Font and additional parameters
float fontSize, int spacing, Color tint);
// Text misc. functions // Text misc. functions
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(SpriteFont font, const char *text, float fontSize, int spacing); // Measure string size for SpriteFont RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font
RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string
RLAPI int GetGlyphIndex(SpriteFont font, int character); // Returns index position for a unicode character on sprite font RLAPI int GetGlyphIndex(Font font, int character); // Returns index position for a unicode character on sprite font
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Basic 3d Shapes Drawing Functions (Module: models) // Basic 3d Shapes Drawing Functions (Module: models)
@ -1007,6 +1009,7 @@ RLAPI void UnloadModel(Model model);
// Mesh loading/unloading functions // Mesh loading/unloading functions
RLAPI Mesh LoadMesh(const char *fileName); // Load mesh from file RLAPI Mesh LoadMesh(const char *fileName); // Load mesh from file
RLAPI void UnloadMesh(Mesh *mesh); // Unload mesh from memory (RAM and/or VRAM) RLAPI void UnloadMesh(Mesh *mesh); // Unload mesh from memory (RAM and/or VRAM)
RLAPI void ExportMesh(const char *fileName, Mesh mesh); // Export mesh as an OBJ file
// Mesh manipulation functions // Mesh manipulation functions
RLAPI BoundingBox MeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits RLAPI BoundingBox MeshBoundingBox(Mesh mesh); // Compute mesh bounding box limits
@ -1031,25 +1034,21 @@ RLAPI void UnloadMaterial(Material material);
// Model drawing functions // Model drawing functions
RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set) RLAPI void DrawModel(Model model, Vector3 position, float scale, Color tint); // Draw a model (with texture if set)
RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, RLAPI void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
float rotationAngle, Vector3 scale, Color tint); // Draw a model with extended parameters
RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set) RLAPI void DrawModelWires(Model model, Vector3 position, float scale, Color tint); // Draw a model wires (with texture if set)
RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, RLAPI void DrawModelWiresEx(Model model, Vector3 position, Vector3 rotationAxis, float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
float rotationAngle, Vector3 scale, Color tint); // Draw a model wires (with texture if set) with extended parameters
RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires) RLAPI void DrawBoundingBox(BoundingBox box, Color color); // Draw bounding box (wires)
RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture RLAPI void DrawBillboard(Camera camera, Texture2D texture, Vector3 center, float size, Color tint); // Draw a billboard texture
RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, RLAPI void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec
Vector3 center, float size, Color tint); // Draw a billboard texture defined by sourceRec
// Collision detection functions // Collision detection functions
RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres RLAPI bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres
RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes RLAPI bool CheckCollisionBoxes(BoundingBox box1, BoundingBox box2); // Detect collision between two bounding boxes
RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere RLAPI bool CheckCollisionBoxSphere(BoundingBox box, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere
RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere RLAPI bool CheckCollisionRaySphere(Ray ray, Vector3 spherePosition, float sphereRadius); // Detect collision between ray and sphere
RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, RLAPI bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadius, Vector3 *collisionPoint); // Detect collision between ray and sphere, returns collision point
Vector3 *collisionPoint); // Detect collision between ray and sphere, returns collision point
RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box RLAPI bool CheckCollisionRayBox(Ray ray, BoundingBox box); // Detect collision between ray and box
RLAPI RayHitInfo GetCollisionRayMesh(Ray ray, Mesh *mesh); // Get collision info between ray and mesh RLAPI RayHitInfo GetCollisionRayModel(Ray ray, Model *model); // Get collision info between ray and model
RLAPI RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3); // Get collision info between ray and triangle RLAPI RayHitInfo GetCollisionRayTriangle(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3); // Get collision info between ray and triangle
RLAPI RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight); // Get collision info between ray and ground plane (Y-normal plane) RLAPI RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight); // Get collision info between ray and ground plane (Y-normal plane)
@ -1148,8 +1147,7 @@ RLAPI float GetMusicTimeLength(Music music); // Get mus
RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds) RLAPI float GetMusicTimePlayed(Music music); // Get current music time played (in seconds)
// AudioStream management functions // AudioStream management functions
RLAPI AudioStream InitAudioStream(unsigned int sampleRate, unsigned int sampleSize, RLAPI AudioStream InitAudioStream(unsigned int sampleRate, 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)
RLAPI void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data RLAPI void UpdateAudioStream(AudioStream stream, const void *data, int samplesCount); // Update audio stream buffers with data
RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory RLAPI void CloseAudioStream(AudioStream stream); // Close audio stream and free memory
RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill RLAPI bool IsAudioBufferProcessed(AudioStream stream); // Check if any audio stream buffers requires refill

View file

@ -24,6 +24,7 @@
* #define SUPPORT_FILEFORMAT_XM * #define SUPPORT_FILEFORMAT_XM
* #define SUPPORT_FILEFORMAT_MOD * #define SUPPORT_FILEFORMAT_MOD
* #define SUPPORT_FILEFORMAT_FLAC * #define SUPPORT_FILEFORMAT_FLAC
* #define SUPPORT_FILEFORMAT_MP3
* 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
* *
@ -127,6 +128,11 @@
#include "external/dr_flac.h" // FLAC loading functions #include "external/dr_flac.h" // FLAC loading functions
#endif #endif
#if defined(SUPPORT_FILEFORMAT_MP3)
#define DR_MP3_IMPLEMENTATION
#include "external/dr_mp3.h" // MP3 loading functions
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#undef bool #undef bool
#endif #endif

View file

@ -25,7 +25,7 @@
* *
**********************************************************************************************/ **********************************************************************************************/
#define RAYLIB_VERSION "1.9.7-dev" #define RAYLIB_VERSION "2.0-dev"
// Edit to control what features Makefile'd raylib is compiled with // Edit to control what features Makefile'd raylib is compiled with
#if defined(RAYLIB_CMAKE) #if defined(RAYLIB_CMAKE)
@ -124,6 +124,7 @@
#define SUPPORT_FILEFORMAT_XM 1 #define SUPPORT_FILEFORMAT_XM 1
#define SUPPORT_FILEFORMAT_MOD 1 #define SUPPORT_FILEFORMAT_MOD 1
//#define SUPPORT_FILEFORMAT_FLAC 1 //#define SUPPORT_FILEFORMAT_FLAC 1
//#define SUPPORT_FILEFORMAT_MP3 1
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------

2841
src/external/dr_mp3.h vendored Normal file

File diff suppressed because it is too large Load diff

View file

@ -382,7 +382,7 @@ typedef struct RenderTexture2D {
Texture2D depth; // Depth buffer attachment texture Texture2D depth; // Depth buffer attachment texture
} RenderTexture2D; } RenderTexture2D;
// SpriteFont character info // Font character info
typedef struct CharInfo { typedef struct CharInfo {
int value; // Character value (Unicode) int value; // Character value (Unicode)
Rectangle rec; // Character rectangle in sprite font Rectangle rec; // Character rectangle in sprite font
@ -391,13 +391,15 @@ typedef struct CharInfo {
int advanceX; // Character advance position X int advanceX; // Character advance position X
} CharInfo; } CharInfo;
// SpriteFont type, includes texture and charSet array data // Font type, includes texture and charSet array data
typedef struct SpriteFont { typedef struct Font {
Texture2D texture; // Font texture Texture2D texture; // Font texture
int baseSize; // Base size (default chars height) int baseSize; // Base size (default chars height)
int charsCount; // Number of characters int charsCount; // Number of characters
CharInfo *chars; // Characters info data CharInfo *chars; // Characters info data
} SpriteFont; } Font;
#define SpriteFont Font // SpriteFont type fallback, defaults to Font
// Camera type, defines a camera position/orientation in 3d space // Camera type, defines a camera position/orientation in 3d space
typedef struct Camera3D { typedef struct Camera3D {
@ -915,11 +917,11 @@ RLAPI void ImageResizeNN(Image *image,int newWidth,int newHeight);
RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image RLAPI void ImageMipmaps(Image *image); // Generate all mipmap levels for a provided image
RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering) RLAPI void ImageDither(Image *image, int rBpp, int gBpp, int bBpp, int aBpp); // Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font) RLAPI Image ImageText(const char *text, int fontSize, Color color); // Create an image from text (default font)
RLAPI Image ImageTextEx(SpriteFont font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font) RLAPI Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint); // Create an image from text (custom sprite font)
RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image RLAPI void ImageDraw(Image *dst, Image src, Rectangle srcRec, Rectangle dstRec); // Draw a source image within a destination image
RLAPI void ImageDrawRectangle(Image *dst, Vector2 position, Rectangle rec, Color color); // Draw rectangle within an image RLAPI void ImageDrawRectangle(Image *dst, Vector2 position, Rectangle rec, Color color); // Draw rectangle within an image
RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination) RLAPI void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize, Color color); // Draw text (default font) within an image (destination)
RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, float spacing, Color color); // Draw text (custom sprite font) within an image (destination) RLAPI void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color color); // Draw text (custom sprite font) within an image (destination)
RLAPI void ImageFlipVertical(Image *image); // Flip image vertically RLAPI void ImageFlipVertical(Image *image); // Flip image vertically
RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally RLAPI void ImageFlipHorizontal(Image *image); // Flip image horizontally
RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint RLAPI void ImageColorTint(Image *image, Color color); // Modify image color: tint
@ -955,23 +957,23 @@ RLAPI void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle dest
// Font Loading and Text Drawing Functions (Module: text) // Font Loading and Text Drawing Functions (Module: text)
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// SpriteFont loading/unloading functions // Font loading/unloading functions
RLAPI SpriteFont GetDefaultFont(void); // Get the default SpriteFont RLAPI Font GetDefaultFont(void); // Get the default Font
RLAPI SpriteFont LoadSpriteFont(const char *fileName); // Load SpriteFont from file into GPU memory (VRAM) RLAPI Font LoadFont(const char *fileName); // Load Font from file into GPU memory (VRAM)
RLAPI SpriteFont LoadSpriteFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load SpriteFont from file with extended parameters RLAPI Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load Font from file with extended parameters
RLAPI void UnloadSpriteFont(SpriteFont font); // Unload SpriteFont from GPU memory (VRAM) RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM)
// Text drawing functions // Text drawing functions
RLAPI void DrawFPS(int posX, int posY); // Shows current FPS RLAPI void DrawFPS(int posX, int posY); // Shows current FPS
RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font) RLAPI void DrawText(const char *text, int posX, int posY, int fontSize, Color color); // Draw text (using default font)
RLAPI void DrawTextEx(SpriteFont font, const char* text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using SpriteFont and additional parameters RLAPI void DrawTextEx(Font font, const char* text, Vector2 position, float fontSize, float spacing, Color tint); // Draw text using Font and additional parameters
// Text misc. functions // Text misc. functions
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(SpriteFont font, const char *text, float fontSize, float spacing); // Measure string size for SpriteFont RLAPI Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // Measure string size for Font
RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed' RLAPI const char *FormatText(const char *text, ...); // Formatting of text with variables to 'embed'
RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string RLAPI const char *SubText(const char *text, int position, int length); // Get a piece of a text string
RLAPI int GetGlyphIndex(SpriteFont font, int character); // Returns index position for a unicode character on sprite font RLAPI int GetGlyphIndex(Font font, int character); // Returns index position for a unicode character on sprite font
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Basic 3d Shapes Drawing Functions (Module: models) // Basic 3d Shapes Drawing Functions (Module: models)

View file

@ -1,6 +1,6 @@
/********************************************************************************************** /**********************************************************************************************
* *
* raylib.text - Basic functions to load SpriteFonts and draw Text * raylib.text - Basic functions to load Fonts and draw Text
* *
* CONFIGURATION: * CONFIGURATION:
* *
@ -73,7 +73,7 @@
// Global variables // Global variables
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
#if defined(SUPPORT_DEFAULT_FONT) #if defined(SUPPORT_DEFAULT_FONT)
static SpriteFont defaultFont; // Default font provided by raylib static Font defaultFont; // Default font provided by raylib
// NOTE: defaultFont is loaded on InitWindow and disposed on CloseWindow [module: core] // NOTE: defaultFont is loaded on InitWindow and disposed on CloseWindow [module: core]
#endif #endif
@ -85,12 +85,12 @@ static SpriteFont defaultFont; // Default font provided by raylib
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Module specific Functions Declaration // Module specific Functions Declaration
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
static SpriteFont LoadImageFont(Image image, Color key, int firstChar); // Load a Image font file (XNA style) static Font LoadImageFont(Image image, Color key, int firstChar); // Load a Image font file (XNA style)
#if defined(SUPPORT_FILEFORMAT_FNT) #if defined(SUPPORT_FILEFORMAT_FNT)
static SpriteFont LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file) static Font LoadBMFont(const char *fileName); // Load a BMFont file (AngelCode font file)
#endif #endif
#if defined(SUPPORT_FILEFORMAT_TTF) #if defined(SUPPORT_FILEFORMAT_TTF)
static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load spritefont from TTF data static Font LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars); // Load spritefont from TTF data
#endif #endif
#if defined(SUPPORT_DEFAULT_FONT) #if defined(SUPPORT_DEFAULT_FONT)
@ -114,7 +114,7 @@ extern void LoadDefaultFont(void)
defaultFont.charsCount = 224; // Number of chars included in our default font defaultFont.charsCount = 224; // Number of chars included in our default font
// Default font is directly defined here (data generated from a sprite font image) // Default font is directly defined here (data generated from a sprite font image)
// This way, we reconstruct SpriteFont without creating large global variables // This way, we reconstruct Font without creating large global variables
// This data is automatically allocated to Stack and automatically deallocated at the end of this function // This data is automatically allocated to Stack and automatically deallocated at the end of this function
int defaultFontData[512] = { int defaultFontData[512] = {
0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00200020, 0x0001b000, 0x00000000, 0x00000000, 0x8ef92520, 0x00020a00, 0x7dbe8000, 0x1f7df45f, 0x00000000, 0x00000000, 0x00000000, 0x00000000, 0x00200020, 0x0001b000, 0x00000000, 0x00000000, 0x8ef92520, 0x00020a00, 0x7dbe8000, 0x1f7df45f,
@ -261,28 +261,28 @@ extern void UnloadDefaultFont(void)
#endif // SUPPORT_DEFAULT_FONT #endif // SUPPORT_DEFAULT_FONT
// Get the default font, useful to be used with extended parameters // Get the default font, useful to be used with extended parameters
SpriteFont GetDefaultFont() Font GetDefaultFont()
{ {
#if defined(SUPPORT_DEFAULT_FONT) #if defined(SUPPORT_DEFAULT_FONT)
return defaultFont; return defaultFont;
#else #else
SpriteFont font = { 0 }; Font font = { 0 };
return font; return font;
#endif #endif
} }
// Load SpriteFont from file into GPU memory (VRAM) // Load Font from file into GPU memory (VRAM)
SpriteFont LoadSpriteFont(const char *fileName) Font LoadFont(const char *fileName)
{ {
// Default hardcoded values for ttf file loading // Default hardcoded values for ttf file loading
#define DEFAULT_TTF_FONTSIZE 32 // Font first character (32 - space) #define DEFAULT_TTF_FONTSIZE 32 // Font first character (32 - space)
#define DEFAULT_TTF_NUMCHARS 95 // ASCII 32..126 is 95 glyphs #define DEFAULT_TTF_NUMCHARS 95 // ASCII 32..126 is 95 glyphs
#define DEFAULT_FIRST_CHAR 32 // Expected first char for image spritefont #define DEFAULT_FIRST_CHAR 32 // Expected first char for image spritefont
SpriteFont spriteFont = { 0 }; Font spriteFont = { 0 };
#if defined(SUPPORT_FILEFORMAT_TTF) #if defined(SUPPORT_FILEFORMAT_TTF)
if (IsFileExtension(fileName, ".ttf")) spriteFont = LoadSpriteFontEx(fileName, DEFAULT_TTF_FONTSIZE, 0, NULL); if (IsFileExtension(fileName, ".ttf")) spriteFont = LoadFontEx(fileName, DEFAULT_TTF_FONTSIZE, 0, NULL);
else else
#endif #endif
#if defined(SUPPORT_FILEFORMAT_FNT) #if defined(SUPPORT_FILEFORMAT_FNT)
@ -297,7 +297,7 @@ SpriteFont LoadSpriteFont(const char *fileName)
if (spriteFont.texture.id == 0) if (spriteFont.texture.id == 0)
{ {
TraceLog(LOG_WARNING, "[%s] SpriteFont could not be loaded, using default font", fileName); TraceLog(LOG_WARNING, "[%s] Font could not be loaded, using default font", fileName);
spriteFont = GetDefaultFont(); spriteFont = GetDefaultFont();
} }
else SetTextureFilter(spriteFont.texture, FILTER_POINT); // By default we set point filter (best performance) else SetTextureFilter(spriteFont.texture, FILTER_POINT); // By default we set point filter (best performance)
@ -305,12 +305,12 @@ SpriteFont LoadSpriteFont(const char *fileName)
return spriteFont; return spriteFont;
} }
// Load SpriteFont from TTF font file with generation parameters // Load Font from TTF font file with generation parameters
// NOTE: You can pass an array with desired characters, those characters should be available in the font // NOTE: You can pass an array with desired characters, those characters should be available in the font
// if array is NULL, default char set is selected 32..126 // if array is NULL, default char set is selected 32..126
SpriteFont LoadSpriteFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars) Font LoadFontEx(const char *fileName, int fontSize, int charsCount, int *fontChars)
{ {
SpriteFont spriteFont = { 0 }; Font spriteFont = { 0 };
int totalChars = 95; // Default charset [32..126] int totalChars = 95; // Default charset [32..126]
#if defined(SUPPORT_FILEFORMAT_TTF) #if defined(SUPPORT_FILEFORMAT_TTF)
@ -330,15 +330,15 @@ SpriteFont LoadSpriteFontEx(const char *fileName, int fontSize, int charsCount,
if (spriteFont.texture.id == 0) if (spriteFont.texture.id == 0)
{ {
TraceLog(LOG_WARNING, "[%s] SpriteFont could not be generated, using default font", fileName); TraceLog(LOG_WARNING, "[%s] Font could not be generated, using default font", fileName);
spriteFont = GetDefaultFont(); spriteFont = GetDefaultFont();
} }
return spriteFont; return spriteFont;
} }
// Unload SpriteFont from GPU memory (VRAM) // Unload Font from GPU memory (VRAM)
void UnloadSpriteFont(SpriteFont font) void UnloadFont(Font font)
{ {
// NOTE: Make sure spriteFont is not default font (fallback) // NOTE: Make sure spriteFont is not default font (fallback)
if (font.texture.id != GetDefaultFont().texture.id) if (font.texture.id != GetDefaultFont().texture.id)
@ -368,9 +368,9 @@ void DrawText(const char *text, int posX, int posY, int fontSize, Color color)
} }
} }
// Draw text using SpriteFont // Draw text using Font
// NOTE: chars spacing is NOT proportional to fontSize // NOTE: chars spacing is NOT proportional to fontSize
void DrawTextEx(SpriteFont font, const char *text, Vector2 position, float fontSize, float spacing, Color tint) void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint)
{ {
int length = strlen(text); int length = strlen(text);
int textOffsetX = 0; // Offset between characters int textOffsetX = 0; // Offset between characters
@ -482,8 +482,8 @@ int MeasureText(const char *text, int fontSize)
return (int)vec.x; return (int)vec.x;
} }
// Measure string size for SpriteFont // Measure string size for Font
Vector2 MeasureTextEx(SpriteFont font, const char *text, float fontSize, float spacing) Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing)
{ {
int len = strlen(text); int len = strlen(text);
int tempLen = 0; // Used to count longer text line num chars int tempLen = 0; // Used to count longer text line num chars
@ -527,7 +527,7 @@ Vector2 MeasureTextEx(SpriteFont font, const char *text, float fontSize, float s
} }
// Returns index position for a unicode character on spritefont // Returns index position for a unicode character on spritefont
int GetGlyphIndex(SpriteFont font, int character) int GetGlyphIndex(Font font, int character)
{ {
#define UNORDERED_CHARSET #define UNORDERED_CHARSET
#if defined(UNORDERED_CHARSET) #if defined(UNORDERED_CHARSET)
@ -575,7 +575,7 @@ void DrawFPS(int posX, int posY)
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Load an Image font file (XNA style) // Load an Image font file (XNA style)
static SpriteFont LoadImageFont(Image image, Color key, int firstChar) static Font LoadImageFont(Image image, Color key, int firstChar)
{ {
#define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a)) #define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a))
@ -648,7 +648,7 @@ static SpriteFont LoadImageFont(Image image, Color key, int firstChar)
xPosToRead = charSpacing; xPosToRead = charSpacing;
} }
TraceLog(LOG_DEBUG, "SpriteFont data parsed correctly from image"); TraceLog(LOG_DEBUG, "Font data parsed correctly from image");
// NOTE: We need to remove key color borders from image to avoid weird // NOTE: We need to remove key color borders from image to avoid weird
// artifacts on texture scaling when using FILTER_BILINEAR or FILTER_TRILINEAR // artifacts on texture scaling when using FILTER_BILINEAR or FILTER_TRILINEAR
@ -660,7 +660,7 @@ static SpriteFont LoadImageFont(Image image, Color key, int firstChar)
free(pixels); // Free pixels array memory free(pixels); // Free pixels array memory
// Create spritefont with all data parsed from image // Create spritefont with all data parsed from image
SpriteFont spriteFont = { 0 }; Font spriteFont = { 0 };
spriteFont.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture spriteFont.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture
spriteFont.charsCount = index; spriteFont.charsCount = index;
@ -684,18 +684,18 @@ static SpriteFont LoadImageFont(Image image, Color key, int firstChar)
spriteFont.baseSize = spriteFont.chars[0].rec.height; spriteFont.baseSize = spriteFont.chars[0].rec.height;
TraceLog(LOG_INFO, "Image file loaded correctly as SpriteFont"); TraceLog(LOG_INFO, "Image file loaded correctly as Font");
return spriteFont; return spriteFont;
} }
#if defined(SUPPORT_FILEFORMAT_FNT) #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 Font LoadBMFont(const char *fileName)
{ {
#define MAX_BUFFER_SIZE 256 #define MAX_BUFFER_SIZE 256
SpriteFont font = { 0 }; Font font = { 0 };
font.texture.id = 0; font.texture.id = 0;
char buffer[MAX_BUFFER_SIZE]; char buffer[MAX_BUFFER_SIZE];
@ -800,10 +800,10 @@ static SpriteFont LoadBMFont(const char *fileName)
if (font.texture.id == 0) if (font.texture.id == 0)
{ {
UnloadSpriteFont(font); UnloadFont(font);
font = GetDefaultFont(); font = GetDefaultFont();
} }
else TraceLog(LOG_INFO, "[%s] SpriteFont loaded successfully", fileName); else TraceLog(LOG_INFO, "[%s] Font loaded successfully", fileName);
return font; return font;
} }
@ -812,7 +812,7 @@ static SpriteFont LoadBMFont(const char *fileName)
#if defined(SUPPORT_FILEFORMAT_TTF) #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 Font LoadTTF(const char *fileName, int fontSize, int charsCount, int *fontChars)
{ {
#define MAX_TTF_SIZE 16 // Maximum ttf file size in MB #define MAX_TTF_SIZE 16 // Maximum ttf file size in MB
@ -830,7 +830,7 @@ static SpriteFont LoadTTF(const char *fileName, int fontSize, int charsCount, in
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);
SpriteFont font = { 0 }; Font font = { 0 };
FILE *ttfFile = fopen(fileName, "rb"); FILE *ttfFile = fopen(fileName, "rb");

View file

@ -1371,7 +1371,7 @@ Image ImageText(const char *text, int fontSize, Color color)
} }
// Create an image from text (custom sprite font) // Create an image from text (custom sprite font)
Image ImageTextEx(SpriteFont font, const char *text, float fontSize, float spacing, Color tint) Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint)
{ {
int length = strlen(text); int length = strlen(text);
int posX = 0; int posX = 0;
@ -1385,7 +1385,7 @@ Image ImageTextEx(SpriteFont font, const char *text, float fontSize, float spaci
// NOTE: glGetTexImage() not available in OpenGL ES // NOTE: glGetTexImage() not available in OpenGL ES
// TODO: This is horrible, retrieving font texture from GPU!!! // TODO: This is horrible, retrieving font texture from GPU!!!
// Define ImageFont struct? or include Image spritefont in SpriteFont struct? // Define ImageFont struct? or include Image spritefont in Font struct?
Image imFont = GetTextureData(font.texture); Image imFont = GetTextureData(font.texture);
ImageColorTint(&imFont, tint); // Apply color tint to font ImageColorTint(&imFont, tint); // Apply color tint to font
@ -1466,7 +1466,7 @@ void ImageDrawText(Image *dst, Vector2 position, const char *text, int fontSize,
} }
// Draw text (custom sprite font) within an image (destination) // Draw text (custom sprite font) within an image (destination)
void ImageDrawTextEx(Image *dst, Vector2 position, SpriteFont font, const char *text, float fontSize, float spacing, Color color) void ImageDrawTextEx(Image *dst, Vector2 position, Font font, const char *text, float fontSize, float spacing, Color color)
{ {
Image imText = ImageTextEx(font, text, fontSize, spacing, color); Image imText = ImageTextEx(font, text, fontSize, spacing, color);

View file

@ -58,7 +58,7 @@ int main(void)
// Global data loading (assets that must be available in all screens, i.e. fonts) // Global data loading (assets that must be available in all screens, i.e. fonts)
InitAudioDevice(); InitAudioDevice();
font = LoadSpriteFont("resources/mecha.png"); font = LoadFont("resources/mecha.png");
music = LoadMusicStream("resources/ambient.ogg"); music = LoadMusicStream("resources/ambient.ogg");
fxCoin = LoadSound("resources/coin.wav"); fxCoin = LoadSound("resources/coin.wav");
@ -96,7 +96,7 @@ int main(void)
} }
// Unload all global loaded data (i.e. fonts) here! // Unload all global loaded data (i.e. fonts) here!
UnloadSpriteFont(font); UnloadFont(font);
UnloadMusicStream(music); UnloadMusicStream(music);
UnloadSound(fxCoin); UnloadSound(fxCoin);

View file

@ -35,7 +35,7 @@ typedef enum GameScreen { LOGO = 0, TITLE, OPTIONS, GAMEPLAY, ENDING } GameScree
// Global Variables Definition // Global Variables Definition
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
GameScreen currentScreen; GameScreen currentScreen;
SpriteFont font; Font font;
Music music; Music music;
Sound fxCoin; Sound fxCoin;