diff options
| author | Ray <[email protected]> | 2018-08-14 19:32:27 +0200 |
|---|---|---|
| committer | Ray <[email protected]> | 2018-08-14 19:32:27 +0200 |
| commit | ab07e099dbf782c4c69cd0f0e06d1f37a3a887bf (patch) | |
| tree | 3b251a6667d3ea3696b0435f9b5306be31d32ba4 /examples/src | |
| parent | a8e30fb58fcc414aae8533f6f118c4f005b02833 (diff) | |
| download | raylib.com-ab07e099dbf782c4c69cd0f0e06d1f37a3a887bf.tar.gz raylib.com-ab07e099dbf782c4c69cd0f0e06d1f37a3a887bf.zip | |
Updated examples
Diffstat (limited to 'examples/src')
29 files changed, 270 insertions, 185 deletions
diff --git a/examples/src/audio/audio_raw_stream.c b/examples/src/audio/audio_raw_stream.c index 80c83e9..7eee46f 100644 --- a/examples/src/audio/audio_raw_stream.c +++ b/examples/src/audio/audio_raw_stream.c @@ -7,7 +7,7 @@ * This example has been created using raylib 1.6 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* Copyright (c) 2015-2018 Ramon Santamaria (@raysan5) and James Hofmann (@triplefox) * ********************************************************************************************/ @@ -15,8 +15,9 @@ #include <stdlib.h> // Required for: malloc(), free() #include <math.h> // Required for: sinf() +#include <string.h> // Required for: memcpy() -#define MAX_SAMPLES 22050 +#define MAX_SAMPLES 512 #define MAX_SAMPLES_PER_UPDATE 4096 int main() @@ -33,20 +34,28 @@ int main() // Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono) AudioStream stream = InitAudioStream(22050, 16, 1); - // Generate samples data from sine wave + // Buffer for the single cycle waveform we are synthesizing short *data = (short *)malloc(sizeof(short)*MAX_SAMPLES); - - // TODO: Review data generation, it seems data is discontinued for loop, - // for that reason, there is a clip everytime audio stream is looped... - for (int i = 0; i < MAX_SAMPLES; i++) - { - data[i] = (short)(sinf(((2*PI*(float)i)/2)*DEG2RAD)*32000); - } + + // Frame buffer, describing the waveform when repeated over the course of a frame + short *writeBuf = (short *)malloc(sizeof(short)*MAX_SAMPLES_PER_UPDATE); PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently) - int totalSamples = MAX_SAMPLES; - int samplesLeft = totalSamples; + // Position read in to determine next frequency + Vector2 mousePosition = { -100.0f, -100.0f }; + + // Cycles per second (hz) + float frequency = 440.0f; + + // Previous value, used to test if sine needs to be rewritten, and to smoothly modulate frequency + float oldFrequency = 1.0f; + + // Cursor to read and copy the samples of the sine wave buffer + int readCursor = 0; + + // Computed size in samples of the sine wave + int waveLength = 1; Vector2 position = { 0, 0 }; @@ -59,22 +68,63 @@ int main() // Update //---------------------------------------------------------------------------------- + // Sample mouse input. + mousePosition = GetMousePosition(); + + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) + { + float fp = (float)(mousePosition.y); + frequency = 40.0f + (float)(fp); + } + + // Rewrite the sine wave. + // Compute two cycles to allow the buffer padding, simplifying any modulation, resampling, etc. + if (frequency != oldFrequency) + { + // Compute wavelength. Limit size in both directions. + int oldWavelength = waveLength; + waveLength = (int)(22050/frequency); + if (waveLength > MAX_SAMPLES/2) waveLength = MAX_SAMPLES/2; + if (waveLength < 1) waveLength = 1; + + // Write sine wave. + for (int i = 0; i < waveLength*2; i++) + { + data[i] = (short)(sinf(((2*PI*(float)i/waveLength)))*32000); + } + + // Scale read cursor's position to minimize transition artifacts + readCursor = (int)(readCursor * ((float)waveLength / (float)oldWavelength)); + oldFrequency = frequency; + } + // Refill audio stream if required - // NOTE: Every update we check if stream data has been already consumed and we update - // buffer with new data from the generated samples, we upload data at a rate (MAX_SAMPLES_PER_UPDATE), - // but notice that at some point we update < MAX_SAMPLES_PER_UPDATE data... if (IsAudioBufferProcessed(stream)) { - int numSamples = 0; - if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE; - else numSamples = samplesLeft; - - UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples); + // Synthesize a buffer that is exactly the requested size + int writeCursor = 0; - samplesLeft -= numSamples; + while (writeCursor < MAX_SAMPLES_PER_UPDATE) + { + // Start by trying to write the whole chunk at once + int writeLength = MAX_SAMPLES_PER_UPDATE-writeCursor; + + // Limit to the maximum readable size + int readLength = waveLength-readCursor; + + if (writeLength > readLength) writeLength = readLength; + + // Write the slice + memcpy(writeBuf + writeCursor, data + readCursor, writeLength*sizeof(short)); + + // Update cursors and loop audio + readCursor = (readCursor + writeLength) % waveLength; + + writeCursor += writeLength; + } - // Reset samples feeding (loop audio) - if (samplesLeft <= 0) samplesLeft = totalSamples; + // Copy finished frame to audio stream + UpdateAudioStream(stream, writeBuf, MAX_SAMPLES_PER_UPDATE); } //---------------------------------------------------------------------------------- @@ -84,13 +134,14 @@ int main() ClearBackground(RAYWHITE); - DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY); + DrawText(FormatText("sine frequency: %i",(int)frequency), GetScreenWidth() - 220, 10, 20, RED); + DrawText("click mouse button to change frequency", 10, 10, 20, DARKGRAY); - // NOTE: Draw a part of the sine wave (only screen width, proportional values) - for (int i = 0; i < GetScreenWidth(); i++) + // Draw the current buffer state proportionate to the screen + for (int i = 0; i < screenWidth; i++) { position.x = i; - position.y = 250 + 50*data[i]/32000; + position.y = 250 + 50*data[i*MAX_SAMPLES/screenWidth]/32000; DrawPixelV(position, RED); } @@ -102,13 +153,13 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- free(data); // Unload sine wave data + free(writeBuf); // Unload write buffer CloseAudioStream(stream); // Close raw audio stream and delete buffers from RAM - CloseAudioDevice(); // Close audio device (music streaming is automatically stopped) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; -}
\ No newline at end of file +} diff --git a/examples/src/core/core_2d_camera.c b/examples/src/core/core_2d_camera.c index f2f219e..7c35c90 100644 --- a/examples/src/core/core_2d_camera.c +++ b/examples/src/core/core_2d_camera.c @@ -97,7 +97,7 @@ int main() ClearBackground(RAYWHITE); - Begin2dMode(camera); + BeginMode2D(camera); DrawRectangle(-6000, 320, 13000, 8000, DARKGRAY); @@ -108,7 +108,7 @@ int main() DrawRectangle(camera.target.x, -500, 1, screenHeight*4, GREEN); DrawRectangle(-500, camera.target.y, screenWidth*4, 1, GREEN); - End2dMode(); + EndMode2D(); DrawText("SCREEN AREA", 640, 10, 20, RED); diff --git a/examples/src/core/core_3d_camera_first_person.c b/examples/src/core/core_3d_camera_first_person.c index 3998af8..d3a8f2e 100644 --- a/examples/src/core/core_3d_camera_first_person.c +++ b/examples/src/core/core_3d_camera_first_person.c @@ -23,7 +23,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera first person"); // Define the camera to look into our 3d world (position, target, up vector) - Camera camera = {{ 4.0f, 2.0f, 4.0f }, { 0.0f, 1.8f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 60.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 4.0f, 2.0f, 4.0f }; + camera.target = (Vector3){ 0.0f, 1.8f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 60.0f; + camera.type = CAMERA_PERSPECTIVE; // Generates some random columns float heights[MAX_COLUMNS]; @@ -56,7 +61,7 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawPlane((Vector3){ 0.0f, 0.0f, 0.0f }, (Vector2){ 32.0f, 32.0f }, LIGHTGRAY); // Draw ground DrawCube((Vector3){ -16.0f, 2.5f, 0.0f }, 1.0f, 5.0f, 32.0f, BLUE); // Draw a blue wall @@ -70,7 +75,7 @@ int main() DrawCubeWires(positions[i], 2.0f, heights[i], 2.0f, MAROON); } - End3dMode(); + EndMode3D(); DrawRectangle( 10, 10, 220, 70, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 220, 70, BLUE); diff --git a/examples/src/core/core_3d_camera_free.c b/examples/src/core/core_3d_camera_free.c index d446e14..9131ddf 100644 --- a/examples/src/core/core_3d_camera_free.c +++ b/examples/src/core/core_3d_camera_free.c @@ -21,11 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera; + Camera3D camera; camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; // Camera position camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y + camera.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -50,14 +51,14 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - End3dMode(); + EndMode3D(); DrawRectangle( 10, 10, 320, 133, Fade(SKYBLUE, 0.5f)); DrawRectangleLines( 10, 10, 320, 133, BLUE); diff --git a/examples/src/core/core_3d_mode.c b/examples/src/core/core_3d_mode.c index 5f76165..39c0752 100644 --- a/examples/src/core/core_3d_mode.c +++ b/examples/src/core/core_3d_mode.c @@ -21,11 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d mode"); // Define the camera to look into our 3d world - Camera camera; + Camera3D camera; camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; // Camera position camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y + camera.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -46,14 +47,14 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - End3dMode(); + EndMode3D(); DrawText("Welcome to the third dimension!", 10, 40, 20, DARKGRAY); diff --git a/examples/src/core/core_3d_picking.c b/examples/src/core/core_3d_picking.c index 7658b39..1c63e2a 100644 --- a/examples/src/core/core_3d_picking.c +++ b/examples/src/core/core_3d_picking.c @@ -26,14 +26,15 @@ int main() camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 45.0f; // Camera field-of-view Y + camera.type = CAMERA_PERSPECTIVE; // Camera mode type Vector3 cubePosition = { 0.0f, 1.0f, 0.0f }; Vector3 cubeSize = { 2.0f, 2.0f, 2.0f }; - - Ray ray; // Picking line ray - + + Ray ray = {0.0f, 0.0f, 0.0f}; // Picking line ray + bool collision = false; - + SetCameraMode(camera, CAMERA_FREE); // Set a free camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second @@ -45,11 +46,11 @@ int main() // Update //---------------------------------------------------------------------------------- UpdateCamera(&camera); // Update camera - + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { ray = GetMouseRay(GetMousePosition(), camera); - + // Check collision between ray and box collision = CheckCollisionRayBox(ray, (BoundingBox){(Vector3){ cubePosition.x - cubeSize.x/2, cubePosition.y - cubeSize.y/2, cubePosition.z - cubeSize.z/2 }, @@ -63,9 +64,9 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); - if (collision) + if (collision) { DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, RED); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, MAROON); @@ -77,15 +78,14 @@ int main() DrawCube(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, GRAY); DrawCubeWires(cubePosition, cubeSize.x, cubeSize.y, cubeSize.z, DARKGRAY); } - + DrawRay(ray, MAROON); - DrawGrid(10, 1.0f); - End3dMode(); - + EndMode3D(); + DrawText("Try selecting the box with mouse!", 240, 10, 20, DARKGRAY); - + if(collision) DrawText("BOX SELECTED", (screenWidth - MeasureText("BOX SELECTED", 30)) / 2, screenHeight * 0.1f, 30, GREEN); DrawFPS(10, 10); @@ -100,4 +100,4 @@ int main() //-------------------------------------------------------------------------------------- return 0; -}
\ No newline at end of file +} diff --git a/examples/src/core/core_basic_window.c b/examples/src/core/core_basic_window.c index 1db38c9..51caa45 100644 --- a/examples/src/core/core_basic_window.c +++ b/examples/src/core/core_basic_window.c @@ -1,8 +1,6 @@ /******************************************************************************************* * -* raylib [core] example - Basic window -* -* Welcome to raylib! +* raylib [core] example - basic window * * 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) diff --git a/examples/src/core/core_input_keys.c b/examples/src/core/core_input_keys.c index b230524..69384fd 100644 --- a/examples/src/core/core_input_keys.c +++ b/examples/src/core/core_input_keys.c @@ -30,10 +30,10 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 0.8f; - if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 0.8f; - if (IsKeyDown(KEY_UP)) ballPosition.y -= 0.8f; - if (IsKeyDown(KEY_DOWN)) ballPosition.y += 0.8f; + if (IsKeyDown(KEY_RIGHT)) ballPosition.x += 2.0f; + if (IsKeyDown(KEY_LEFT)) ballPosition.x -= 2.0f; + if (IsKeyDown(KEY_UP)) ballPosition.y -= 2.0f; + if (IsKeyDown(KEY_DOWN)) ballPosition.y += 2.0f; //---------------------------------------------------------------------------------- // Draw diff --git a/examples/src/core/core_vr_simulator.c b/examples/src/core/core_vr_simulator.c index d919c41..3f59e83 100644 --- a/examples/src/core/core_vr_simulator.c +++ b/examples/src/core/core_vr_simulator.c @@ -31,6 +31,7 @@ int main() camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 60.0f; // Camera field-of-view Y + camera.type = CAMERA_PERSPECTIVE; // Camera type Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -57,14 +58,14 @@ int main() BeginVrDrawing(); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(40, 1.0f); - End3dMode(); + EndMode3D(); EndVrDrawing(); diff --git a/examples/src/core/core_world_screen.c b/examples/src/core/core_world_screen.c index f8c53c7..460f6b8 100644 --- a/examples/src/core/core_world_screen.c +++ b/examples/src/core/core_world_screen.c @@ -21,7 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [core] example - 3d camera free"); // Define the camera to look into our 3d world - Camera camera = {{ 10.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 10.0f, 10.0f, 10.0f }; + camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; Vector3 cubePosition = { 0.0f, 0.0f, 0.0f }; @@ -49,14 +54,14 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); DrawGrid(10, 1.0f); - End3dMode(); + EndMode3D(); DrawText("Enemy: 100 / 100", cubeScreenPosition.x - MeasureText("Enemy: 100 / 100", 20) / 2, cubeScreenPosition.y, 20, BLACK); DrawText("Text is always on top of the cube", (screenWidth - MeasureText("Text is always on top of the cube", 20)) / 2, 25, 20, GRAY); diff --git a/examples/src/models/models_billboard.c b/examples/src/models/models_billboard.c index bca9faf..8ce6a44 100644 --- a/examples/src/models/models_billboard.c +++ b/examples/src/models/models_billboard.c @@ -21,7 +21,13 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - drawing billboards"); // Define the camera to look into our 3d world - Camera camera = {{ 5.0f, 4.0f, 5.0f }, { 0.0f, 2.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 5.0f, 4.0f, 5.0f }; + camera.target = (Vector3){ 0.0f, 2.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; + Texture2D bill = LoadTexture("resources/billboard.png"); // Our texture billboard Vector3 billPosition = { 0.0f, 2.0f, 0.0f }; // Position where draw billboard @@ -45,13 +51,13 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawBillboard(camera, bill, billPosition, 2.0f, WHITE); DrawGrid(10, 1.0f); // Draw a grid - End3dMode(); + EndMode3D(); DrawFPS(10, 10); diff --git a/examples/src/models/models_box_collisions.c b/examples/src/models/models_box_collisions.c index 69cec41..41f6056 100644 --- a/examples/src/models/models_box_collisions.c +++ b/examples/src/models/models_box_collisions.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - box collisions"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; Vector3 playerPosition = { 0.0f, 1.0f, 2.0f }; Vector3 playerSize = { 1.0f, 2.0f, 1.0f }; @@ -87,7 +87,7 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); // Draw enemy-box DrawCube(enemyBoxPos, enemyBoxSize.x, enemyBoxSize.y, enemyBoxSize.z, GRAY); @@ -102,7 +102,7 @@ int main() DrawGrid(10, 1.0f); // Draw a grid - End3dMode(); + EndMode3D(); DrawText("Move player with cursors to collide", 220, 40, 20, GRAY); diff --git a/examples/src/models/models_cubicmap.c b/examples/src/models/models_cubicmap.c index d8be932..c8d62c4 100644 --- a/examples/src/models/models_cubicmap.c +++ b/examples/src/models/models_cubicmap.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - cubesmap loading and drawing"); // Define the camera to look into our 3d world - Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 16.0f, 14.0f, 16.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; Image image = LoadImage("resources/cubicmap.png"); // Load cubicmap image (RAM) Texture2D cubicmap = LoadTextureFromImage(image); // Convert image to texture to display (VRAM) @@ -56,11 +56,11 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawModel(model, mapPosition, 1.0f, WHITE); - End3dMode(); + EndMode3D(); 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); diff --git a/examples/src/models/models_geometric_shapes.c b/examples/src/models/models_geometric_shapes.c index a13a1f3..82ca4c6 100644 --- a/examples/src/models/models_geometric_shapes.c +++ b/examples/src/models/models_geometric_shapes.c @@ -21,7 +21,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - geometric shapes"); // Define the camera to look into our 3d world - Camera camera = {{ 0.0f, 10.0f, 10.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = { 0 }; + camera.position = (Vector3){ 0.0f, 10.0f, 10.0f }; + camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; + camera.fovy = 45.0f; + camera.type = CAMERA_PERSPECTIVE; SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -40,7 +45,7 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawCube((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, RED); DrawCubeWires((Vector3){-4.0f, 0.0f, 2.0f}, 2.0f, 5.0f, 2.0f, GOLD); @@ -58,7 +63,7 @@ int main() DrawGrid(10, 1.0f); // Draw a grid - End3dMode(); + EndMode3D(); DrawFPS(10, 10); diff --git a/examples/src/models/models_heightmap.c b/examples/src/models/models_heightmap.c index e476d1b..d131b12 100644 --- a/examples/src/models/models_heightmap.c +++ b/examples/src/models/models_heightmap.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - heightmap loading and drawing"); // Define our custom camera to look into our 3d world - Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 18.0f, 16.0f, 18.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; Image image = LoadImage("resources/heightmap.png"); // Load heightmap image (RAM) Texture2D texture = LoadTextureFromImage(image); // Convert image to texture (VRAM) @@ -53,13 +53,13 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawModel(model, mapPosition, 1.0f, RED); DrawGrid(20, 1.0f); - End3dMode(); + EndMode3D(); DrawTexture(texture, screenWidth - texture.width - 20, 20, WHITE); DrawRectangleLines(screenWidth - texture.width - 20, 20, texture.width, texture.height, GREEN); diff --git a/examples/src/models/models_mesh_generation.c b/examples/src/models/models_mesh_generation.c index 7222215..c02bd91 100644 --- a/examples/src/models/models_mesh_generation.c +++ b/examples/src/models/models_mesh_generation.c @@ -41,7 +41,7 @@ int main() for (int i = 0; i < NUM_MODELS; i++) models[i].material.maps[MAP_DIFFUSE].texture = texture; // Define the camera to look into our 3d world - Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 5.0f, 5.0f, 5.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Model drawing position Vector3 position = { 0.0f, 0.0f, 0.0f }; @@ -72,13 +72,13 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); DrawModel(models[currentModel], position, 1.0f, WHITE); DrawGrid(10, 1.0); - End3dMode(); + EndMode3D(); DrawRectangle(30, 400, 310, 30, Fade(SKYBLUE, 0.5f)); DrawRectangleLines(30, 400, 310, 30, Fade(DARKBLUE, 0.5f)); diff --git a/examples/src/models/models_skybox.c b/examples/src/models/models_skybox.c index 46297e4..6f6002b 100644 --- a/examples/src/models/models_skybox.c +++ b/examples/src/models/models_skybox.c @@ -21,7 +21,7 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - skybox loading and drawing"); // Define the camera to look into our 3d world - Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; + Camera camera = {{ 1.0f, 1.0f, 1.0f }, { 0.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f, 0 }; // Load skybox model Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); @@ -36,12 +36,17 @@ int main() Shader shdrCubemap = LoadShader("resources/shaders/cubemap.vs", "resources/shaders/cubemap.fs"); SetShaderValuei(shdrCubemap, GetShaderLocation(shdrCubemap, "equirectangularMap"), (int[1]){ 0 }, 1); - Texture2D texHDR = LoadTexture("resources/pinetree.hdr"); + // Load HDR panorama (sphere) texture + Texture2D texHDR = LoadTexture("resources/dresden_square.hdr"); + + // Generate cubemap (texture with 6 quads-cube-mapping) from panorama HDR texture + // NOTE: New texture is generated rendering to texture, shader computes the sphre->cube coordinates mapping skybox.material.maps[MAP_CUBEMAP].texture = GenTextureCubemap(shdrCubemap, texHDR, 512); - UnloadShader(shdrCubemap); // Cubemap generation shader not required any more + UnloadTexture(texHDR); // Texture not required anymore, cubemap already generated + UnloadShader(shdrCubemap); // Unload cubemap generation shader, not required anymore - SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode + SetCameraMode(camera, CAMERA_FIRST_PERSON); // Set a first person camera mode SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -60,13 +65,13 @@ int main() ClearBackground(RAYWHITE); - Begin3dMode(camera); + BeginMode3D(camera); - DrawModel(skybox, Vector3Zero(), 1.0f, WHITE); + DrawModel(skybox, (Vector3){0, 0, 0}, 1.0f, WHITE); DrawGrid(10, 1.0f); - End3dMode(); + EndMode3D(); DrawFPS(10, 10); @@ -76,7 +81,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadModel(skybox); // Unload skybox model + UnloadModel(skybox); // Unload skybox model (and textures) CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/models/models_yaw_pitch_roll.c b/examples/src/models/models_yaw_pitch_roll.c index 2bae2bf..0dcf8c7 100644 --- a/examples/src/models/models_yaw_pitch_roll.c +++ b/examples/src/models/models_yaw_pitch_roll.c @@ -5,7 +5,7 @@ * This example has been created using raylib 1.8 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Example based on Berni work on Raspberry Pi: +* Example based on Berni work on Raspberry Pi: * http://forum.raylib.com/index.php?p=/discussion/124/line-versus-triangle-drawing-order * * Copyright (c) 2017 Ramon Santamaria (@raysan5) @@ -30,25 +30,26 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [models] example - plane rotations (yaw, pitch, roll)"); - Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); + Texture2D texAngleGauge = LoadTexture("resources/angle_gauge.png"); Texture2D texBackground = LoadTexture("resources/background.png"); - Texture2D texPitch = LoadTexture("resources/pitch.png"); + Texture2D texPitch = LoadTexture("resources/pitch.png"); Texture2D texPlane = LoadTexture("resources/plane.png"); RenderTexture2D framebuffer = LoadRenderTexture(192, 192); - + // Model loading Model model = LoadModel("resources/plane.obj"); // Load OBJ model model.material.maps[MAP_DIFFUSE].texture = LoadTexture("resources/plane_diffuse.png"); // Set map diffuse texture - + GenTextureMipmaps(&model.material.maps[MAP_DIFFUSE].texture); - + Camera camera = { 0 }; camera.position = (Vector3){ 0.0f, 60.0f, -120.0f };// Camera position perspective camera.target = (Vector3){ 0.0f, 12.0f, 0.0f }; // Camera looking at point camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; // Camera up vector (rotation towards target) camera.fovy = 30.0f; // Camera field-of-view Y - + camera.type = CAMERA_PERSPECTIVE; // Camera type + float pitch = 0.0f; float roll = 0.0f; float yaw = 0.0f; @@ -61,7 +62,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - + // Plane roll (x-axis) controls if (IsKeyDown(KEY_LEFT)) roll += 1.0f; else if (IsKeyDown(KEY_RIGHT)) roll -= 1.0f; @@ -70,7 +71,7 @@ int main() if (roll > 0.0f) roll -= 0.5f; else if (roll < 0.0f) roll += 0.5f; } - + // Plane yaw (y-axis) controls if (IsKeyDown(KEY_S)) yaw += 1.0f; else if (IsKeyDown(KEY_A)) yaw -= 1.0f; @@ -79,7 +80,7 @@ int main() if (yaw > 0.0f) yaw -= 0.5f; else if (yaw < 0.0f) yaw += 0.5f; } - + // Plane pitch (z-axis) controls if (IsKeyDown(KEY_DOWN)) pitch += 0.6f; else if (IsKeyDown(KEY_UP)) pitch -= 0.6f; @@ -88,7 +89,7 @@ int main() if (pitch > 0.3f) pitch -= 0.3f; else if (pitch < -0.3f) pitch += 0.3f; } - + // Wraps the phase of an angle to fit between -180 and +180 degrees int pitchOffset = pitch; while (pitchOffset > 180) pitchOffset -= 360; @@ -96,20 +97,20 @@ int main() pitchOffset *= 10; Matrix transform = MatrixIdentity(); - + transform = MatrixMultiply(transform, MatrixRotateZ(DEG2RAD*roll)); transform = MatrixMultiply(transform, MatrixRotateX(DEG2RAD*pitch)); transform = MatrixMultiply(transform, MatrixRotateY(DEG2RAD*yaw)); - + model.transform = transform; //---------------------------------------------------------------------------------- // Draw //---------------------------------------------------------------------------------- BeginDrawing(); - + ClearBackground(RAYWHITE); - + // Draw framebuffer texture (Ahrs Display) int centerX = framebuffer.texture.width/2; int centerY = framebuffer.texture.height/2; @@ -119,35 +120,35 @@ int main() BeginBlendMode(BLEND_ALPHA); - DrawTexturePro(texBackground, (Rectangle){0,0,texBackground.width, texBackground.height}, + DrawTexturePro(texBackground, (Rectangle){ 0, 0, texBackground.width, texBackground.height }, (Rectangle){ centerX, centerY, texBackground.width*scaleFactor, texBackground.height*scaleFactor}, - (Vector2){texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor}, roll, WHITE); + (Vector2){ texBackground.width/2*scaleFactor, texBackground.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE); DrawTexturePro(texPitch, (Rectangle){ 0, 0, texPitch.width, texPitch.height }, (Rectangle){ centerX, centerY, texPitch.width*scaleFactor, texPitch.height*scaleFactor }, (Vector2){ texPitch.width/2*scaleFactor, texPitch.height/2*scaleFactor + pitchOffset*scaleFactor }, roll, WHITE); - - DrawTexturePro(texPlane, (Rectangle){0,0,texPlane.width, texPlane.height }, - (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, - (Vector2){texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); - + + DrawTexturePro(texPlane, (Rectangle){ 0, 0, texPlane.width, texPlane.height }, + (Rectangle){ centerX, centerY, texPlane.width*scaleFactor, texPlane.height*scaleFactor }, + (Vector2){ texPlane.width/2*scaleFactor, texPlane.height/2*scaleFactor }, 0, WHITE); + EndBlendMode(); EndTextureMode(); // Draw 3D model (recomended to draw 3D always before 2D) - Begin3dMode(camera); + BeginMode3D(camera); DrawModel(model, (Vector3){ 0, 6.0f, 0 }, 1.0f, WHITE); // Draw 3d model with texture DrawGrid(10, 10.0f); - End3dMode(); + EndMode3D(); // Draw 2D GUI stuff - DrawAngleGauge(texAngleGauge, 80, 80, roll, "roll", RED); - DrawAngleGauge(texAngleGauge, 190, 80, pitch, "pitch", GREEN); - DrawAngleGauge(texAngleGauge, 300, 80, yaw, "yaw", SKYBLUE); - + DrawAngleGauge(texAngleGauge, 80, 70, roll, "roll", RED); + DrawAngleGauge(texAngleGauge, 190, 70, pitch, "pitch", GREEN); + DrawAngleGauge(texAngleGauge, 300, 70, yaw, "yaw", SKYBLUE); + DrawRectangle(30, 360, 260, 70, Fade(SKYBLUE, 0.5f)); DrawRectangleLines(30, 360, 260, 70, Fade(DARKBLUE, 0.5f)); DrawText("Pitch controlled with: KEY_UP / KEY_DOWN", 40, 370, 10, DARKGRAY); @@ -155,31 +156,31 @@ int main() DrawText("Yaw controlled with: KEY_A / KEY_S", 40, 410, 10, DARKGRAY); // Draw framebuffer texture - DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height }, + DrawTextureRec(framebuffer.texture, (Rectangle){ 0, 0, framebuffer.texture.width, -framebuffer.texture.height }, (Vector2){ screenWidth - framebuffer.texture.width - 20, 20 }, Fade(WHITE, 0.8f)); - + DrawRectangleLines(screenWidth - framebuffer.texture.width - 20, 20, framebuffer.texture.width, framebuffer.texture.height, DARKGRAY); - + EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- - + // Unload all loaded data UnloadModel(model); - + UnloadRenderTexture(framebuffer); - - UnloadTexture(texAngleGauge); + + UnloadTexture(texAngleGauge); UnloadTexture(texBackground); - UnloadTexture(texPitch); + UnloadTexture(texPitch); UnloadTexture(texPlane); - + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- - + return 0; } @@ -192,7 +193,7 @@ void DrawAngleGauge(Texture2D angleGauge, int x, int y, float angle, char title[ int textSize = 20; DrawTexturePro(angleGauge, srcRec, dstRec, origin, angle, color); - - DrawText(FormatText("%5.1f�", angle), x - MeasureText(FormatText("%5.1f�", angle), textSize) / 2, y + 10, textSize, DARKGRAY); - DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); -}
\ No newline at end of file + + DrawText(FormatText("%5.1f", angle), x - MeasureText(FormatText("%5.1f", angle), textSize) / 2, y + 10, textSize, DARKGRAY); + DrawText(title, x - MeasureText(title, textSize) / 2, y + 60, textSize, DARKGRAY); +} diff --git a/examples/src/text/text_bmfont_ttf.c b/examples/src/text/text_bmfont_ttf.c index 0778fd1..f71f5dd 100644 --- a/examples/src/text/text_bmfont_ttf.c +++ b/examples/src/text/text_bmfont_ttf.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [text] example - BMFont and TTF SpriteFonts loading +* raylib [text] example - BMFont and TTF Fonts loading * * This example has been created using raylib 1.4 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -24,8 +24,8 @@ int main() const char msgTtf[64] = "THIS SPRITE FONT has been GENERATED from a TTF"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont fontBm = LoadSpriteFont("resources/bmfont.fnt"); // BMFont (AngelCode) - SpriteFont fontTtf = LoadSpriteFont("resources/pixantiqua.ttf"); // TTF font + Font fontBm = LoadFont("resources/bmfont.fnt"); // BMFont (AngelCode) + Font fontTtf = LoadFont("resources/pixantiqua.ttf"); // TTF font Vector2 fontPosition; @@ -58,8 +58,8 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadSpriteFont(fontBm); // AngelCode SpriteFont unloading - UnloadSpriteFont(fontTtf); // TTF SpriteFont unloading + UnloadFont(fontBm); // AngelCode Font unloading + UnloadFont(fontTtf); // TTF Font unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/text/text_bmfont_unordered.c b/examples/src/text/text_bmfont_unordered.c index 01561be..a514761 100644 --- a/examples/src/text/text_bmfont_unordered.c +++ b/examples/src/text/text_bmfont_unordered.c @@ -25,7 +25,7 @@ int main() const char msg[256] = "ASCII extended characters:\n¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆ\nÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæ\nçèéêëìíîïðñòóôõö÷øùúûüýþÿ"; // NOTE: Loaded font has an unordered list of characters (chars in the range 32..255) - SpriteFont font = LoadSpriteFont("resources/pixantiqua.fnt"); // BMFont (AngelCode) + Font font = LoadFont("resources/pixantiqua.fnt"); // BMFont (AngelCode) SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -56,7 +56,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadSpriteFont(font); // AngelCode SpriteFont unloading + UnloadFont(font); // AngelCode Font unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/text/text_input_box.c b/examples/src/text/text_input_box.c index 54eebf4..5f8d1c0 100644 --- a/examples/src/text/text_input_box.c +++ b/examples/src/text/text_input_box.c @@ -52,7 +52,7 @@ int main() letterCount++; } - if (key == KEY_BACKSPACE) + if (IsKeyPressed(KEY_BACKSPACE)) { letterCount--; name[letterCount] = '\0'; diff --git a/examples/src/text/text_raylib_fonts.c b/examples/src/text/text_raylib_fonts.c index 6d8ef2b..3c930ac 100644 --- a/examples/src/text/text_raylib_fonts.c +++ b/examples/src/text/text_raylib_fonts.c @@ -26,16 +26,16 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont fonts[MAX_FONTS]; + Font fonts[MAX_FONTS]; - fonts[0] = LoadSpriteFont("resources/fonts/alagard.png"); - fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.png"); - fonts[2] = LoadSpriteFont("resources/fonts/mecha.png"); - fonts[3] = LoadSpriteFont("resources/fonts/setback.png"); - fonts[4] = LoadSpriteFont("resources/fonts/romulus.png"); - fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.png"); - fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.png"); - fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.png"); + fonts[0] = LoadFont("resources/fonts/alagard.png"); + fonts[1] = LoadFont("resources/fonts/pixelplay.png"); + fonts[2] = LoadFont("resources/fonts/mecha.png"); + fonts[3] = LoadFont("resources/fonts/setback.png"); + fonts[4] = LoadFont("resources/fonts/romulus.png"); + fonts[5] = LoadFont("resources/fonts/pixantiqua.png"); + fonts[6] = LoadFont("resources/fonts/alpha_beta.png"); + fonts[7] = LoadFont("resources/fonts/jupiter_crash.png"); const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi", "PIXELPLAY FONT designed by Aleksander Shevchuk", @@ -93,8 +93,8 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - // SpriteFonts unloading - for (int i = 0; i < MAX_FONTS; i++) UnloadSpriteFont(fonts[i]); + // Fonts unloading + for (int i = 0; i < MAX_FONTS; i++) UnloadFont(fonts[i]); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/text/text_sprite_fonts.c b/examples/src/text/text_sprite_fonts.c index aefbfd1..7ce2fef 100644 --- a/examples/src/text/text_sprite_fonts.c +++ b/examples/src/text/text_sprite_fonts.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [text] example - SpriteFont loading and usage +* raylib [text] example - Font loading and usage * * This example has been created using raylib 1.0 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) @@ -25,9 +25,9 @@ int main() const char msg3[50] = "...and a THIRD one! GREAT! :D"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont font1 = LoadSpriteFont("resources/custom_mecha.png"); // SpriteFont loading - SpriteFont font2 = LoadSpriteFont("resources/custom_alagard.png"); // SpriteFont loading - SpriteFont font3 = LoadSpriteFont("resources/custom_jupiter_crash.png"); // SpriteFont loading + Font font1 = LoadFont("resources/custom_mecha.png"); // Font loading + Font font2 = LoadFont("resources/custom_alagard.png"); // Font loading + Font font3 = LoadFont("resources/custom_jupiter_crash.png"); // Font loading Vector2 fontPosition1, fontPosition2, fontPosition3; @@ -66,9 +66,9 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadSpriteFont(font1); // SpriteFont unloading - UnloadSpriteFont(font2); // SpriteFont unloading - UnloadSpriteFont(font3); // SpriteFont unloading + UnloadFont(font1); // Font unloading + UnloadFont(font2); // Font unloading + UnloadFont(font3); // Font unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/text/text_ttf_loading.c b/examples/src/text/text_ttf_loading.c index 02b7f95..0e964eb 100644 --- a/examples/src/text/text_ttf_loading.c +++ b/examples/src/text/text_ttf_loading.c @@ -20,26 +20,29 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [text] example - ttf loading"); - const char msg[50] = "TTF SpriteFont"; + const char msg[50] = "TTF Font"; // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) - // TTF SpriteFont loading with custom generation parameters - SpriteFont font = LoadSpriteFontEx("resources/KAISG.ttf", 96, 0, 0); + // TTF Font loading with custom generation parameters + Font font = LoadFontEx("resources/KAISG.ttf", 96, 0, 0); // Generate mipmap levels to use trilinear filtering // NOTE: On 2D drawing it won't be noticeable, it looks like FILTER_BILINEAR GenTextureMipmaps(&font.texture); float fontSize = font.baseSize; - Vector2 fontPosition = { 40, screenHeight/2 + 50 }; + Vector2 fontPosition = { 40, screenHeight/2 - 80 }; Vector2 textSize; SetTextureFilter(font.texture, FILTER_POINT); int currentFontFilter = 0; // FILTER_POINT + // NOTE: Drag and drop support only available for desktop platforms: Windows, Linux, OSX +#if defined(PLATFORM_DESKTOP) int count = 0; char **droppedFiles; +#endif SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -74,6 +77,7 @@ int main() if (IsKeyDown(KEY_LEFT)) fontPosition.x -= 10; else if (IsKeyDown(KEY_RIGHT)) fontPosition.x += 10; +#if defined(PLATFORM_DESKTOP) // Load a dropped TTF file dynamically (at current fontSize) if (IsFileDropped()) { @@ -81,11 +85,12 @@ int main() if (count == 1) // Only support one ttf file dropped { - UnloadSpriteFont(font); - font = LoadSpriteFontEx(droppedFiles[0], fontSize, 0, 0); + UnloadFont(font); + font = LoadFontEx(droppedFiles[0], fontSize, 0, 0); ClearDroppedFiles(); } } +#endif //---------------------------------------------------------------------------------- // Draw @@ -119,10 +124,11 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadSpriteFont(font); // SpriteFont unloading - +#if defined(PLATFORM_DESKTOP) ClearDroppedFiles(); // Clear internal buffers - +#endif + UnloadFont(font); // Font unloading + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/examples/src/textures/textures_image_drawing.c b/examples/src/textures/textures_image_drawing.c index ac128af..b179612 100644 --- a/examples/src/textures/textures_image_drawing.c +++ b/examples/src/textures/textures_image_drawing.c @@ -38,12 +38,12 @@ int main() UnloadImage(cat); // Unload image from RAM // Load custom font for frawing on image - SpriteFont font = LoadSpriteFont("resources/custom_jupiter_crash.png"); + Font font = LoadFont("resources/custom_jupiter_crash.png"); // Draw over image using custom font ImageDrawTextEx(&parrots, (Vector2){ 300, 230 }, font, "PARROTS & CAT", font.baseSize, -2, WHITE); - UnloadSpriteFont(font); // Unload custom spritefont (already drawn used on image) + UnloadFont(font); // Unload custom spritefont (already drawn used on image) Texture2D texture = LoadTextureFromImage(parrots); // Image converted to texture, uploaded to GPU memory (VRAM) UnloadImage(parrots); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM diff --git a/examples/src/textures/textures_image_generation.c b/examples/src/textures/textures_image_generation.c index 7d8e017..b9608c8 100644 --- a/examples/src/textures/textures_image_generation.c +++ b/examples/src/textures/textures_image_generation.c @@ -24,10 +24,10 @@ int main() Image verticalGradient = GenImageGradientV(screenWidth, screenHeight, RED, BLUE); Image horizontalGradient = GenImageGradientH(screenWidth, screenHeight, RED, BLUE); - Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.f, WHITE, BLACK); + Image radialGradient = GenImageGradientRadial(screenWidth, screenHeight, 0.0f, WHITE, BLACK); Image checked = GenImageChecked(screenWidth, screenHeight, 32, 32, RED, BLUE); Image whiteNoise = GenImageWhiteNoise(screenWidth, screenHeight, 0.5f); - Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 8.f); + Image perlinNoise = GenImagePerlinNoise(screenWidth, screenHeight, 50, 50, 4.0f); Image cellular = GenImageCellular(screenWidth, screenHeight, 32); Texture2D textures[NUM_TEXTURES]; @@ -58,7 +58,7 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON) || IsKeyPressed(KEY_RIGHT)) { currentTexture = (currentTexture + 1)%NUM_TEXTURES; // Cycle between the textures } diff --git a/examples/src/textures/textures_particles_blending.c b/examples/src/textures/textures_particles_blending.c index 842ac77..3b7dcaa 100644 --- a/examples/src/textures/textures_particles_blending.c +++ b/examples/src/textures/textures_particles_blending.c @@ -42,7 +42,7 @@ int main() 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.0f; - mouseTail[i].rotation = GetRandomValue(0, 360); + mouseTail[i].rotation = (float)GetRandomValue(0, 360); mouseTail[i].active = false; } @@ -107,9 +107,9 @@ int main() // Draw active particles for (int i = 0; i < MAX_PARTICLES; i++) { - if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0, 0, smoke.width, smoke.height }, + if (mouseTail[i].active) DrawTexturePro(smoke, (Rectangle){ 0.0f, 0.0f, (float)smoke.width, (float)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, + (Vector2){ (float)(smoke.width*mouseTail[i].size/2.0f), (float)(smoke.height*mouseTail[i].size/2.0f) }, mouseTail[i].rotation, Fade(mouseTail[i].color, mouseTail[i].alpha)); } diff --git a/examples/src/textures/textures_rectangle.c b/examples/src/textures/textures_rectangle.c index c90db8a..e124774 100644 --- a/examples/src/textures/textures_rectangle.c +++ b/examples/src/textures/textures_rectangle.c @@ -27,7 +27,7 @@ int main() Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading Vector2 position = { 350.0f, 280.0f }; - Rectangle frameRec = { 0, 0, scarfy.width/6, scarfy.height }; + Rectangle frameRec = { 0.0f, 0.0f, (float)scarfy.width/6, (float)scarfy.height }; int currentFrame = 0; int framesCounter = 0; @@ -50,7 +50,7 @@ int main() if (currentFrame > 5) currentFrame = 0; - frameRec.x = currentFrame*scarfy.width/6; + frameRec.x = (float)currentFrame*(float)scarfy.width/6; } if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; diff --git a/examples/src/textures/textures_srcrec_dstrec.c b/examples/src/textures/textures_srcrec_dstrec.c index 53ffd1d..cc08eb5 100644 --- a/examples/src/textures/textures_srcrec_dstrec.c +++ b/examples/src/textures/textures_srcrec_dstrec.c @@ -27,13 +27,13 @@ int main() int frameHeight = scarfy.height; // NOTE: Source rectangle (part of the texture to use for drawing) - Rectangle sourceRec = { 0, 0, frameWidth, frameHeight }; + Rectangle sourceRec = { 0.0f, 0.0f, (float)frameWidth, (float)frameHeight }; // NOTE: Destination rectangle (screen rectangle where drawing part of texture) - Rectangle destRec = { screenWidth/2, screenHeight/2, frameWidth*2, frameHeight*2 }; + Rectangle destRec = { (float)screenWidth/2, (float)screenHeight/2, (float)frameWidth*2, (float)frameHeight*2 }; // NOTE: Origin of the texture (rotation/scale point), it's relative to destination rectangle size - Vector2 origin = { frameWidth, frameHeight }; + Vector2 origin = { (float)frameWidth, (float)frameHeight }; int rotation = 0; @@ -59,10 +59,10 @@ int main() // destRec defines the rectangle where our texture part will fit (scaling it to fit) // origin defines the point of the texture used as reference for rotation and scaling // rotation defines the texture rotation (using origin as rotation point) - DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, WHITE); + DrawTexturePro(scarfy, sourceRec, destRec, origin, (float)rotation, WHITE); - DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY); - DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY); + DrawLine((int) destRec.x, 0, (int) destRec.x, screenHeight, GRAY); + DrawLine(0, (int)destRec.y, screenWidth, (int)destRec.y, GRAY); DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); |
