diff options
| author | Ray <raysan5@gmail.com> | 2015-08-31 01:16:34 +0200 |
|---|---|---|
| committer | Ray <raysan5@gmail.com> | 2015-08-31 01:16:34 +0200 |
| commit | 60194753d7b8abcdec3df2a502ccd29a1076bb7c (patch) | |
| tree | 47df863966fee50bd3a10d195c3f8274b4ed5ee6 /examples | |
| parent | 3a9ed0e8462570e30d92e2aa8c0ff3cf655ef863 (diff) | |
| parent | 808aeabf4c2ab0828e4f7806b75d95dc1b5ab212 (diff) | |
| download | raylib-60194753d7b8abcdec3df2a502ccd29a1076bb7c.tar.gz raylib-60194753d7b8abcdec3df2a502ccd29a1076bb7c.zip | |
Merge pull request #26 from raysan5/develop
Develop branch integration
Diffstat (limited to 'examples')
90 files changed, 893 insertions, 236 deletions
diff --git a/examples/audio_sound_loading.c b/examples/audio_sound_loading.c index 359af0af..1376a27d 100644 --- a/examples/audio_sound_loading.c +++ b/examples/audio_sound_loading.c @@ -7,7 +7,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core_3d_camera_first_person.c b/examples/core_3d_camera_first_person.c new file mode 100644 index 00000000..cd37f873 --- /dev/null +++ b/examples/core_3d_camera_first_person.c @@ -0,0 +1,91 @@ +/******************************************************************************************* +* +* raylib [core] example - 3d camera first person +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_COLUMNS 20 + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); + + // 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 }}; + + // Generates some random columns + float heights[MAX_COLUMNS]; + Vector3 positions[MAX_COLUMNS] = { 0.0, 2.5, 0.0 }; + Color colors[MAX_COLUMNS]; + + for (int i = 0; i < MAX_COLUMNS; i++) + { + heights[i] = (float)GetRandomValue(1, 12); + positions[i] = (Vector3){ GetRandomValue(-15, 15), heights[i]/2, GetRandomValue(-15, 15) }; + colors[i] = (Color){ GetRandomValue(20, 255), GetRandomValue(10, 55), 30, 255 }; + } + + Vector3 playerPosition = { 4, 2, 4 }; // Define player position + + SetCameraMode(CAMERA_FIRST_PERSON); // Set a first person camera mode + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateCameraPlayer(&camera, &playerPosition); // Update camera and player position + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 32, 32 }, LIGHTGRAY); // Draw ground + DrawCube((Vector3){ -16, 2.5, 0 }, 1, 5, 32, BLUE); // Draw a blue wall + DrawCube((Vector3){ 16, 2.5, 0 }, 1, 5, 32, LIME); // Draw a green wall + DrawCube((Vector3){ 0, 2.5, 16 }, 32, 5, 1, GOLD); // Draw a yellow wall + + // Draw some cubes around + for (int i = 0; i < MAX_COLUMNS; i++) + { + DrawCube(positions[i], 2, heights[i], 2, colors[i]); + DrawCubeWires(positions[i], 2, heights[i], 2, MAROON); + } + + End3dMode(); + + DrawText("First person camera default controls:", 20, 20, 10, GRAY); + DrawText("- Move with keys: W, A, S, D", 40, 50, 10, DARKGRAY); + DrawText("- Mouse move to lokk around", 40, 70, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/core_3d_camera_first_person.png b/examples/core_3d_camera_first_person.png Binary files differnew file mode 100644 index 00000000..9373da2d --- /dev/null +++ b/examples/core_3d_camera_first_person.png diff --git a/examples/core_3d_camera_free.c b/examples/core_3d_camera_free.c new file mode 100644 index 00000000..cca9cfd5 --- /dev/null +++ b/examples/core_3d_camera_free.c @@ -0,0 +1,75 @@ +/******************************************************************************************* +* +* raylib [core] example - Initialize 3d camera free +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); + + // 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 }}; + + Vector3 cubePosition = { 0.0, 0.0, 0.0 }; + + SetCameraMode(CAMERA_FREE); // Set a free camera mode + SetCameraPosition(camera.position); // Set internal camera position to match our camera position + SetCameraTarget(camera.target); // Set internal camera target to match our camera target + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + UpdateCamera(&camera); // Update internal camera and our camera + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(WHITE); + + Begin3dMode(camera); + + DrawCube(cubePosition, 2, 2, 2, RED); + DrawCubeWires(cubePosition, 2, 2, 2, MAROON); + + DrawGrid(10.0, 1.0); + + End3dMode(); + + DrawText("Free camera default controls:", 20, 20, 10, GRAY); + DrawText("- Mouse Wheel to Zoom in-out", 40, 50, 10, DARKGRAY); + DrawText("- Mouse Wheel Pressed to Pan", 40, 70, 10, DARKGRAY); + DrawText("- Alt + Mouse Wheel Pressed to Rotate", 40, 90, 10, DARKGRAY); + DrawText("- Alt + Ctrl + Mouse Wheel Pressed for Smooth Zoom", 40, 110, 10, DARKGRAY); + DrawText("- Z to zoom to (0, 0, 0)", 40, 130, 10, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/core_3d_camera_free.png b/examples/core_3d_camera_free.png Binary files differnew file mode 100644 index 00000000..afb5a7c5 --- /dev/null +++ b/examples/core_3d_camera_free.png diff --git a/examples/core_3d_mode.c b/examples/core_3d_mode.c index 2275058d..c38da256 100644 --- a/examples/core_3d_mode.c +++ b/examples/core_3d_mode.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core_3d_picking.c b/examples/core_3d_picking.c index a7a96fa9..13839070 100644 --- a/examples/core_3d_picking.c +++ b/examples/core_3d_picking.c @@ -2,10 +2,10 @@ * * raylib [core] example - Picking in 3d mode * -* This example has been created using raylib 1.0 (www.raylib.com) +* This example has been created using raylib 1.3 (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) +* Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com) * ********************************************************************************************/ @@ -23,23 +23,30 @@ int main() // 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 }}; - Vector3 cubePosition = { 0.0, 0.0, 0.0 }; + Vector3 cubePosition = { 0.0, 1.0, 0.0 }; - Ray pickingLine; + Ray ray; // Picking line ray - SetCameraMode(CAMERA_FREE); + SetCameraMode(CAMERA_FREE); // Set a free camera mode + SetCameraPosition(camera.position); // Set internal camera position to match our camera position - SetTargetFPS(60); + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - camera = UpdateCamera(0); + UpdateCamera(&camera); // Update internal camera and our camera - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pickingLine = GetMouseRay(GetMousePosition(), camera); + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + { + // NOTE: This function is NOT WORKING properly! + ray = GetMouseRay(GetMousePosition(), camera); + + // TODO: Check collision between ray and box + } //---------------------------------------------------------------------------------- // Draw @@ -50,14 +57,16 @@ int main() Begin3dMode(camera); - DrawCube(cubePosition, 2, 2, 2, RED); - DrawCubeWires(cubePosition, 2, 2, 2, MAROON); + DrawCube(cubePosition, 2, 2, 2, GRAY); + DrawCubeWires(cubePosition, 2, 2, 2, DARKGRAY); DrawGrid(10.0, 1.0); - DrawRay(pickingLine, MAROON); + DrawRay(ray, MAROON); End3dMode(); + + DrawText("Try selecting the box with mouse!", 240, 10, 20, GRAY); DrawFPS(10, 10); diff --git a/examples/core_3d_picking.png b/examples/core_3d_picking.png Binary files differnew file mode 100644 index 00000000..828c41a8 --- /dev/null +++ b/examples/core_3d_picking.png diff --git a/examples/core_basic_window_web.c b/examples/core_basic_window_web.c index b35c07e6..65650b1a 100644 --- a/examples/core_basic_window_web.c +++ b/examples/core_basic_window_web.c @@ -15,7 +15,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core_color_select.c b/examples/core_color_select.c index a2a79ed9..118dc88a 100644 --- a/examples/core_color_select.c +++ b/examples/core_color_select.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/models_planes.c b/examples/core_drop_files.c index 58b5137e..5802e48f 100644 --- a/examples/models_planes.c +++ b/examples/core_drop_files.c @@ -1,8 +1,8 @@ /******************************************************************************************* * -* raylib [models] example - Draw 3d planes +* raylib [core] example - Windows drop files * -* This example has been created using raylib 1.2 (www.raylib.com) +* This example has been created using raylib 1.3 (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) @@ -18,12 +18,12 @@ int main() int screenWidth = 800; int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [models] example - 3d planes"); - - // 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 }}; - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + InitWindow(screenWidth, screenHeight, "raylib [core] example - drop files"); + + int count = 0; + char **droppedFiles; + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -31,7 +31,10 @@ int main() { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + if (IsFileDropped()) + { + droppedFiles = GetDroppedFiles(&count); + } //---------------------------------------------------------------------------------- // Draw @@ -40,15 +43,21 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); - - DrawPlane((Vector3){ 0, 0, 0 }, (Vector2){ 4, 4 }, RED); // Draw a plane XZ - - DrawGrid(10.0, 1.0); - - End3dMode(); - - DrawFPS(10, 10); + if (count == 0) DrawText("Drop your files to this window!", 100, 40, 20, DARKGRAY); + else + { + DrawText("Dropped files:", 100, 40, 20, DARKGRAY); + + for (int i = 0; i < count; i++) + { + if (i%2 == 0) DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.5f)); + else DrawRectangle(0, 85 + 40*i, screenWidth, 40, Fade(LIGHTGRAY, 0.3f)); + + DrawText(droppedFiles[i], 120, 100 + 40*i, 10, GRAY); + } + + DrawText("Drop new files...", 100, 110 + 40*count, 20, DARKGRAY); + } EndDrawing(); //---------------------------------------------------------------------------------- @@ -56,7 +65,9 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - CloseWindow(); // Close window and OpenGL context + ClearDroppedFiles(); // Clear internal buffers + + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; diff --git a/examples/core_drop_files.png b/examples/core_drop_files.png Binary files differnew file mode 100644 index 00000000..d46c44cf --- /dev/null +++ b/examples/core_drop_files.png diff --git a/examples/core_input_gamepad.c b/examples/core_input_gamepad.c index 384ef989..64be4cd8 100644 --- a/examples/core_input_gamepad.c +++ b/examples/core_input_gamepad.c @@ -8,7 +8,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core_input_keys.c b/examples/core_input_keys.c index 442ae840..99d5e516 100644 --- a/examples/core_input_keys.c +++ b/examples/core_input_keys.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core_input_mouse.c b/examples/core_input_mouse.c index eeef8c7a..c64b421e 100644 --- a/examples/core_input_mouse.c +++ b/examples/core_input_mouse.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core_mouse_wheel.c b/examples/core_mouse_wheel.c index 08c2ee1e..6a5252ee 100644 --- a/examples/core_mouse_wheel.c +++ b/examples/core_mouse_wheel.c @@ -5,7 +5,7 @@ * This test 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) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/core_random_values.c b/examples/core_random_values.c index 20989ee1..98e0e91e 100644 --- a/examples/core_random_values.c +++ b/examples/core_random_values.c @@ -5,7 +5,7 @@ * 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) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/models_billboard.c b/examples/models_billboard.c index a58ec7d7..05d836ca 100644 --- a/examples/models_billboard.c +++ b/examples/models_billboard.c @@ -2,10 +2,10 @@ * * raylib [models] example - Drawing billboards * -* This example has been created using raylib 1.2 (www.raylib.com) +* This example has been created using raylib 1.3 (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) +* Copyright (c) 2015 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -21,24 +21,24 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards"); // Define the camera to look into our 3d world - Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 5.0, 4.0, 5.0 }, { 0.0, 2.0, 0.0 }, { 0.0, 1.0, 0.0 }}; - Texture2D lena = LoadTexture("resources/lena.png"); // Our texture for billboard - Rectangle eyesRec = { 225, 240, 155, 50 }; // Part of the texture to draw - Vector3 billPosition = { 0.0, 0.0, 0.0 }; // Position where draw billboard + Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard + Vector3 billPosition = { 0.0, 2.0, 0.0 }; // Position where draw billboard + + SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode + SetCameraPosition(camera.position); // Set internal camera position to match our camera position + SetCameraTarget(camera.target); // Set internal camera target to match our camera target - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_LEFT)) camera.position.x -= 0.2; - if (IsKeyDown(KEY_RIGHT)) camera.position.x += 0.2; - if (IsKeyDown(KEY_UP)) camera.position.y -= 0.2; - if (IsKeyDown(KEY_DOWN)) camera.position.y += 0.2; + UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw @@ -49,8 +49,7 @@ int main() Begin3dMode(camera); - //DrawBillboard(camera, lena, billPosition, 1.0, WHITE); - DrawBillboardRec(camera, lena, eyesRec, billPosition, 4.0, WHITE); + DrawBillboard(camera, bill, billPosition, 2.0f, WHITE); DrawGrid(10.0, 1.0); // Draw a grid @@ -64,7 +63,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(lena); // Unload texture + UnloadTexture(bill); // Unload texture CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/models_billboard.png b/examples/models_billboard.png Binary files differnew file mode 100644 index 00000000..f1ed9239 --- /dev/null +++ b/examples/models_billboard.png diff --git a/examples/models_cubicmap.c b/examples/models_cubicmap.c index 62f7b076..d7fe896c 100644 --- a/examples/models_cubicmap.c +++ b/examples/models_cubicmap.c @@ -2,10 +2,10 @@ * * raylib [models] example - Cubicmap loading and drawing * -* This example has been created using raylib 1.2 (www.raylib.com) +* This example has been created using raylib 1.3 (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) +* Copyright (c) 2015 Ramon Santamaria (Ray San - raysan@raysanweb.com) * ********************************************************************************************/ @@ -21,29 +21,32 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing"); // Define the camera to look into our 3d world - Camera camera = {{ 7.0, 7.0, 7.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + Camera camera = {{ 16.0, 14.0, 16.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; - Image image = LoadImage("resources/cubicmap.png"); // Load cubesmap image (RAM) - Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) + Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) + Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) Model map = LoadCubicmap(image); // Load cubicmap model (generate model from image) - SetModelTexture(&map, texture); // Bind texture to model - Vector3 mapPosition = { -1, 0.0, -1 }; // Set model position + + // NOTE: By default each cube is mapped to one part of texture atlas + Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); // Load map texture + SetModelTexture(&map, texture); // Bind texture to map model + + Vector3 mapPosition = { -16, 0.0, -8 }; // Set model position UnloadImage(image); // Unload cubesmap image from RAM, already uploaded to VRAM + + SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode + SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_UP)) camera.position.y += 0.2f; - else if (IsKeyDown(KEY_DOWN)) camera.position.y -= 0.2f; - - if (IsKeyDown(KEY_RIGHT)) camera.position.z += 0.2f; - else if (IsKeyDown(KEY_LEFT)) camera.position.z -= 0.2f; + UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw @@ -54,13 +57,15 @@ int main() Begin3dMode(camera); - DrawModel(map, mapPosition, 1.0f, MAROON); - - DrawGrid(10.0, 1.0); - - DrawGizmo(mapPosition); + DrawModel(map, mapPosition, 1.0f, WHITE); End3dMode(); + + DrawTextureEx(cubicmap, (Vector2){ screenWidth - cubicmap.width*4 - 20, 20 }, 0.0f, 4.0f, WHITE); + DrawRectangleLines(screenWidth - cubicmap.width*4 - 20, 20, cubicmap.width*4, cubicmap.height*4, GREEN); + + DrawText("cubicmap image used to", 658, 90, 10, GRAY); + DrawText("generate map 3d model", 658, 104, 10, GRAY); DrawFPS(10, 10); @@ -70,8 +75,9 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Unload texture - UnloadModel(map); // Unload model + UnloadTexture(cubicmap); // Unload cubicmap texture + UnloadTexture(texture); // Unload map texture + UnloadModel(map); // Unload map model CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/models_cubicmap.png b/examples/models_cubicmap.png Binary files differindex f686ba21..9cb854cb 100644 --- a/examples/models_cubicmap.png +++ b/examples/models_cubicmap.png diff --git a/examples/models_custom_shader.c b/examples/models_custom_shader.c deleted file mode 100644 index 5430ed65..00000000 --- a/examples/models_custom_shader.c +++ /dev/null @@ -1,86 +0,0 @@ -/******************************************************************************************* -* -* raylib [models] example - Load and draw a 3d model (OBJ) -* -* 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) -* -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) -* -********************************************************************************************/ - -#include "raylib.h" - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 1280; - int screenHeight = 720; - - InitWindow(screenWidth, screenHeight, "raylib [models] example - custom shader"); - - // Define the camera to look into our 3d world - Camera camera = {{ 10.0, 8.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; - - Texture2D texture = LoadTexture("resources/catsham.png"); // Load model texture - Shader shader = LoadShader("resources/shaders/custom.vs", "resources/shaders/custom.fs"); - //Shader poste = LoadShader("resources/shaders/custom.vs", "resources/shaders/pixel.fs"); - - Model cat = LoadModel("resources/cat.obj"); // Load OBJ model - - SetModelTexture(&cat, texture); // Bind texture to model - //SetModelShader(&cat, poste); - - Vector3 catPosition = { 0.0, 0.0, 0.0 }; // Set model position - - SetPostproShader(shader); - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_LEFT)) catPosition.x -= 0.2; - if (IsKeyDown(KEY_RIGHT)) catPosition.x += 0.2; - if (IsKeyDown(KEY_UP)) catPosition.z -= 0.2; - if (IsKeyDown(KEY_DOWN)) catPosition.z += 0.2; - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - Begin3dMode(camera); - - DrawModel(cat, catPosition, 0.1f, WHITE); // Draw 3d model with texture - - DrawGrid(10.0, 1.0); // Draw a grid - - DrawGizmo(catPosition); // Draw gizmo - - End3dMode(); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Unload texture - UnloadModel(cat); // Unload model - UnloadShader(shader); - //UnloadShader(poste); - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/examples/models_geometric_shapes.c b/examples/models_geometric_shapes.c index 3a649a3a..e2d41dcd 100644 --- a/examples/models_geometric_shapes.c +++ b/examples/models_geometric_shapes.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/models_heightmap.c b/examples/models_heightmap.c index a23656a5..fec3f5e6 100644 --- a/examples/models_heightmap.c +++ b/examples/models_heightmap.c @@ -2,10 +2,10 @@ * * raylib [models] example - Heightmap loading and drawing * -* This example has been created using raylib 1.1 (www.raylib.com) +* This example has been created using raylib 1.3 (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) +* Copyright (c) 2015 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -20,26 +20,29 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing"); - // Define the camera to look into our 3d world - Camera camera = {{ 10.0, 12.0, 10.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; + // Define our custom camera to look into our 3d world + Camera camera = {{ 24.0, 18.0, 24.0 }, { 0.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }}; Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) - Model map = LoadHeightmap(image, 4); // Load heightmap model + Model map = LoadHeightmap(image, 32); // Load heightmap model SetModelTexture(&map, texture); // Bind texture to model - Vector3 mapPosition = { -4, 0.0, -4 }; // Set model position + Vector3 mapPosition = { -16, 0.0, -16 }; // Set model position (depends on model scaling!) - UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM + UnloadImage(image); // Unload heightmap image from RAM, already uploaded to VRAM + + SetCameraMode(CAMERA_ORBITAL); // Set an orbital camera mode + SetCameraPosition(camera.position); // Set internal camera position to match our custom camera position - SetTargetFPS(60); // Set our game to run at 60 frames-per-second + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //---------------------------------------------------------------------------------- - // ... + UpdateCamera(&camera); // Update internal camera and our camera //---------------------------------------------------------------------------------- // Draw @@ -50,13 +53,13 @@ int main() Begin3dMode(camera); - DrawModel(map, mapPosition, 0.5f, MAROON); - - DrawGrid(10.0, 1.0); - - DrawGizmo(mapPosition); + // NOTE: Model is scaled to 1/4 of its original size (128x128 units) + DrawModel(map, mapPosition, 1/4.0f, RED); End3dMode(); + + DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE); + DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN); DrawFPS(10, 10); diff --git a/examples/models_heightmap.png b/examples/models_heightmap.png Binary files differindex a32ec954..9ed04586 100644 --- a/examples/models_heightmap.png +++ b/examples/models_heightmap.png diff --git a/examples/models_obj_loading.c b/examples/models_obj_loading.c index 55501f65..ef024356 100644 --- a/examples/models_obj_loading.c +++ b/examples/models_obj_loading.c @@ -2,7 +2,7 @@ * * raylib [models] example - Load and draw a 3d model (OBJ) * -* This example has been created using raylib 1.0 (www.raylib.com) +* This example has been created using raylib 1.3 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2014 Ramon Santamaria (@raysan5) diff --git a/examples/models_obj_loading.png b/examples/models_obj_loading.png Binary files differindex da49c457..560348b4 100644 --- a/examples/models_obj_loading.png +++ b/examples/models_obj_loading.png diff --git a/examples/openal32.dll b/examples/openal32.dll Binary files differdeleted file mode 100644 index 71ced6a2..00000000 --- a/examples/openal32.dll +++ /dev/null diff --git a/examples/resources/billboard.png b/examples/resources/billboard.png Binary files differnew file mode 100644 index 00000000..e2fe398d --- /dev/null +++ b/examples/resources/billboard.png diff --git a/examples/resources/cubicmap.png b/examples/resources/cubicmap.png Binary files differindex 87b95d50..b361c018 100644 --- a/examples/resources/cubicmap.png +++ b/examples/resources/cubicmap.png diff --git a/examples/resources/cubicmap_atlas.png b/examples/resources/cubicmap_atlas.png Binary files differnew file mode 100644 index 00000000..7ddfc83a --- /dev/null +++ b/examples/resources/cubicmap_atlas.png diff --git a/examples/resources/guybrush.png b/examples/resources/guybrush.png Binary files differnew file mode 100644 index 00000000..32c9dced --- /dev/null +++ b/examples/resources/guybrush.png diff --git a/examples/resources/heightmap.png b/examples/resources/heightmap.png Binary files differindex c17050fc..fe30f679 100644 --- a/examples/resources/heightmap.png +++ b/examples/resources/heightmap.png diff --git a/examples/resources/lena.png b/examples/resources/lena.png Binary files differdeleted file mode 100644 index 59ef68aa..00000000 --- a/examples/resources/lena.png +++ /dev/null diff --git a/examples/resources/raylib_logo.dds b/examples/resources/raylib_logo.dds Binary files differdeleted file mode 100644 index b558bc15..00000000 --- a/examples/resources/raylib_logo.dds +++ /dev/null diff --git a/examples/resources/raylib_logo_uncompressed.dds b/examples/resources/raylib_logo_uncompressed.dds Binary files differdeleted file mode 100644 index 2b40a205..00000000 --- a/examples/resources/raylib_logo_uncompressed.dds +++ /dev/null diff --git a/examples/resources/smoke.png b/examples/resources/smoke.png Binary files differnew file mode 100644 index 00000000..7bad8c68 --- /dev/null +++ b/examples/resources/smoke.png diff --git a/examples/resources/texture_formats/sonic.png b/examples/resources/texture_formats/sonic.png Binary files differnew file mode 100644 index 00000000..7a096847 --- /dev/null +++ b/examples/resources/texture_formats/sonic.png diff --git a/examples/resources/texture_formats/sonic_A1R5G5B5.dds b/examples/resources/texture_formats/sonic_A1R5G5B5.dds Binary files differnew file mode 100644 index 00000000..5e2347db --- /dev/null +++ b/examples/resources/texture_formats/sonic_A1R5G5B5.dds diff --git a/examples/resources/texture_formats/sonic_A4R4G4B4.dds b/examples/resources/texture_formats/sonic_A4R4G4B4.dds Binary files differnew file mode 100644 index 00000000..c5ccaf0c --- /dev/null +++ b/examples/resources/texture_formats/sonic_A4R4G4B4.dds diff --git a/examples/resources/texture_formats/sonic_A8R8G8B8.dds b/examples/resources/texture_formats/sonic_A8R8G8B8.dds Binary files differnew file mode 100644 index 00000000..fb71b7be --- /dev/null +++ b/examples/resources/texture_formats/sonic_A8R8G8B8.dds diff --git a/examples/resources/texture_formats/sonic_ASTC_4x4_ldr.astc b/examples/resources/texture_formats/sonic_ASTC_4x4_ldr.astc Binary files differnew file mode 100644 index 00000000..9a98d9a0 --- /dev/null +++ b/examples/resources/texture_formats/sonic_ASTC_4x4_ldr.astc diff --git a/examples/resources/texture_formats/sonic_ASTC_8x8_ldr.astc b/examples/resources/texture_formats/sonic_ASTC_8x8_ldr.astc Binary files differnew file mode 100644 index 00000000..360a264a --- /dev/null +++ b/examples/resources/texture_formats/sonic_ASTC_8x8_ldr.astc diff --git a/examples/resources/texture_formats/sonic_DXT1_RGB.dds b/examples/resources/texture_formats/sonic_DXT1_RGB.dds Binary files differnew file mode 100644 index 00000000..9d0b4598 --- /dev/null +++ b/examples/resources/texture_formats/sonic_DXT1_RGB.dds diff --git a/examples/resources/texture_formats/sonic_DXT1_RGBA.dds b/examples/resources/texture_formats/sonic_DXT1_RGBA.dds Binary files differnew file mode 100644 index 00000000..102bae7f --- /dev/null +++ b/examples/resources/texture_formats/sonic_DXT1_RGBA.dds diff --git a/examples/resources/texture_formats/sonic_DXT3_RGBA.dds b/examples/resources/texture_formats/sonic_DXT3_RGBA.dds Binary files differnew file mode 100644 index 00000000..46d965cb --- /dev/null +++ b/examples/resources/texture_formats/sonic_DXT3_RGBA.dds diff --git a/examples/resources/texture_formats/sonic_DXT5_RGBA.dds b/examples/resources/texture_formats/sonic_DXT5_RGBA.dds Binary files differnew file mode 100644 index 00000000..b3a59a79 --- /dev/null +++ b/examples/resources/texture_formats/sonic_DXT5_RGBA.dds diff --git a/examples/resources/texture_formats/sonic_ETC1_RGB.ktx b/examples/resources/texture_formats/sonic_ETC1_RGB.ktx Binary files differnew file mode 100644 index 00000000..66241b9d --- /dev/null +++ b/examples/resources/texture_formats/sonic_ETC1_RGB.ktx diff --git a/examples/resources/texture_formats/sonic_ETC1_RGB.pkm b/examples/resources/texture_formats/sonic_ETC1_RGB.pkm Binary files differnew file mode 100644 index 00000000..c6fc6df4 --- /dev/null +++ b/examples/resources/texture_formats/sonic_ETC1_RGB.pkm diff --git a/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.ktx b/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.ktx Binary files differnew file mode 100644 index 00000000..b01812cb --- /dev/null +++ b/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.ktx diff --git a/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.old.pkm b/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.old.pkm Binary files differnew file mode 100644 index 00000000..61ac48ce --- /dev/null +++ b/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.old.pkm diff --git a/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.pkm b/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.pkm Binary files differnew file mode 100644 index 00000000..61ac48ce --- /dev/null +++ b/examples/resources/texture_formats/sonic_ETC2_EAC_RGBA.pkm diff --git a/examples/resources/texture_formats/sonic_ETC2_RGB.ktx b/examples/resources/texture_formats/sonic_ETC2_RGB.ktx Binary files differnew file mode 100644 index 00000000..7f1207f7 --- /dev/null +++ b/examples/resources/texture_formats/sonic_ETC2_RGB.ktx diff --git a/examples/resources/texture_formats/sonic_ETC2_RGB.pkm b/examples/resources/texture_formats/sonic_ETC2_RGB.pkm Binary files differnew file mode 100644 index 00000000..f290f019 --- /dev/null +++ b/examples/resources/texture_formats/sonic_ETC2_RGB.pkm diff --git a/examples/resources/texture_formats/sonic_GRAYSCALE.pvr b/examples/resources/texture_formats/sonic_GRAYSCALE.pvr Binary files differnew file mode 100644 index 00000000..d31e2651 --- /dev/null +++ b/examples/resources/texture_formats/sonic_GRAYSCALE.pvr diff --git a/examples/resources/texture_formats/sonic_L8A8.pvr b/examples/resources/texture_formats/sonic_L8A8.pvr Binary files differnew file mode 100644 index 00000000..ccf5932e --- /dev/null +++ b/examples/resources/texture_formats/sonic_L8A8.pvr diff --git a/examples/resources/texture_formats/sonic_PVRT_RGB.pvr b/examples/resources/texture_formats/sonic_PVRT_RGB.pvr Binary files differnew file mode 100644 index 00000000..22f3f66a --- /dev/null +++ b/examples/resources/texture_formats/sonic_PVRT_RGB.pvr diff --git a/examples/resources/texture_formats/sonic_PVRT_RGBA.pvr b/examples/resources/texture_formats/sonic_PVRT_RGBA.pvr Binary files differnew file mode 100644 index 00000000..feb9aeaf --- /dev/null +++ b/examples/resources/texture_formats/sonic_PVRT_RGBA.pvr diff --git a/examples/resources/texture_formats/sonic_PVRT_RGBA_2bpp.pvr b/examples/resources/texture_formats/sonic_PVRT_RGBA_2bpp.pvr Binary files differnew file mode 100644 index 00000000..9147e1bb --- /dev/null +++ b/examples/resources/texture_formats/sonic_PVRT_RGBA_2bpp.pvr diff --git a/examples/resources/texture_formats/sonic_PVRT_RGB_2bpp.pvr b/examples/resources/texture_formats/sonic_PVRT_RGB_2bpp.pvr Binary files differnew file mode 100644 index 00000000..2a8aea8c --- /dev/null +++ b/examples/resources/texture_formats/sonic_PVRT_RGB_2bpp.pvr diff --git a/examples/resources/texture_formats/sonic_R4G4B4A4.pvr b/examples/resources/texture_formats/sonic_R4G4B4A4.pvr Binary files differnew file mode 100644 index 00000000..3f7368a3 --- /dev/null +++ b/examples/resources/texture_formats/sonic_R4G4B4A4.pvr diff --git a/examples/resources/texture_formats/sonic_R5G5B5A1.pvr b/examples/resources/texture_formats/sonic_R5G5B5A1.pvr Binary files differnew file mode 100644 index 00000000..c7fa098d --- /dev/null +++ b/examples/resources/texture_formats/sonic_R5G5B5A1.pvr diff --git a/examples/resources/texture_formats/sonic_R5G6B5.dds b/examples/resources/texture_formats/sonic_R5G6B5.dds Binary files differnew file mode 100644 index 00000000..217da954 --- /dev/null +++ b/examples/resources/texture_formats/sonic_R5G6B5.dds diff --git a/examples/resources/texture_formats/sonic_R5G6B5.pvr b/examples/resources/texture_formats/sonic_R5G6B5.pvr Binary files differnew file mode 100644 index 00000000..9bb8320e --- /dev/null +++ b/examples/resources/texture_formats/sonic_R5G6B5.pvr diff --git a/examples/resources/texture_formats/sonic_R8G8B8.pvr b/examples/resources/texture_formats/sonic_R8G8B8.pvr Binary files differnew file mode 100644 index 00000000..072cf3ef --- /dev/null +++ b/examples/resources/texture_formats/sonic_R8G8B8.pvr diff --git a/examples/resources/texture_formats/sonic_R8G8B8A8.pvr b/examples/resources/texture_formats/sonic_R8G8B8A8.pvr Binary files differnew file mode 100644 index 00000000..f82534f9 --- /dev/null +++ b/examples/resources/texture_formats/sonic_R8G8B8A8.pvr diff --git a/examples/resources/texture_formats/sonic_R8G8B8A8.raw b/examples/resources/texture_formats/sonic_R8G8B8A8.raw Binary files differnew file mode 100644 index 00000000..fc5858e7 --- /dev/null +++ b/examples/resources/texture_formats/sonic_R8G8B8A8.raw diff --git a/examples/shapes_basic_shapes.c b/examples/shapes_basic_shapes.c index 4ae9f4df..4b14af89 100644 --- a/examples/shapes_basic_shapes.c +++ b/examples/shapes_basic_shapes.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/shapes_colors_palette.c b/examples/shapes_colors_palette.c index 926dcdf8..3e161114 100644 --- a/examples/shapes_colors_palette.c +++ b/examples/shapes_colors_palette.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/shapes_logo_raylib.c b/examples/shapes_logo_raylib.c index a9e5104a..3dd8fbf3 100644 --- a/examples/shapes_logo_raylib.c +++ b/examples/shapes_logo_raylib.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/shapes_logo_raylib_anim.c b/examples/shapes_logo_raylib_anim.c index cd3a4aa6..d0831378 100644 --- a/examples/shapes_logo_raylib_anim.c +++ b/examples/shapes_logo_raylib_anim.c @@ -5,7 +5,7 @@ * 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) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/text_font_select.c b/examples/text_font_select.c index 25825aba..fe586db8 100644 --- a/examples/text_font_select.c +++ b/examples/text_font_select.c @@ -2,10 +2,10 @@ * * raylib [text] example - Font selector * -* This example has been created using raylib 1.0 (www.raylib.com) +* This example has been created using raylib 1.3 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2014 Ramon Santamaria (@raysan5) +* Copyright (c) 2015 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -41,7 +41,7 @@ int main() const char text[50] = "THIS is THE FONT you SELECTED!"; // Main text - Vector2 textSize = MeasureTextEx(fonts[currentFont], text, GetFontBaseSize(fonts[currentFont])*3, 1); + Vector2 textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1); Vector2 mousePoint; @@ -118,7 +118,7 @@ int main() } // Text measurement for better positioning on screen - textSize = MeasureTextEx(fonts[currentFont], text, GetFontBaseSize(fonts[currentFont])*3, 1); + textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1); //---------------------------------------------------------------------------------- // Draw @@ -140,7 +140,7 @@ int main() DrawText("NEXT", 700, positionY + 13, 20, btnNextOutColor); DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2, - 260 + (70 - textSize.y)/2 }, GetFontBaseSize(fonts[currentFont])*3, + 260 + (70 - textSize.y)/2 }, fonts[currentFont].size*3, 1, colors[currentFont]); EndDrawing(); diff --git a/examples/text_font_select.png b/examples/text_font_select.png Binary files differindex 27bf9432..65040df6 100644 --- a/examples/text_font_select.png +++ b/examples/text_font_select.png diff --git a/examples/text_format_text.c b/examples/text_format_text.c index 516e3ecf..ca28be74 100644 --- a/examples/text_format_text.c +++ b/examples/text_format_text.c @@ -5,7 +5,7 @@ * 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) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/text_rbmf_fonts.c b/examples/text_rbmf_fonts.c index a521862b..b4bd851b 100644 --- a/examples/text_rbmf_fonts.c +++ b/examples/text_rbmf_fonts.c @@ -5,10 +5,10 @@ * NOTE: raylib is distributed with some free to use fonts (even for commercial pourposes!) * To view details and credits for those fonts, check raylib license file * -* This example has been created using raylib 1.0 (www.raylib.com) +* This example has been created using raylib 1.3 (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) +* Copyright (c) 2015 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -50,8 +50,8 @@ int main() 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; + positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].size*2, spacings[i]).x/2; + positions[i].y = 60 + fonts[i].size + 50*i; } Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD }; @@ -76,7 +76,7 @@ int main() for (int i = 0; i < 8; i++) { - DrawTextEx(fonts[i], messages[i], positions[i], GetFontBaseSize(fonts[i])*2, spacings[i], colors[i]); + DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].size*2, spacings[i], colors[i]); } EndDrawing(); diff --git a/examples/text_rbmf_fonts.png b/examples/text_rbmf_fonts.png Binary files differindex 58f6d83f..c047c503 100644 --- a/examples/text_rbmf_fonts.png +++ b/examples/text_rbmf_fonts.png diff --git a/examples/text_sprite_fonts.c b/examples/text_sprite_fonts.c index e27e8c08..c73eda85 100644 --- a/examples/text_sprite_fonts.c +++ b/examples/text_sprite_fonts.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -31,14 +31,14 @@ int main() Vector2 fontPosition1, fontPosition2, fontPosition3; - fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, GetFontBaseSize(font1), -3).x/2; - fontPosition1.y = screenHeight/2 - GetFontBaseSize(font1)/2 - 80; + fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.size, -3).x/2; + fontPosition1.y = screenHeight/2 - font1.size/2 - 80; - fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, GetFontBaseSize(font2), -2).x/2; - fontPosition2.y = screenHeight/2 - GetFontBaseSize(font2)/2 - 10; + fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.size, -2).x/2; + fontPosition2.y = screenHeight/2 - font2.size/2 - 10; - fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, GetFontBaseSize(font3), 2).x/2; - fontPosition3.y = screenHeight/2 - GetFontBaseSize(font3)/2 + 50; + fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.size, 2).x/2; + fontPosition3.y = screenHeight/2 - font3.size/2 + 50; //-------------------------------------------------------------------------------------- @@ -56,9 +56,9 @@ int main() ClearBackground(RAYWHITE); - DrawTextEx(font1, msg1, fontPosition1, GetFontBaseSize(font1), -3, WHITE); - DrawTextEx(font2, msg2, fontPosition2, GetFontBaseSize(font2), -2, WHITE); - DrawTextEx(font3, msg3, fontPosition3, GetFontBaseSize(font3), 2, WHITE); + DrawTextEx(font1, msg1, fontPosition1, font1.size, -3, WHITE); + DrawTextEx(font2, msg2, fontPosition2, font2.size, -2, WHITE); + DrawTextEx(font3, msg3, fontPosition3, font3.size, 2, WHITE); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/examples/textures_formats_loading.c b/examples/textures_formats_loading.c new file mode 100644 index 00000000..a758fe27 --- /dev/null +++ b/examples/textures_formats_loading.c @@ -0,0 +1,244 @@ +/******************************************************************************************* +* +* raylib [textures] example - texture formats loading (compressed and uncompressed) +* +* NOTE: This example requires raylib OpenGL 3.3+ or ES2 versions for compressed textures, +* OpenGL 1.1 does not support compressed textures, only uncompressed ones. +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define NUM_TEXTURES 24 + +typedef enum { + PNG_R8G8B8A8 = 0, + PVR_GRAYSCALE, + PVR_GRAY_ALPHA, + PVR_R5G6B5, + PVR_R5G5B5A1, + PVR_R4G4B4A4, + DDS_R5G6B5, + DDS_R5G5B5A1, + DDS_R4G4B4A4, + DDS_R8G8B8A8, + DDS_DXT1_RGB, + DDS_DXT1_RGBA, + DDS_DXT3_RGBA, + DDS_DXT5_RGBA, + PKM_ETC1_RGB, + PKM_ETC2_RGB, + PKM_ETC2_EAC_RGBA, + KTX_ETC1_RGB, + KTX_ETC2_RGB, + KTX_ETC2_EAC_RGBA, + ASTC_4x4_LDR, + ASTC_8x8_LDR, + PVR_PVRT_RGB, + PVR_PVRT_RGBA + +} TextureFormats; + +static const char *formatText[] = { + "PNG_R8G8B8A8", + "PVR_GRAYSCALE", + "PVR_GRAY_ALPHA", + "PVR_R5G6B5", + "PVR_R5G5B5A1", + "PVR_R4G4B4A4", + "DDS_R5G6B5", + "DDS_R5G5B5A1", + "DDS_R4G4B4A4", + "DDS_R8G8B8A8", + "DDS_DXT1_RGB", + "DDS_DXT1_RGBA", + "DDS_DXT3_RGBA", + "DDS_DXT5_RGBA", + "PKM_ETC1_RGB", + "PKM_ETC2_RGB", + "PKM_ETC2_EAC_RGBA", + "KTX_ETC1_RGB", + "KTX_ETC2_RGB", + "KTX_ETC2_EAC_RGBA", + "ASTC_4x4_LDR", + "ASTC_8x8_LDR", + "PVR_PVRT_RGB", + "PVR_PVRT_RGBA" +}; + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 480; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture formats loading"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Texture2D sonic[NUM_TEXTURES]; + + sonic[PNG_R8G8B8A8] = LoadTexture("resources/texture_formats/sonic.png"); + + // Load UNCOMPRESSED PVR texture data + sonic[PVR_GRAYSCALE] = LoadTexture("resources/texture_formats/sonic_GRAYSCALE.pvr"); + sonic[PVR_GRAY_ALPHA] = LoadTexture("resources/texture_formats/sonic_L8A8.pvr"); + sonic[PVR_R5G6B5] = LoadTexture("resources/texture_formats/sonic_R5G6B5.pvr"); + sonic[PVR_R5G5B5A1] = LoadTexture("resources/texture_formats/sonic_R5G5B5A1.pvr"); + sonic[PVR_R4G4B4A4] = LoadTexture("resources/texture_formats/sonic_R4G4B4A4.pvr"); + + // Load UNCOMPRESSED DDS texture data + sonic[DDS_R5G6B5] = LoadTexture("resources/texture_formats/sonic_R5G6B5.dds"); + sonic[DDS_R5G5B5A1] = LoadTexture("resources/texture_formats/sonic_A1R5G5B5.dds"); + sonic[DDS_R4G4B4A4] = LoadTexture("resources/texture_formats/sonic_A4R4G4B4.dds"); + sonic[DDS_R8G8B8A8] = LoadTexture("resources/texture_formats/sonic_A8R8G8B8.dds"); + + // Load COMPRESSED DXT DDS texture data (if supported) + sonic[DDS_DXT1_RGB] = LoadTexture("resources/texture_formats/sonic_DXT1_RGB.dds"); + sonic[DDS_DXT1_RGBA] = LoadTexture("resources/texture_formats/sonic_DXT1_RGBA.dds"); + sonic[DDS_DXT3_RGBA] = LoadTexture("resources/texture_formats/sonic_DXT3_RGBA.dds"); + sonic[DDS_DXT5_RGBA] = LoadTexture("resources/texture_formats/sonic_DXT5_RGBA.dds"); + + // Load COMPRESSED ETC texture data (if supported) + sonic[PKM_ETC1_RGB] = LoadTexture("resources/texture_formats/sonic_ETC1_RGB.pkm"); + sonic[PKM_ETC2_RGB] = LoadTexture("resources/texture_formats/sonic_ETC2_RGB.pkm"); + sonic[PKM_ETC2_EAC_RGBA] = LoadTexture("resources/texture_formats/sonic_ETC2_EAC_RGBA.pkm"); + + sonic[KTX_ETC1_RGB] = LoadTexture("resources/texture_formats/sonic_ETC1_RGB.ktx"); + sonic[KTX_ETC2_RGB] = LoadTexture("resources/texture_formats/sonic_ETC2_RGB.ktx"); + sonic[KTX_ETC2_EAC_RGBA] = LoadTexture("resources/texture_formats/sonic_ETC2_EAC_RGBA.ktx"); + + // Load COMPRESSED ASTC texture data (if supported) + sonic[ASTC_4x4_LDR] = LoadTexture("resources/texture_formats/sonic_ASTC_4x4_ldr.astc"); + sonic[ASTC_8x8_LDR] = LoadTexture("resources/texture_formats/sonic_ASTC_8x8_ldr.astc"); + + // Load COMPRESSED PVR texture data (if supported) + sonic[PVR_PVRT_RGB] = LoadTexture("resources/texture_formats/sonic_PVRT_RGB.pvr"); + sonic[PVR_PVRT_RGBA] = LoadTexture("resources/texture_formats/sonic_PVRT_RGBA.pvr"); + + int selectedFormat = PNG_R8G8B8A8; + + Rectangle selectRecs[NUM_TEXTURES]; + + for (int i = 0; i < NUM_TEXTURES; i++) + { + if (i < NUM_TEXTURES/2) selectRecs[i] = (Rectangle){ 40, 45 + 32*i, 150, 30 }; + else selectRecs[i] = (Rectangle){ 40 + 152, 45 + 32*(i - NUM_TEXTURES/2), 150, 30 }; + } + + // Texture sizes in KB + float textureSizes[NUM_TEXTURES] = { + 512*512*32/8/1024, //PNG_R8G8B8A8 (32 bpp) + 512*512*8/8/1024, //PVR_GRAYSCALE (8 bpp) + 512*512*16/8/1024, //PVR_GRAY_ALPHA (16 bpp) + 512*512*16/8/1024, //PVR_R5G6B5 (16 bpp) + 512*512*16/8/1024, //PVR_R5G5B5A1 (16 bpp) + 512*512*16/8/1024, //PVR_R4G4B4A4 (16 bpp) + 512*512*16/8/1024, //DDS_R5G6B5 (16 bpp) + 512*512*16/8/1024, //DDS_R5G5B5A1 (16 bpp) + 512*512*16/8/1024, //DDS_R4G4B4A4 (16 bpp) + 512*512*32/8/1024, //DDS_R8G8B8A8 (32 bpp) + 512*512*4/8/1024, //DDS_DXT1_RGB (4 bpp) -Compressed- + 512*512*4/8/1024, //DDS_DXT1_RGBA (4 bpp) -Compressed- + 512*512*8/8/1024, //DDS_DXT3_RGBA (8 bpp) -Compressed- + 512*512*8/8/1024, //DDS_DXT5_RGBA (8 bpp) -Compressed- + 512*512*4/8/1024, //PKM_ETC1_RGB (4 bpp) -Compressed- + 512*512*4/8/1024, //PKM_ETC2_RGB (4 bpp) -Compressed- + 512*512*8/8/1024, //PKM_ETC2_EAC_RGBA (8 bpp) -Compressed- + 512*512*4/8/1024, //KTX_ETC1_RGB (4 bpp) -Compressed- + 512*512*4/8/1024, //KTX_ETC2_RGB (4 bpp) -Compressed- + 512*512*8/8/1024, //KTX_ETC2_EAC_RGBA (8 bpp) -Compressed- + 512*512*8/8/1024, //ASTC_4x4_LDR (8 bpp) -Compressed- + 512*512*2/8/1024, //ASTC_8x8_LDR (2 bpp) -Compressed- + 512*512*4/8/1024, //PVR_PVRT_RGB (4 bpp) -Compressed- + 512*512*4/8/1024, //PVR_PVRT_RGBA (4 bpp) -Compressed- + }; + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsKeyPressed(KEY_DOWN)) + { + selectedFormat++; + if (selectedFormat >= NUM_TEXTURES) selectedFormat = 0; + } + else if (IsKeyPressed(KEY_UP)) + { + selectedFormat--; + if (selectedFormat < 0) selectedFormat = NUM_TEXTURES - 1; + } + else if (IsKeyPressed(KEY_RIGHT)) + { + if (selectedFormat < NUM_TEXTURES/2) selectedFormat += NUM_TEXTURES/2; + } + else if (IsKeyPressed(KEY_LEFT)) + { + if (selectedFormat >= NUM_TEXTURES/2) selectedFormat -= NUM_TEXTURES/2; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + + BeginDrawing(); + + ClearBackground(RAYWHITE); + + // Draw rectangles + for (int i = 0; i < NUM_TEXTURES; i++) + { + if (i == selectedFormat) + { + DrawRectangleRec(selectRecs[i], SKYBLUE); + DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, BLUE); + DrawText(formatText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(formatText[i], 10)/2, selectRecs[i].y + 11, 10, DARKBLUE); + } + else + { + DrawRectangleRec(selectRecs[i], LIGHTGRAY); + DrawRectangleLines(selectRecs[i].x, selectRecs[i].y, selectRecs[i].width, selectRecs[i].height, GRAY); + DrawText(formatText[i], selectRecs[i].x + selectRecs[i].width/2 - MeasureText(formatText[i], 10)/2, selectRecs[i].y + 11, 10, DARKGRAY); + } + } + + // Draw selected texture + if (sonic[selectedFormat].id != 0) + { + DrawTexture(sonic[selectedFormat], 350, 0, WHITE); + } + else + { + DrawRectangleLines(488, 165, 200, 110, DARKGRAY); + DrawText("FORMAT", 550, 180, 20, MAROON); + DrawText("NOT SUPPORTED", 500, 210, 20, MAROON); + DrawText("ON YOUR GPU", 520, 240, 20, MAROON); + } + + DrawText("Select texture format (use cursor keys):", 40, 26, 10, DARKGRAY); + DrawText("Required GPU memory size (VRAM):", 40, 442, 10, DARKGRAY); + DrawText(FormatText("%4.0f KB", textureSizes[selectedFormat]), 240, 435, 20, DARKBLUE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + for (int i = 0; i < NUM_TEXTURES; i++) UnloadTexture(sonic[i]); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/textures_formats_loading.png b/examples/textures_formats_loading.png Binary files differnew file mode 100644 index 00000000..4cdb2f13 --- /dev/null +++ b/examples/textures_formats_loading.png diff --git a/examples/textures_logo_raylib.c b/examples/textures_logo_raylib.c index f4aeb738..2ebf0867 100644 --- a/examples/textures_logo_raylib.c +++ b/examples/textures_logo_raylib.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ diff --git a/examples/textures_particles_trail_blending.c b/examples/textures_particles_trail_blending.c new file mode 100644 index 00000000..1e7abf7e --- /dev/null +++ b/examples/textures_particles_trail_blending.c @@ -0,0 +1,132 @@ +/******************************************************************************************* +* +* raylib example - particles trail blending +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_PARTICLES 200 + +typedef struct { + Vector2 position; + Color color; + float alpha; + float size; + float rotation; + bool active; // NOTE: Use it to activate/deactive particle +} Particle; + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles trail blending"); + + // Particles pool, reuse them! + Particle mouseTail[MAX_PARTICLES]; + + // Initialize particles + for (int i = 0; i < MAX_PARTICLES; i++) + { + mouseTail[i].position = (Vector2){ 0, 0 }; + mouseTail[i].color = (Color){ GetRandomValue(0, 255), GetRandomValue(0, 255), GetRandomValue(0, 255), 255 }; + mouseTail[i].alpha = 1.0f; + mouseTail[i].size = (float)GetRandomValue(1, 30)/20; + mouseTail[i].rotation = GetRandomValue(0, 360); + mouseTail[i].active = false; + } + + float gravity = 3; + + Texture2D smoke = LoadTexture("resources/smoke.png"); + + int blending = BLEND_ALPHA; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + + // Activate one particle every frame and Update active particles + // NOTE: Particles initial position should be mouse position when activated + // NOTE: Particles fall down with gravity and rotation... and disappear after 2 seconds (alpha = 0) + // NOTE: When a particle disappears, active = false and it can be reused. + for (int i = 0; i < MAX_PARTICLES; i++) + { + if (!mouseTail[i].active) + { + mouseTail[i].active = true; + mouseTail[i].alpha = 1.0f; + mouseTail[i].position = GetMousePosition(); + i = MAX_PARTICLES; + } + } + + for (int i = 0; i < MAX_PARTICLES; i++) + { + if (mouseTail[i].active) + { + mouseTail[i].position.y += gravity; + mouseTail[i].alpha -= 0.01f; + + if (mouseTail[i].alpha <= 0.0f) mouseTail[i].active = false; + + mouseTail[i].rotation += 5; + } + } + + if (IsKeyPressed(KEY_SPACE)) + { + if (blending == BLEND_ALPHA) blending = BLEND_ADDITIVE; + else blending = BLEND_ALPHA; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(DARKGRAY); + + SetBlendMode(blending); + + // Draw active particles + for (int i = 0; i < MAX_PARTICLES; i++) + { + if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0, 0, smoke.width, smoke.height }, + (Rectangle){ mouseTail[i].position.x, mouseTail[i].position.y, smoke.width*mouseTail[i].size, smoke.height*mouseTail[i].size }, + (Vector2){ smoke.width*mouseTail[i].size/2, smoke.height*mouseTail[i].size/2 }, mouseTail[i].rotation, + Fade(mouseTail[i].color, mouseTail[i].alpha)); + } + + DrawText("PRESS SPACE to CHANGE BLENDING MODE", 180, 20, 20, RAYWHITE); + + if (blending == BLEND_ALPHA) DrawText("ALPHA BLENDING", 290, screenHeight - 40, 20, RAYWHITE); + else DrawText("ADDITIVE BLENDING", 280, screenHeight - 40, 20, RAYWHITE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(smoke); + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/textures_particles_trail_blending.png b/examples/textures_particles_trail_blending.png Binary files differnew file mode 100644 index 00000000..b0c40fd2 --- /dev/null +++ b/examples/textures_particles_trail_blending.png diff --git a/examples/textures_raw_data.c b/examples/textures_raw_data.c new file mode 100644 index 00000000..a4ff71b3 --- /dev/null +++ b/examples/textures_raw_data.c @@ -0,0 +1,90 @@ +/******************************************************************************************* +* +* raylib [textures] example - Load textures from raw data +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* This example has been created using raylib 1.3 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#include <stdlib.h> // Required for malloc() and free() + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [textures] example - texture from raw data"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + // Load RAW image data (512x512, 32bit RGBA, no file header) + Image sonicRaw = LoadImageRaw("resources/texture_formats/sonic_R8G8B8A8.raw", 512, 512, UNCOMPRESSED_R8G8B8A8, 0); + Texture2D sonic = LoadTextureFromImage(sonicRaw); // Upload CPU (RAM) image to GPU (VRAM) + UnloadImage(sonicRaw); // Unload CPU (RAM) image data + + // Generate a checked texture by code (1024x1024 pixels) + int width = 1024; + int height = 1024; + + Color *pixels = (Color *)malloc(width*height*sizeof(Color)); + + for (int y = 0; y < height; y++) + { + for (int x = 0; x < width; x++) + { + if (((x/32+y/32)/1)%2 == 0) pixels[y*height + x] = DARKBLUE; + else pixels[y*height + x] = SKYBLUE; + } + } + + // Load pixels data into an image structure and create texture + Image checkedIm = LoadImageEx(pixels, width, height); + Texture2D checked = LoadTextureFromImage(checkedIm); + UnloadImage(checkedIm); // Unload CPU (RAM) image data + free(pixels); // Unload CPU (RAM) pixels data + //--------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.3f)); + DrawTexture(sonic, 330, -20, WHITE); + + DrawText("CHECKED TEXTURE ", 84, 100, 30, DARKBLUE); + DrawText("GENERATED by CODE", 72, 164, 30, DARKBLUE); + DrawText("and RAW IMAGE LOADING", 46, 226, 30, DARKBLUE); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(sonic); // Texture unloading + UnloadTexture(checked); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/textures_raw_data.png b/examples/textures_raw_data.png Binary files differnew file mode 100644 index 00000000..374d2266 --- /dev/null +++ b/examples/textures_raw_data.png diff --git a/examples/textures_rectangle.c b/examples/textures_rectangle.c index c0fb0d97..61cce9fb 100644 --- a/examples/textures_rectangle.c +++ b/examples/textures_rectangle.c @@ -5,7 +5,7 @@ * 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) * -* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -20,15 +20,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); - const char textLine1[] = "Lena image is a standard test image which has been in use since 1973."; - const char textLine2[] = "It comprises 512x512 pixels, and it is probably the most widely used"; - const char textLine3[] = "test image for all sorts of image processing algorithms."; - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D texture = LoadTexture("resources/lena.png"); // Texture loading + Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading - Rectangle eyesRec = { 225, 240, 155, 50 }; // Part of the texture to draw - Vector2 position = { 369, 241 }; + Vector2 position = { 350, 240 }; + Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height }; + int currentFrame = 0; //-------------------------------------------------------------------------------------- // Main game loop @@ -36,7 +33,14 @@ int main() { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + if (IsKeyPressed(KEY_RIGHT)) + { + currentFrame++; + + if (currentFrame > 6) currentFrame = 0; + + frameRec.x = currentFrame*guybrush.width/7; + } //---------------------------------------------------------------------------------- // Draw @@ -45,15 +49,19 @@ int main() ClearBackground(RAYWHITE); - DrawText("LENA", 220, 100, 20, PINK); - - DrawTexture(texture, screenWidth/2 - 256, 0, Fade(WHITE, 0.1f)); // Draw background image - - DrawTextureRec(texture, eyesRec, position, WHITE); // Draw eyes part of image - - DrawText(textLine1, 220, 140, 10, DARKGRAY); - DrawText(textLine2, 220, 160, 10, DARKGRAY); - DrawText(textLine3, 220, 180, 10, DARKGRAY); + DrawTexture(guybrush, 35, 40, WHITE); + DrawRectangleLines(35, 40, guybrush.width, guybrush.height, LIME); + + DrawTextureRec(guybrush, frameRec, position, WHITE); // Draw part of the texture + + DrawRectangleLines(35 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); + + DrawText("PRESS RIGHT KEY to", 540, 310, 10, GRAY); + DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, GRAY); + + DrawText("Guybrush Ulysses Threepwood,", 100, 300, 10, GRAY); + DrawText("main character of the Monkey Island series", 80, 320, 10, GRAY); + DrawText("of computer adventure games by LucasArts.", 80, 340, 10, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -61,7 +69,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading + UnloadTexture(guybrush); // Texture unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/textures_rectangle.png b/examples/textures_rectangle.png Binary files differindex fb434a8e..d89404ab 100644 --- a/examples/textures_rectangle.png +++ b/examples/textures_rectangle.png diff --git a/examples/textures_srcrec_dstrec.c b/examples/textures_srcrec_dstrec.c index 1f0b56e2..72a209fb 100644 --- a/examples/textures_srcrec_dstrec.c +++ b/examples/textures_srcrec_dstrec.c @@ -5,7 +5,7 @@ * 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) +* Copyright (c) 2014 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -21,16 +21,23 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [textures] examples - texture source and destination rectangles"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D texture = LoadTexture("resources/raylib_logo.png"); // Texture loading + Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading + int frameWidth = guybrush.width/7; + int frameHeight = guybrush.height; + // NOTE: Source rectangle (part of the texture to use for drawing) - Rectangle sourceRec = { 128, 128, 128, 128 }; + Rectangle sourceRec = { 0, 0, frameWidth, frameHeight }; // NOTE: Destination rectangle (screen rectangle where drawing part of texture) - Rectangle destRec = { screenWidth/2, screenHeight/2, 256, 256 }; - - // NOTE: Origin of the texture in case of rotation, it's relative to destination rectangle size - Vector2 origin = { 128, 128 }; + Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 }; + + // NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size + Vector2 origin = { frameWidth, frameHeight }; + + int rotation = 0; + + SetTargetFPS(60); //-------------------------------------------------------------------------------------- // Main game loop @@ -38,7 +45,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - // TODO: Update your variables here + rotation++; //---------------------------------------------------------------------------------- // Draw @@ -48,10 +55,10 @@ int main() ClearBackground(RAYWHITE); // NOTE: Using DrawTexturePro() we can easily rotate and scale the part of the texture we draw - DrawTexturePro(texture, sourceRec, destRec, origin, 45, LIGHTGRAY); + DrawTexturePro(guybrush, sourceRec, destRec, origin, rotation, WHITE); - DrawLine(destRec.x, 0, destRec.x, screenHeight, RED); - DrawLine(0, destRec.y, screenWidth, destRec.y, RED); + DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY); + DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -59,7 +66,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(texture); // Texture unloading + UnloadTexture(guybrush); // Texture unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/textures_srcrec_dstrec.png b/examples/textures_srcrec_dstrec.png Binary files differindex 95b7130e..7459d6ec 100644 --- a/examples/textures_srcrec_dstrec.png +++ b/examples/textures_srcrec_dstrec.png diff --git a/examples/textures_to_image.c b/examples/textures_to_image.c new file mode 100644 index 00000000..3ea8e017 --- /dev/null +++ b/examples/textures_to_image.c @@ -0,0 +1,68 @@ +/******************************************************************************************* +* +* raylib [textures] example - Retrieve image data from texture: GetTextureData() +* +* NOTE: Images are loaded in CPU memory (RAM); textures are loaded in GPU memory (VRAM) +* +* 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 to image"); + + // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) + + Image image = LoadImage("resources/raylib_logo.png"); // Load image data into CPU memory (RAM) + Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (RAM -> VRAM) + UnloadImage(image); // Unload image data from CPU memory (RAM) + + image = GetTextureData(texture); // Retrieve image data from GPU memory (VRAM -> RAM) + UnloadTexture(texture); // Unload texture from GPU memory (VRAM) + + texture = LoadTextureFromImage(image); // Recreate texture from retrieved image data (RAM -> VRAM) + UnloadImage(image); // Unload retrieved image data from CPU memory (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, WHITE); + + DrawText("this IS a texture loaded from an image!", 300, 370, 10, GRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadTexture(texture); // Texture unloading + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/examples/textures_to_image.png b/examples/textures_to_image.png Binary files differnew file mode 100644 index 00000000..410103a5 --- /dev/null +++ b/examples/textures_to_image.png |
