Examples reviewed

This commit is contained in:
raysan5 2015-08-27 16:13:31 +02:00
parent 8745d733f9
commit 997170a317
10 changed files with 107 additions and 136 deletions

View file

@ -7,7 +7,7 @@
* This example has been created using raylib 1.1 (www.raylib.com) * This example has been created using raylib 1.1 (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)
* *
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
@ -58,7 +58,12 @@ int main()
SetMusicVolume(volume); SetMusicVolume(volume);
} }
*/ */
if (IsWindowMinimized()) PauseMusicStream();
else ResumeMusicStream();
timePlayed = GetMusicTimePlayed() / GetMusicTimeLength() * 100 * 4; // We scale by 4 to fit 400 pixels timePlayed = GetMusicTimePlayed() / GetMusicTimeLength() * 100 * 4; // We scale by 4 to fit 400 pixels
UpdateMusicStream();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw

View file

@ -1,11 +1,8 @@
/******************************************************************************************* /*******************************************************************************************
* *
* raylib [textures] example - DDS Texture loading and drawing (compressed and uncompressed) * raylib [core] example - Picking in 3d mode
* *
* NOTE: This example requires raylib OpenGL 3.3+ or ES2 versions for compressed texture, * This example has been created using raylib 1.0 (www.raylib.com)
* OpenGL 1.1 does not support compressed textures, only uncompressed version.
*
* This example has been created using raylib 1.2 (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)
* *
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
@ -21,33 +18,48 @@ int main()
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 450; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - DDS texture loading and drawing"); InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d picking");
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // Define the camera to look into our 3d world
Camera camera = {{ 0.0, 10.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }};
Texture2D texture = LoadTexture("resources/raylib_logo.dds"); // Texture loading (compressed) Vector3 cubePosition = { 0.0, 0.0, 0.0 };
SetTargetFPS(60); // Set our game to run at 60 frames-per-second Ray pickingLine;
//---------------------------------------------------------------------------------------
SetCameraMode(CAMERA_FREE);
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
// Main game loop // Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key while (!WindowShouldClose()) // Detect window close button or ESC key
{ {
// Update // Update
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// TODO: Update your variables here camera = UpdateCamera(0);
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pickingLine = GetMouseRay(GetMousePosition(), camera);
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
// Draw // Draw
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2, screenHeight/2 - texture.height/2, WHITE); Begin3dMode(camera);
DrawText("this may be a compressed texture!", 320, 370, 10, GRAY); DrawCube(cubePosition, 2, 2, 2, RED);
DrawCubeWires(cubePosition, 2, 2, 2, MAROON);
DrawGrid(10.0, 1.0);
DrawRay(pickingLine, MAROON);
End3dMode();
DrawFPS(10, 10);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -55,9 +67,7 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading CloseWindow(); // Close window and OpenGL context
CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
return 0; return 0;

View file

@ -15,7 +15,7 @@
* 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)
* *
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/

View file

@ -164,8 +164,6 @@ EXAMPLES = \
textures_logo_raylib \ textures_logo_raylib \
textures_image_loading \ textures_image_loading \
textures_rectangle \ textures_rectangle \
textures_compressed_dds \
textures_mipmaps \
textures_srcrec_dstrec \ textures_srcrec_dstrec \
text_sprite_fonts \ text_sprite_fonts \
text_rbmf_fonts \ text_rbmf_fonts \
@ -253,14 +251,6 @@ textures_image_loading: textures_image_loading.c
textures_rectangle: textures_rectangle.c textures_rectangle: textures_rectangle.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [textures] example - compressed texture loading (DDS)
textures_compressed_dds: textures_compressed_dds.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [textures] example - texture mipmaps generation
textures_mipmaps: textures_mipmaps.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
# compile [textures] example - texture source and destination rectangles # compile [textures] example - texture source and destination rectangles
textures_srcrec_dstrec: textures_srcrec_dstrec.c textures_srcrec_dstrec: textures_srcrec_dstrec.c
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS) $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)

View file

@ -5,7 +5,7 @@
* 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)
* *
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
@ -16,7 +16,7 @@ int main()
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 800; int screenWidth = 800;
int screenHeight = 150; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - font selector"); InitWindow(screenWidth, screenHeight, "raylib [text] example - font selector");
@ -45,13 +45,15 @@ int main()
Vector2 mousePoint; Vector2 mousePoint;
Rectangle btnNextRec = { 673, 18, 109, 44 }; // Button rectangle (useful for collision)
Color btnNextOutColor = DARKBLUE; // Button color (outside line) Color btnNextOutColor = DARKBLUE; // Button color (outside line)
Color btnNextInColor = SKYBLUE; // Button color (inside) Color btnNextInColor = SKYBLUE; // Button color (inside)
int framesCounter = 0; // Useful to count frames button is 'active' = clicked int framesCounter = 0; // Useful to count frames button is 'active' = clicked
int positionY = 180; // Text selector and button Y position
Rectangle btnNextRec = { 673, positionY, 109, 44 }; // Button rectangle (useful for collision)
SetTargetFPS(60); // Set our game to run at 60 frames-per-second SetTargetFPS(60); // Set our game to run at 60 frames-per-second
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
@ -72,6 +74,15 @@ int main()
if (currentFont > 0) currentFont--; if (currentFont > 0) currentFont--;
} }
if (IsKeyPressed('0')) currentFont = 0;
else if (IsKeyPressed('1')) currentFont = 1;
else if (IsKeyPressed('2')) currentFont = 2;
else if (IsKeyPressed('3')) currentFont = 3;
else if (IsKeyPressed('4')) currentFont = 4;
else if (IsKeyPressed('5')) currentFont = 5;
else if (IsKeyPressed('6')) currentFont = 6;
else if (IsKeyPressed('7')) currentFont = 7;
// Mouse-based font selection (NEXT button logic) // Mouse-based font selection (NEXT button logic)
mousePoint = GetMousePosition(); mousePoint = GetMousePosition();
@ -116,17 +127,20 @@ int main()
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawRectangle(18, 18, 644, 44, DARKGRAY); DrawText("font selector - use arroys, button or numbers", 160, 80, 20, DARKGRAY);
DrawRectangle(20, 20, 640, 40, LIGHTGRAY); DrawLine(120, 120, 680, 120, DARKGRAY);
DrawText(fontNames[currentFont], 30, 31, 20, BLACK);
DrawText("< >", 610, 26, 30, BLACK); DrawRectangle(18, positionY, 644, 44, DARKGRAY);
DrawRectangle(20, positionY + 2, 640, 40, LIGHTGRAY);
DrawText(fontNames[currentFont], 30, positionY + 13, 20, BLACK);
DrawText("< >", 610, positionY + 8, 30, BLACK);
DrawRectangleRec(btnNextRec, btnNextOutColor); DrawRectangleRec(btnNextRec, btnNextOutColor);
DrawRectangle(675, 20, 105, 40, btnNextInColor); DrawRectangle(675, positionY + 2, 105, 40, btnNextInColor);
DrawText("NEXT", 700, 31, 20, btnNextOutColor); DrawText("NEXT", 700, positionY + 13, 20, btnNextOutColor);
DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2, DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2,
75 + (70 - textSize.y)/2 }, GetFontBaseSize(fonts[currentFont])*3, 260 + (70 - textSize.y)/2 }, GetFontBaseSize(fonts[currentFont])*3,
1, colors[currentFont]); 1, colors[currentFont]);
EndDrawing(); EndDrawing();

View file

@ -18,20 +18,43 @@ int main()
{ {
// Initialization // Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
int screenWidth = 560; int screenWidth = 800;
int screenHeight = 800; int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [text] example - rBMF fonts"); InitWindow(screenWidth, screenHeight, "raylib [text] example - rBMF 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 font1 = LoadSpriteFont("resources/fonts/alagard.rbmf"); // rBMF font loading SpriteFont fonts[8];
SpriteFont font2 = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // rBMF font loading
SpriteFont font3 = LoadSpriteFont("resources/fonts/mecha.rbmf"); // rBMF font loading fonts[0] = LoadSpriteFont("resources/fonts/alagard.rbmf"); // rBMF font loading
SpriteFont font4 = LoadSpriteFont("resources/fonts/setback.rbmf"); // rBMF font loading fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // rBMF font loading
SpriteFont font5 = LoadSpriteFont("resources/fonts/romulus.rbmf"); // rBMF font loading fonts[2] = LoadSpriteFont("resources/fonts/mecha.rbmf"); // rBMF font loading
SpriteFont font6 = LoadSpriteFont("resources/fonts/pixantiqua.rbmf"); // rBMF font loading fonts[3] = LoadSpriteFont("resources/fonts/setback.rbmf"); // rBMF font loading
SpriteFont font7 = LoadSpriteFont("resources/fonts/alpha_beta.rbmf"); // rBMF font loading fonts[4] = LoadSpriteFont("resources/fonts/romulus.rbmf"); // rBMF font loading
SpriteFont font8 = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf"); // rBMF font loading fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.rbmf"); // rBMF font loading
fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.rbmf"); // rBMF font loading
fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf"); // rBMF font loading
const char *messages[8] = { "ALAGARD FONT designed by Hewett Tsoi",
"PIXELPLAY FONT designed by Aleksander Shevchuk",
"MECHA FONT designed by Captain Falcon",
"SETBACK FONT designed by Brian Kent (AEnigma)",
"ROMULUS FONT designed by Hewett Tsoi",
"PIXANTIQUA FONT designed by Gerhard Grossmann",
"ALPHA_BETA FONT designed by Brian Kent (AEnigma)",
"JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" };
const int spacings[8] = { 2, 4, 8, 4, 3, 4, 4, 1 };
Vector2 positions[8];
for (int i = 0; i < 8; i++)
{
positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], GetFontBaseSize(fonts[i])*2, spacings[i]).x/2;
positions[i].y = 60 + GetFontBaseSize(fonts[i]) + 50*i;
}
Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD };
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
// Main game loop // Main game loop
@ -48,14 +71,13 @@ int main()
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
DrawTextEx(font1, "TESTING ALAGARD FONT", (Vector2){ 100, 100 }, GetFontBaseSize(font1)*2, 2, MAROON); DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY);
DrawTextEx(font2, "TESTING PIXELPLAY FONT", (Vector2){ 100, 180 }, GetFontBaseSize(font2)*2, 4, ORANGE); DrawLine(220, 50, 590, 50, DARKGRAY);
DrawTextEx(font3, "TESTING MECHA FONT", (Vector2){ 100, 260 }, GetFontBaseSize(font3)*2, 8, DARKGREEN);
DrawTextEx(font4, "TESTING SETBACK FONT", (Vector2){ 100, 350 }, GetFontBaseSize(font4)*2, 4, DARKBLUE); for (int i = 0; i < 8; i++)
DrawTextEx(font5, "TESTING ROMULUS FONT", (Vector2){ 100, 430 }, GetFontBaseSize(font5)*2, 3, DARKPURPLE); {
DrawTextEx(font6, "TESTING PIXANTIQUA FONT", (Vector2){ 100, 510 }, GetFontBaseSize(font6)*2, 4, LIME); DrawTextEx(fonts[i], messages[i], positions[i], GetFontBaseSize(fonts[i])*2, spacings[i], colors[i]);
DrawTextEx(font7, "TESTING ALPHA_BETA FONT", (Vector2){ 100, 590 }, GetFontBaseSize(font7)*2, 4, GOLD); }
DrawTextEx(font8, "TESTING JUPITER_CRASH FONT", (Vector2){ 100, 660 }, GetFontBaseSize(font8)*2, 1, RED);
EndDrawing(); EndDrawing();
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -63,14 +85,10 @@ int main()
// De-Initialization // De-Initialization
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------
UnloadSpriteFont(font1); // SpriteFont unloading for (int i = 0; i < 8; i++)
UnloadSpriteFont(font2); // SpriteFont unloading {
UnloadSpriteFont(font3); // SpriteFont unloading UnloadSpriteFont(fonts[i]); // SpriteFont unloading
UnloadSpriteFont(font4); // SpriteFont unloading }
UnloadSpriteFont(font5); // SpriteFont unloading
UnloadSpriteFont(font6); // SpriteFont unloading
UnloadSpriteFont(font7); // SpriteFont unloading
UnloadSpriteFont(font8); // SpriteFont unloading
CloseWindow(); // Close window and OpenGL context CloseWindow(); // Close window and OpenGL context
//-------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------

Binary file not shown.

Before

Width:  |  Height:  |  Size: 15 KiB

View file

@ -7,7 +7,7 @@
* This example has been created using raylib 1.1 (www.raylib.com) * This example has been created using raylib 1.1 (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)
* *
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) * Copyright (c) 2014 Ramon Santamaria (@raysan5)
* *
********************************************************************************************/ ********************************************************************************************/
@ -25,7 +25,7 @@ int main()
// NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required)
Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM) Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM)
Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM)
UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM
//--------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------

View file

@ -1,66 +0,0 @@
/*******************************************************************************************
*
* raylib [textures] example - Texture loading with mipmaps, mipmaps generation
*
* NOTE: On OpenGL 1.1, mipmaps are calculated 'manually', original image must be power-of-two
* On OpenGL 3.3 and ES2, mipmaps are generated automatically
*
* This example has been created using raylib 1.1 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
*
********************************************************************************************/
#include "raylib.h"
int main()
{
// Initialization
//--------------------------------------------------------------------------------------
int screenWidth = 800;
int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture mipmaps generation");
// NOTE: To generate mipmaps for an image, image must be loaded first and converted to texture
Image image = LoadImage("resources/raylib_logo.png"); // Load image to CPU memory (RAM)
Texture2D texture = LoadTextureFromImage(image); // Load texture into GPU memory (VRAM)
GenTextureMipmaps(texture); // Generate mipmaps for texture
UnloadImage(image); // Once texture has been created, we can unload image data from RAM
//--------------------------------------------------------------------------------------
// Main game loop
while (!WindowShouldClose()) // Detect window close button or ESC key
{
// Update
//----------------------------------------------------------------------------------
// TODO: Update your variables here
//----------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
DrawTexture(texture, screenWidth/2 - texture.width/2,
screenHeight/2 - texture.height/2 - 30, WHITE);
DrawText("this IS a texture with mipmaps! really!", 210, 360, 20, GRAY);
EndDrawing();
//----------------------------------------------------------------------------------
}
// De-Initialization
//--------------------------------------------------------------------------------------
UnloadTexture(texture); // Texture unloading
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB