diff options
| author | Ray <[email protected]> | 2017-04-20 00:21:38 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-04-20 00:21:38 +0200 |
| commit | bc1bfe54d6df0b872b604870d3e55a9f9f4e19dd (patch) | |
| tree | fa1fb6c1b03008d98c342970fa095d7cc84c2252 /docs/examples/src | |
| parent | 407746193d991190fa4dead94649abb2ed27d462 (diff) | |
| parent | 35172430c6b5929e8f6781e0d92b4bc1f9fcc2a2 (diff) | |
| download | raylib-bc1bfe54d6df0b872b604870d3e55a9f9f4e19dd.tar.gz raylib-bc1bfe54d6df0b872b604870d3e55a9f9f4e19dd.zip | |
Merge pull request #262 from raysan5/develop
Integrate develop branch
Diffstat (limited to 'docs/examples/src')
| -rw-r--r-- | docs/examples/src/audio/audio_module_playing.c (renamed from docs/examples/src/audio_module_playing.c) | 6 | ||||
| -rw-r--r-- | docs/examples/src/audio/audio_music_stream.c (renamed from docs/examples/src/audio_music_stream.c) | 4 | ||||
| -rw-r--r-- | docs/examples/src/audio/audio_raw_stream.c (renamed from docs/examples/src/audio_raw_stream.c) | 29 | ||||
| -rw-r--r-- | docs/examples/src/audio/audio_sound_loading.c (renamed from docs/examples/src/audio_sound_loading.c) | 4 | ||||
| -rw-r--r-- | docs/examples/src/core/core_2d_camera.c (renamed from docs/examples/src/core_2d_camera.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_3d_camera_first_person.c (renamed from docs/examples/src/core_3d_camera_first_person.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_3d_camera_free.c (renamed from docs/examples/src/core_3d_camera_free.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_3d_mode.c (renamed from docs/examples/src/core_3d_mode.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_3d_picking.c (renamed from docs/examples/src/core_3d_picking.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_basic_window.c (renamed from docs/examples/src/core_basic_window.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_color_select.c (renamed from docs/examples/src/core_color_select.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_drop_files.c (renamed from docs/examples/src/core_drop_files.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_gestures_detection.c (renamed from docs/examples/src/core_gestures_detection.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_input_gamepad.c (renamed from docs/examples/src/core_input_gamepad.c) | 4 | ||||
| -rw-r--r-- | docs/examples/src/core/core_input_keys.c (renamed from docs/examples/src/core_input_keys.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_input_mouse.c (renamed from docs/examples/src/core_input_mouse.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_mouse_wheel.c (renamed from docs/examples/src/core_mouse_wheel.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_random_values.c (renamed from docs/examples/src/core_random_values.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_storage_values.c (renamed from docs/examples/src/core_storage_values.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/core/core_vr_simulator.c (renamed from docs/examples/src/core_oculus_rift.c) | 41 | ||||
| -rw-r--r-- | docs/examples/src/core/core_world_screen.c (renamed from docs/examples/src/core_world_screen.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/models/models_billboard.c (renamed from docs/examples/src/models_billboard.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/models/models_box_collisions.c (renamed from docs/examples/src/models_box_collisions.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/models/models_cubicmap.c (renamed from docs/examples/src/models_cubicmap.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/models/models_geometric_shapes.c (renamed from docs/examples/src/models_geometric_shapes.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/models/models_heightmap.c (renamed from docs/examples/src/models_heightmap.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/models/models_mesh_picking.c | 195 | ||||
| -rw-r--r-- | docs/examples/src/models/models_obj_loading.c (renamed from docs/examples/src/models_obj_loading.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/physac/physics_demo.c (renamed from docs/examples/src/physics_demo.c) | 16 | ||||
| -rw-r--r-- | docs/examples/src/physac/physics_friction.c (renamed from docs/examples/src/physics_friction.c) | 17 | ||||
| -rw-r--r-- | docs/examples/src/physac/physics_movement.c (renamed from docs/examples/src/physics_movement.c) | 19 | ||||
| -rw-r--r-- | docs/examples/src/physac/physics_restitution.c (renamed from docs/examples/src/physics_restitution.c) | 17 | ||||
| -rw-r--r-- | docs/examples/src/physac/physics_shatter.c (renamed from docs/examples/src/physics_shatter.c) | 17 | ||||
| -rw-r--r-- | docs/examples/src/shaders/shaders_custom_uniform.c (renamed from docs/examples/src/shaders_custom_uniform.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/shaders/shaders_model_shader.c (renamed from docs/examples/src/shaders_model_shader.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/shaders/shaders_postprocessing.c (renamed from docs/examples/src/shaders_postprocessing.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/shaders/shaders_shapes_textures.c (renamed from docs/examples/src/shaders_shapes_textures.c) | 21 | ||||
| -rw-r--r-- | docs/examples/src/shaders_standard_lighting.c | 120 | ||||
| -rw-r--r-- | docs/examples/src/shapes/shapes_basic_shapes.c (renamed from docs/examples/src/shapes_basic_shapes.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/shapes/shapes_colors_palette.c (renamed from docs/examples/src/shapes_colors_palette.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/shapes/shapes_lines_bezier.c | 59 | ||||
| -rw-r--r-- | docs/examples/src/shapes/shapes_logo_raylib.c (renamed from docs/examples/src/shapes_logo_raylib.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/shapes/shapes_logo_raylib_anim.c (renamed from docs/examples/src/shapes_logo_raylib_anim.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/text/text_bmfont_ttf.c (renamed from docs/examples/src/text_bmfont_ttf.c) | 12 | ||||
| -rw-r--r-- | docs/examples/src/text/text_bmfont_unordered.c (renamed from docs/examples/src/text_bmfont_unordered.c) | 8 | ||||
| -rw-r--r-- | docs/examples/src/text/text_format_text.c (renamed from docs/examples/src/text_format_text.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/text/text_input_box.c | 116 | ||||
| -rw-r--r-- | docs/examples/src/text/text_raylib_fonts.c (renamed from docs/examples/src/text_rbmf_fonts.c) | 58 | ||||
| -rw-r--r-- | docs/examples/src/text/text_sprite_fonts.c (renamed from docs/examples/src/text_sprite_fonts.c) | 24 | ||||
| -rw-r--r-- | docs/examples/src/text/text_ttf_loading.c (renamed from docs/examples/src/text_ttf_loading.c) | 4 | ||||
| -rw-r--r-- | docs/examples/src/text/text_writing_anim.c (renamed from docs/examples/src/text_writing_anim.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/text_font_select.c | 158 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_image_drawing.c (renamed from docs/examples/src/textures_image_drawing.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_image_loading.c (renamed from docs/examples/src/textures_image_loading.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_image_processing.c (renamed from docs/examples/src/textures_image_processing.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_logo_raylib.c (renamed from docs/examples/src/textures_logo_raylib.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_particles_blending.c (renamed from docs/examples/src/textures_particles_trail_blending.c) | 8 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_raw_data.c (renamed from docs/examples/src/textures_raw_data.c) | 24 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_rectangle.c (renamed from docs/examples/src/textures_rectangle.c) | 55 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_srcrec_dstrec.c (renamed from docs/examples/src/textures_srcrec_dstrec.c) | 12 | ||||
| -rw-r--r-- | docs/examples/src/textures/textures_to_image.c (renamed from docs/examples/src/textures_to_image.c) | 0 | ||||
| -rw-r--r-- | docs/examples/src/textures_formats_loading.c | 244 |
62 files changed, 602 insertions, 690 deletions
diff --git a/docs/examples/src/audio_module_playing.c b/docs/examples/src/audio/audio_module_playing.c index a9ee4619..671a119f 100644 --- a/docs/examples/src/audio_module_playing.c +++ b/docs/examples/src/audio/audio_module_playing.c @@ -52,7 +52,7 @@ int main() circles[i].color = colors[GetRandomValue(0, 13)]; } - Music xm = LoadMusicStream("resources/audio/mini1111.xm"); + Music xm = LoadMusicStream("resources/mini1111.xm"); PlayMusicStream(xm); @@ -86,7 +86,7 @@ int main() } // Get timePlayed scaled to bar dimensions - timePlayed = (GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40))*2; + timePlayed = GetMusicTimePlayed(xm)/GetMusicTimeLength(xm)*(screenWidth - 40); // Color circles animation for (int i = MAX_CIRCLES - 1; (i >= 0) && !pause; i--) @@ -112,7 +112,7 @@ int main() //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(WHITE); + ClearBackground(RAYWHITE); for (int i = MAX_CIRCLES - 1; i >= 0; i--) { diff --git a/docs/examples/src/audio_music_stream.c b/docs/examples/src/audio/audio_music_stream.c index dc9d4355..f9fe23d2 100644 --- a/docs/examples/src/audio_music_stream.c +++ b/docs/examples/src/audio/audio_music_stream.c @@ -24,7 +24,7 @@ int main() InitAudioDevice(); // Initialize audio device - Music music = LoadMusicStream("resources/audio/guitar_noodling.ogg"); + Music music = LoadMusicStream("resources/guitar_noodling.ogg"); PlayMusicStream(music); @@ -58,7 +58,7 @@ int main() } // Get timePlayed scaled to bar dimensions (400 pixels) - timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*100*4; + timePlayed = GetMusicTimePlayed(music)/GetMusicTimeLength(music)*400; //---------------------------------------------------------------------------------- // Draw diff --git a/docs/examples/src/audio_raw_stream.c b/docs/examples/src/audio/audio_raw_stream.c index c044a7e0..80c83e96 100644 --- a/docs/examples/src/audio_raw_stream.c +++ b/docs/examples/src/audio/audio_raw_stream.c @@ -16,7 +16,8 @@ #include <stdlib.h> // Required for: malloc(), free() #include <math.h> // Required for: sinf() -#define MAX_SAMPLES 20000 +#define MAX_SAMPLES 22050 +#define MAX_SAMPLES_PER_UPDATE 4096 int main() { @@ -29,21 +30,20 @@ int main() InitAudioDevice(); // Initialize audio device - // Init raw audio stream (sample rate: 22050, sample size: 32bit-float, channels: 1-mono) - AudioStream stream = InitAudioStream(22050, 32, 1); + // Init raw audio stream (sample rate: 22050, sample size: 16bit-short, channels: 1-mono) + AudioStream stream = InitAudioStream(22050, 16, 1); - // Fill audio stream with some samples (sine wave) - float *data = (float *)malloc(sizeof(float)*MAX_SAMPLES); + // Generate samples data from sine wave + 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] = sinf(((2*PI*(float)i)/2)*DEG2RAD); + data[i] = (short)(sinf(((2*PI*(float)i)/2)*DEG2RAD)*32000); } - // NOTE: The generated MAX_SAMPLES do not fit to close a perfect loop - // for that reason, there is a clip everytime audio stream is looped - - PlayAudioStream(stream); + PlayAudioStream(stream); // Start processing stream buffer (no data loaded currently) int totalSamples = MAX_SAMPLES; int samplesLeft = totalSamples; @@ -60,10 +60,13 @@ int main() //---------------------------------------------------------------------------------- // 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 >= 4096) numSamples = 4096; + if (samplesLeft >= MAX_SAMPLES_PER_UPDATE) numSamples = MAX_SAMPLES_PER_UPDATE; else numSamples = samplesLeft; UpdateAudioStream(stream, data + (totalSamples - samplesLeft), numSamples); @@ -83,11 +86,11 @@ int main() DrawText("SINE WAVE SHOULD BE PLAYING!", 240, 140, 20, LIGHTGRAY); - // NOTE: Draw a part of the sine wave (only screen width) + // NOTE: Draw a part of the sine wave (only screen width, proportional values) for (int i = 0; i < GetScreenWidth(); i++) { position.x = i; - position.y = 250 + 50*data[i]; + position.y = 250 + 50*data[i]/32000; DrawPixelV(position, RED); } diff --git a/docs/examples/src/audio_sound_loading.c b/docs/examples/src/audio/audio_sound_loading.c index f081e8ed..00e58326 100644 --- a/docs/examples/src/audio_sound_loading.c +++ b/docs/examples/src/audio/audio_sound_loading.c @@ -24,8 +24,8 @@ int main() InitAudioDevice(); // Initialize audio device - Sound fxWav = LoadSound("resources/audio/weird.wav"); // Load WAV audio file - Sound fxOgg = LoadSound("resources/audio/tanatana.ogg"); // Load OGG audio file + Sound fxWav = LoadSound("resources/sound.wav"); // Load WAV audio file + Sound fxOgg = LoadSound("resources/tanatana.ogg"); // Load OGG audio file SetTargetFPS(60); //-------------------------------------------------------------------------------------- diff --git a/docs/examples/src/core_2d_camera.c b/docs/examples/src/core/core_2d_camera.c index f2f219ef..f2f219ef 100644 --- a/docs/examples/src/core_2d_camera.c +++ b/docs/examples/src/core/core_2d_camera.c diff --git a/docs/examples/src/core_3d_camera_first_person.c b/docs/examples/src/core/core_3d_camera_first_person.c index 3998af81..3998af81 100644 --- a/docs/examples/src/core_3d_camera_first_person.c +++ b/docs/examples/src/core/core_3d_camera_first_person.c diff --git a/docs/examples/src/core_3d_camera_free.c b/docs/examples/src/core/core_3d_camera_free.c index d446e14a..d446e14a 100644 --- a/docs/examples/src/core_3d_camera_free.c +++ b/docs/examples/src/core/core_3d_camera_free.c diff --git a/docs/examples/src/core_3d_mode.c b/docs/examples/src/core/core_3d_mode.c index 5f761655..5f761655 100644 --- a/docs/examples/src/core_3d_mode.c +++ b/docs/examples/src/core/core_3d_mode.c diff --git a/docs/examples/src/core_3d_picking.c b/docs/examples/src/core/core_3d_picking.c index bd5c3347..bd5c3347 100644 --- a/docs/examples/src/core_3d_picking.c +++ b/docs/examples/src/core/core_3d_picking.c diff --git a/docs/examples/src/core_basic_window.c b/docs/examples/src/core/core_basic_window.c index 1db38c95..1db38c95 100644 --- a/docs/examples/src/core_basic_window.c +++ b/docs/examples/src/core/core_basic_window.c diff --git a/docs/examples/src/core_color_select.c b/docs/examples/src/core/core_color_select.c index 002a6931..002a6931 100644 --- a/docs/examples/src/core_color_select.c +++ b/docs/examples/src/core/core_color_select.c diff --git a/docs/examples/src/core_drop_files.c b/docs/examples/src/core/core_drop_files.c index 5c1501b8..5c1501b8 100644 --- a/docs/examples/src/core_drop_files.c +++ b/docs/examples/src/core/core_drop_files.c diff --git a/docs/examples/src/core_gestures_detection.c b/docs/examples/src/core/core_gestures_detection.c index 63a1e6bd..63a1e6bd 100644 --- a/docs/examples/src/core_gestures_detection.c +++ b/docs/examples/src/core/core_gestures_detection.c diff --git a/docs/examples/src/core_input_gamepad.c b/docs/examples/src/core/core_input_gamepad.c index f98885e3..64520a47 100644 --- a/docs/examples/src/core_input_gamepad.c +++ b/docs/examples/src/core/core_input_gamepad.c @@ -4,8 +4,8 @@ * * NOTE: This example requires a Gamepad connected to the system * raylib is configured to work with the following gamepads: -* Xbox 360 Controller (Xbox 360, Xbox One) -* PLAYSTATION(R)3 Controller +* - Xbox 360 Controller (Xbox 360, Xbox One) +* - PLAYSTATION(R)3 Controller * Check raylib.h for buttons configuration * * This example has been created using raylib 1.6 (www.raylib.com) diff --git a/docs/examples/src/core_input_keys.c b/docs/examples/src/core/core_input_keys.c index b2305246..b2305246 100644 --- a/docs/examples/src/core_input_keys.c +++ b/docs/examples/src/core/core_input_keys.c diff --git a/docs/examples/src/core_input_mouse.c b/docs/examples/src/core/core_input_mouse.c index 24d2dfcd..24d2dfcd 100644 --- a/docs/examples/src/core_input_mouse.c +++ b/docs/examples/src/core/core_input_mouse.c diff --git a/docs/examples/src/core_mouse_wheel.c b/docs/examples/src/core/core_mouse_wheel.c index 6a5252ee..6a5252ee 100644 --- a/docs/examples/src/core_mouse_wheel.c +++ b/docs/examples/src/core/core_mouse_wheel.c diff --git a/docs/examples/src/core_random_values.c b/docs/examples/src/core/core_random_values.c index 06e550dd..06e550dd 100644 --- a/docs/examples/src/core_random_values.c +++ b/docs/examples/src/core/core_random_values.c diff --git a/docs/examples/src/core_storage_values.c b/docs/examples/src/core/core_storage_values.c index 43f0882f..43f0882f 100644 --- a/docs/examples/src/core_storage_values.c +++ b/docs/examples/src/core/core_storage_values.c diff --git a/docs/examples/src/core_oculus_rift.c b/docs/examples/src/core/core_vr_simulator.c index eb628cd7..69e0f849 100644 --- a/docs/examples/src/core_oculus_rift.c +++ b/docs/examples/src/core/core_vr_simulator.c @@ -1,14 +1,11 @@ /******************************************************************************************* * -* raylib [core] example - Oculus Rift CV1 +* raylib [core] example - VR Simulator (Oculus Rift CV1 parameters) * -* Compile example using: -* gcc -o $(NAME_PART).exe $(FILE_NAME) -L. -L..\src\external\OculusSDK\LibOVR -lLibOVRRT32_1 -lraylib -lglfw3 -lopengl32 -lgdi32 -std=c99 -* -* This example has been created using raylib 1.5 (www.raylib.com) +* This example has been created using raylib 1.7 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * -* Copyright (c) 2016 Ramon Santamaria (@raysan5) +* Copyright (c) 2017 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -23,10 +20,9 @@ int main() // NOTE: screenWidth/screenHeight should match VR device aspect ratio - InitWindow(screenWidth, screenHeight, "raylib [core] example - oculus rift"); - - // NOTE: If device is not available, it fallbacks to default device (simulator) - InitVrDevice(HMD_OCULUS_RIFT_CV1); // Init VR device (Oculus Rift CV1) + InitWindow(screenWidth, screenHeight, "raylib [core] example - vr simulator"); + + InitVrSimulator(HMD_OCULUS_RIFT_CV1); // Init VR simulator (Oculus Rift CV1 parameters) // Define the camera to look into our 3d world Camera camera; @@ -47,10 +43,9 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsVrSimulator()) UpdateCamera(&camera); // Update camera (simulator mode) - else if (IsVrDeviceReady()) UpdateVrTracking(&camera); // Update camera with device tracking data - - if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode + UpdateCamera(&camera); // Update camera (simulator mode) + + if (IsKeyPressed(KEY_SPACE)) ToggleVrMode(); // Toggle VR mode //---------------------------------------------------------------------------------- // Draw @@ -58,15 +53,19 @@ int main() BeginDrawing(); ClearBackground(RAYWHITE); + + BeginVrDrawing(); - Begin3dMode(camera); + Begin3dMode(camera); - DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); - DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); + DrawCube(cubePosition, 2.0f, 2.0f, 2.0f, RED); + DrawCubeWires(cubePosition, 2.0f, 2.0f, 2.0f, MAROON); - DrawGrid(40, 1.0f); + DrawGrid(40, 1.0f); - End3dMode(); + End3dMode(); + + EndVrDrawing(); DrawFPS(10, 10); @@ -76,10 +75,10 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - CloseVrDevice(); // Close VR device + CloseVrSimulator(); // Close VR simulator CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; -} +}
\ No newline at end of file diff --git a/docs/examples/src/core_world_screen.c b/docs/examples/src/core/core_world_screen.c index f8c53c70..f8c53c70 100644 --- a/docs/examples/src/core_world_screen.c +++ b/docs/examples/src/core/core_world_screen.c diff --git a/docs/examples/src/models_billboard.c b/docs/examples/src/models/models_billboard.c index bca9faf8..bca9faf8 100644 --- a/docs/examples/src/models_billboard.c +++ b/docs/examples/src/models/models_billboard.c diff --git a/docs/examples/src/models_box_collisions.c b/docs/examples/src/models/models_box_collisions.c index 69cec418..69cec418 100644 --- a/docs/examples/src/models_box_collisions.c +++ b/docs/examples/src/models/models_box_collisions.c diff --git a/docs/examples/src/models_cubicmap.c b/docs/examples/src/models/models_cubicmap.c index 0e613029..0e613029 100644 --- a/docs/examples/src/models_cubicmap.c +++ b/docs/examples/src/models/models_cubicmap.c diff --git a/docs/examples/src/models_geometric_shapes.c b/docs/examples/src/models/models_geometric_shapes.c index a13a1f3b..a13a1f3b 100644 --- a/docs/examples/src/models_geometric_shapes.c +++ b/docs/examples/src/models/models_geometric_shapes.c diff --git a/docs/examples/src/models_heightmap.c b/docs/examples/src/models/models_heightmap.c index 10069e03..10069e03 100644 --- a/docs/examples/src/models_heightmap.c +++ b/docs/examples/src/models/models_heightmap.c diff --git a/docs/examples/src/models/models_mesh_picking.c b/docs/examples/src/models/models_mesh_picking.c new file mode 100644 index 00000000..0b5247ec --- /dev/null +++ b/docs/examples/src/models/models_mesh_picking.c @@ -0,0 +1,195 @@ +/******************************************************************************************* +* +* raylib [models] example - Mesh picking in 3d mode, ground plane, triangle, mesh +* +* This example has been created using raylib 1.7 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2015 Ramon Santamaria (@raysan5) +* Example contributed by Joel Davis (@joeld42) +* +********************************************************************************************/ + +#include "raylib.h" +#include "raymath.h" + +#define FLT_MAX 3.40282347E+38F // Maximum value of a float, defined in <float.h> + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [models] example - mesh picking"); + + // Define the camera to look into our 3d world + Camera camera; + camera.position = (Vector3){ 10.0f, 8.0f, 10.0f }; // Camera position + camera.target = (Vector3){ 0.0f, 2.3f, 0.0f }; // Camera looking at point + camera.up = (Vector3){ 0.0f, 1.6f, 0.0f }; // Camera up vector (rotation towards target) + camera.fovy = 45.0f; // Camera field-of-view Y + + Ray ray; // Picking ray + + Model tower = LoadModel("resources/tower.obj"); // Load OBJ model + Texture2D texture = LoadTexture("resources/tower.png"); // Load model texture + tower.material.texDiffuse = texture; // Set model diffuse texture + + Vector3 towerPos = { 0.0f, 0.0f, 0.0f }; // Set model position + BoundingBox towerBBox = CalculateBoundingBox(tower.mesh); + bool hitMeshBBox = false; + bool hitTriangle = false; + + // Test triangle + Vector3 ta = (Vector3){ -25.0, 0.5, 0.0 }; + Vector3 tb = (Vector3){ -4.0, 2.5, 1.0 }; + Vector3 tc = (Vector3){ -8.0, 6.5, 0.0 }; + + Vector3 bary = { 0.0f, 0.0f, 0.0f }; + + SetCameraMode(camera, CAMERA_FREE); // Set a free 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 + //---------------------------------------------------------------------------------- + UpdateCamera(&camera); // Update camera + + // Display information about closest hit + RayHitInfo nearestHit; + char *hitObjectName = "None"; + nearestHit.distance = FLT_MAX; + nearestHit.hit = false; + Color cursorColor = WHITE; + + // Get ray and test against ground, triangle, and mesh + ray = GetMouseRay(GetMousePosition(), camera); + + // Check ray collision aginst ground plane + RayHitInfo groundHitInfo = GetCollisionRayGround(ray, 0.0f); + + if ((groundHitInfo.hit) && (groundHitInfo.distance < nearestHit.distance)) + { + nearestHit = groundHitInfo; + cursorColor = GREEN; + hitObjectName = "Ground"; + } + + // Check ray collision against test triangle + RayHitInfo triHitInfo = GetCollisionRayTriangle(ray, ta, tb, tc); + + if ((triHitInfo.hit) && (triHitInfo.distance < nearestHit.distance)) + { + nearestHit = triHitInfo; + cursorColor = PURPLE; + hitObjectName = "Triangle"; + + bary = VectorBarycenter(nearestHit.hitPosition, ta, tb, tc); + hitTriangle = true; + } + else hitTriangle = false; + + RayHitInfo meshHitInfo; + + // Check ray collision against bounding box first, before trying the full ray-mesh test + if (CheckCollisionRayBox(ray, towerBBox)) + { + hitMeshBBox = true; + + // Check ray collision against mesh + meshHitInfo = GetCollisionRayMesh(ray, &tower.mesh); + + if ((meshHitInfo.hit) && (meshHitInfo.distance < nearestHit.distance)) + { + nearestHit = meshHitInfo; + cursorColor = ORANGE; + hitObjectName = "Mesh"; + } + + } hitMeshBBox = false; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + Begin3dMode(camera); + + // Draw the tower + DrawModel(tower, towerPos, 1.0, WHITE); + + // Draw the test triangle + DrawLine3D(ta, tb, PURPLE); + DrawLine3D(tb, tc, PURPLE); + DrawLine3D(tc, ta, PURPLE); + + // Draw the mesh bbox if we hit it + if (hitMeshBBox) DrawBoundingBox(towerBBox, LIME); + + // If we hit something, draw the cursor at the hit point + if (nearestHit.hit) + { + DrawCube(nearestHit.hitPosition, 0.3, 0.3, 0.3, cursorColor); + DrawCubeWires(nearestHit.hitPosition, 0.3, 0.3, 0.3, RED); + + Vector3 normalEnd; + normalEnd.x = nearestHit.hitPosition.x + nearestHit.hitNormal.x; + normalEnd.y = nearestHit.hitPosition.y + nearestHit.hitNormal.y; + normalEnd.z = nearestHit.hitPosition.z + nearestHit.hitNormal.z; + + DrawLine3D(nearestHit.hitPosition, normalEnd, RED); + } + + DrawRay(ray, MAROON); + + DrawGrid(100, 1.0f); + + End3dMode(); + + // Draw some debug GUI text + DrawText(FormatText("Hit Object: %s", hitObjectName), 10, 50, 10, BLACK); + + if (nearestHit.hit) + { + int ypos = 70; + + DrawText(FormatText("Distance: %3.2f", nearestHit.distance), 10, ypos, 10, BLACK); + + DrawText(FormatText("Hit Pos: %3.2f %3.2f %3.2f", + nearestHit.hitPosition.x, + nearestHit.hitPosition.y, + nearestHit.hitPosition.z), 10, ypos + 15, 10, BLACK); + + DrawText(FormatText("Hit Norm: %3.2f %3.2f %3.2f", + nearestHit.hitNormal.x, + nearestHit.hitNormal.y, + nearestHit.hitNormal.z), 10, ypos + 30, 10, BLACK); + + if (hitTriangle) DrawText(FormatText("Barycenter: %3.2f %3.2f %3.2f", bary.x, bary.y, bary.z), 10, ypos + 45, 10, BLACK); + } + + DrawText("Use Mouse to Move Camera", 10, 430, 10, GRAY); + + DrawFPS(10, 10); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadModel(tower); // Unload model + UnloadTexture(texture); // Unload texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +}
\ No newline at end of file diff --git a/docs/examples/src/models_obj_loading.c b/docs/examples/src/models/models_obj_loading.c index 50d42d2e..50d42d2e 100644 --- a/docs/examples/src/models_obj_loading.c +++ b/docs/examples/src/models/models_obj_loading.c diff --git a/docs/examples/src/physics_demo.c b/docs/examples/src/physac/physics_demo.c index bed7c94d..55588363 100644 --- a/docs/examples/src/physics_demo.c +++ b/docs/examples/src/physac/physics_demo.c @@ -2,17 +2,22 @@ * * Physac - Physics demo * -* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread) * -* Copyright (c) 2016 Victor Fisac +* Use the following line to compile: +* +* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread +* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ #include "raylib.h" #define PHYSAC_IMPLEMENTATION -#include "..\src\physac.h" +#include "physac.h" int main() { @@ -114,9 +119,10 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Unitialize physics + ClosePhysics(); // Uninitialize physics CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } + diff --git a/docs/examples/src/physics_friction.c b/docs/examples/src/physac/physics_friction.c index 28d3c4b8..6ce1d406 100644 --- a/docs/examples/src/physics_friction.c +++ b/docs/examples/src/physac/physics_friction.c @@ -2,17 +2,22 @@ * * Physac - Physics friction * -* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread) * -* Copyright (c) 2016 Victor Fisac +* Use the following line to compile: +* +* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread +* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ #include "raylib.h" #define PHYSAC_IMPLEMENTATION -#include "..\src\physac.h" +#include "physac.h" int main() { @@ -128,9 +133,11 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Unitialize physics + ClosePhysics(); // Uninitialize physics + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } + diff --git a/docs/examples/src/physics_movement.c b/docs/examples/src/physac/physics_movement.c index ca18f3df..534997bf 100644 --- a/docs/examples/src/physics_movement.c +++ b/docs/examples/src/physac/physics_movement.c @@ -2,19 +2,24 @@ * * Physac - Physics movement * -* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread) * -* Copyright (c) 2016 Victor Fisac +* Use the following line to compile: +* +* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread +* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ #include "raylib.h" #define PHYSAC_IMPLEMENTATION -#include "..\src\physac.h" +#include "physac.h" -#define VELOCITY 0.5f +#define VELOCITY 0.5f int main() { @@ -114,9 +119,11 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Unitialize physics + ClosePhysics(); // Uninitialize physics + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } + diff --git a/docs/examples/src/physics_restitution.c b/docs/examples/src/physac/physics_restitution.c index 3543db69..0809697c 100644 --- a/docs/examples/src/physics_restitution.c +++ b/docs/examples/src/physac/physics_restitution.c @@ -2,17 +2,22 @@ * * Physac - Physics restitution * -* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread) * -* Copyright (c) 2016 Victor Fisac +* Use the following line to compile: +* +* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread +* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ #include "raylib.h" #define PHYSAC_IMPLEMENTATION -#include "..\src\physac.h" +#include "physac.h" int main() { @@ -107,9 +112,11 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Unitialize physics + ClosePhysics(); // Uninitialize physics + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } + diff --git a/docs/examples/src/physics_shatter.c b/docs/examples/src/physac/physics_shatter.c index 2cb9d195..b237bfca 100644 --- a/docs/examples/src/physics_shatter.c +++ b/docs/examples/src/physac/physics_shatter.c @@ -2,17 +2,22 @@ * * Physac - Body shatter * -* NOTE: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. -* The file pthreadGC2.dll is required to run the program; you can find it in 'src\external' +* NOTE 1: Physac requires multi-threading, when InitPhysics() a second thread is created to manage physics calculations. +* NOTE 2: Physac requires static C library linkage to avoid dependency on MinGW DLL (-static -lpthread) * -* Copyright (c) 2016 Victor Fisac +* Use the following line to compile: +* +* gcc -o $(NAME_PART).exe $(FILE_NAME) -s $(RAYLIB_DIR)\raylib\raylib_icon -static -lraylib -lpthread +* -lglfw3 -lopengl32 -lgdi32 -lopenal32 -lwinmm -std=c99 -Wl,--subsystem,windows -Wl,-allow-multiple-definition +* +* Copyright (c) 2017 Victor Fisac * ********************************************************************************************/ #include "raylib.h" #define PHYSAC_IMPLEMENTATION -#include "..\src\physac.h" +#include "physac.h" int main() { @@ -99,9 +104,11 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - ClosePhysics(); // Unitialize physics + ClosePhysics(); // Uninitialize physics + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; } + diff --git a/docs/examples/src/shaders_custom_uniform.c b/docs/examples/src/shaders/shaders_custom_uniform.c index 89f87df9..89f87df9 100644 --- a/docs/examples/src/shaders_custom_uniform.c +++ b/docs/examples/src/shaders/shaders_custom_uniform.c diff --git a/docs/examples/src/shaders_model_shader.c b/docs/examples/src/shaders/shaders_model_shader.c index 51e9c1b3..51e9c1b3 100644 --- a/docs/examples/src/shaders_model_shader.c +++ b/docs/examples/src/shaders/shaders_model_shader.c diff --git a/docs/examples/src/shaders_postprocessing.c b/docs/examples/src/shaders/shaders_postprocessing.c index 43d1af72..43d1af72 100644 --- a/docs/examples/src/shaders_postprocessing.c +++ b/docs/examples/src/shaders/shaders_postprocessing.c diff --git a/docs/examples/src/shaders_shapes_textures.c b/docs/examples/src/shaders/shaders_shapes_textures.c index 0a14469f..40e99a8f 100644 --- a/docs/examples/src/shaders_shapes_textures.c +++ b/docs/examples/src/shaders/shaders_shapes_textures.c @@ -9,7 +9,7 @@ * on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders * raylib comes with shaders ready for both versions, check raylib/shaders install folder * -* This example has been created using raylib 1.3 (www.raylib.com) +* This example has been created using raylib 1.7 (www.raylib.com) * raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) * * Copyright (c) 2015 Ramon Santamaria (@raysan5) @@ -18,9 +18,6 @@ #include "raylib.h" -#include <stdio.h> -#include <stdlib.h> - int main() { // Initialization @@ -30,14 +27,12 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [shaders] example - shapes and texture shaders"); - Texture2D sonic = LoadTexture("resources/texture_formats/sonic.png"); + Texture2D fudesumi = LoadTexture("resources/fudesumi.png"); // NOTE: Using GLSL 330 shader version, on OpenGL ES 2.0 use GLSL 100 shader version Shader shader = LoadShader("resources/shaders/glsl330/base.vs", "resources/shaders/glsl330/grayscale.fs"); - - // Shader usage is also different than models/postprocessing, shader is just activated when required - + SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -91,21 +86,23 @@ int main() // Activate our custom shader to be applied on next shapes/textures drawings BeginShaderMode(shader); - DrawTexture(sonic, 380, -10, WHITE); // Using custom shader + DrawTexture(fudesumi, 500, -30, WHITE); // Using custom shader // Activate our default shader for next drawings EndShaderMode(); + DrawText("(c) Fudesumi sprite by Eiden Marsal", 380, screenHeight - 20, 10, GRAY); + EndDrawing(); //---------------------------------------------------------------------------------- } // De-Initialization //-------------------------------------------------------------------------------------- - UnloadShader(shader); // Unload shader - UnloadTexture(sonic); // Unload texture + UnloadShader(shader); // Unload shader + UnloadTexture(fudesumi); // Unload texture - CloseWindow(); // Close window and OpenGL context + CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- return 0; diff --git a/docs/examples/src/shaders_standard_lighting.c b/docs/examples/src/shaders_standard_lighting.c deleted file mode 100644 index e539ec47..00000000 --- a/docs/examples/src/shaders_standard_lighting.c +++ /dev/null @@ -1,120 +0,0 @@ -/******************************************************************************************* -* -* raylib [shaders] example - Standard lighting (materials and lights) -* -* NOTE: This example requires raylib OpenGL 3.3 or ES2 versions for shaders support, -* OpenGL 1.1 does not support shaders, recompile raylib to OpenGL 3.3 version. -* -* NOTE: Shaders used in this example are #version 330 (OpenGL 3.3), to test this example -* on OpenGL ES 2.0 platforms (Android, Raspberry Pi, HTML5), use #version 100 shaders -* raylib comes with shaders ready for both versions, check raylib/shaders install folder -* -* 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) 2016 Ramon Santamaria (@raysan5) -* -********************************************************************************************/ - -#include "raylib.h" - -int main() -{ - // Initialization - //-------------------------------------------------------------------------------------- - int screenWidth = 800; - int screenHeight = 450; - - SetConfigFlags(FLAG_MSAA_4X_HINT); // Enable Multi Sampling Anti Aliasing 4x (if available) - - InitWindow(screenWidth, screenHeight, "raylib [shaders] example - model shader"); - - // Define the camera to look into our 3d world - Camera camera = {{ 4.0f, 4.0f, 4.0f }, { 0.0f, 1.5f, 0.0f }, { 0.0f, 1.0f, 0.0f }, 45.0f }; - Vector3 position = { 0.0f, 0.0f, 0.0f }; // Set model position - - Model dwarf = LoadModel("resources/model/dwarf.obj"); // Load OBJ model - - Material material = LoadStandardMaterial(); - - material.texDiffuse = LoadTexture("resources/model/dwarf_diffuse.png"); // Load model diffuse texture - material.texNormal = LoadTexture("resources/model/dwarf_normal.png"); // Load model normal texture - material.texSpecular = LoadTexture("resources/model/dwarf_specular.png"); // Load model specular texture - material.colDiffuse = WHITE; - material.colAmbient = (Color){0, 0, 10, 255}; - material.colSpecular = WHITE; - material.glossiness = 50.0f; - - dwarf.material = material; // Apply material to model - - Light spotLight = CreateLight(LIGHT_SPOT, (Vector3){3.0f, 5.0f, 2.0f}, (Color){255, 255, 255, 255}); - spotLight->target = (Vector3){0.0f, 0.0f, 0.0f}; - spotLight->intensity = 2.0f; - spotLight->diffuse = (Color){255, 100, 100, 255}; - spotLight->coneAngle = 60.0f; - - Light dirLight = CreateLight(LIGHT_DIRECTIONAL, (Vector3){0.0f, -3.0f, -3.0f}, (Color){255, 255, 255, 255}); - dirLight->target = (Vector3){1.0f, -2.0f, -2.0f}; - dirLight->intensity = 2.0f; - dirLight->diffuse = (Color){100, 255, 100, 255}; - - Light pointLight = CreateLight(LIGHT_POINT, (Vector3){0.0f, 4.0f, 5.0f}, (Color){255, 255, 255, 255}); - pointLight->intensity = 2.0f; - pointLight->diffuse = (Color){100, 100, 255, 255}; - pointLight->radius = 3.0f; - - // Setup orbital camera - SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital 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 - //---------------------------------------------------------------------------------- - UpdateCamera(&camera); // Update camera - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - Begin3dMode(camera); - - DrawModel(dwarf, position, 2.0f, WHITE); // Draw 3d model with texture - - DrawLight(spotLight); // Draw spot light - DrawLight(dirLight); // Draw directional light - DrawLight(pointLight); // Draw point light - - DrawGrid(10, 1.0f); // Draw a grid - - End3dMode(); - - DrawText("(c) Dwarf 3D model by David Moreno", screenWidth - 200, screenHeight - 20, 10, GRAY); - - DrawFPS(10, 10); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - UnloadMaterial(material); // Unload material and assigned textures - UnloadModel(dwarf); // Unload model - - // Destroy all created lights - DestroyLight(pointLight); - DestroyLight(dirLight); - DestroyLight(spotLight); - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/docs/examples/src/shapes_basic_shapes.c b/docs/examples/src/shapes/shapes_basic_shapes.c index 6b2719fc..6b2719fc 100644 --- a/docs/examples/src/shapes_basic_shapes.c +++ b/docs/examples/src/shapes/shapes_basic_shapes.c diff --git a/docs/examples/src/shapes_colors_palette.c b/docs/examples/src/shapes/shapes_colors_palette.c index dcab862e..dcab862e 100644 --- a/docs/examples/src/shapes_colors_palette.c +++ b/docs/examples/src/shapes/shapes_colors_palette.c diff --git a/docs/examples/src/shapes/shapes_lines_bezier.c b/docs/examples/src/shapes/shapes_lines_bezier.c new file mode 100644 index 00000000..f4133459 --- /dev/null +++ b/docs/examples/src/shapes/shapes_lines_bezier.c @@ -0,0 +1,59 @@ +/******************************************************************************************* +* +* raylib [shapes] example - Cubic-bezier lines +* +* This example has been created using raylib 1.7 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2017 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + SetConfigFlags(FLAG_MSAA_4X_HINT); + InitWindow(screenWidth, screenHeight, "raylib [shapes] example - cubic-bezier lines"); + + Vector2 start = { 0, 0 }; + Vector2 end = { screenWidth, screenHeight }; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) start = GetMousePosition(); + else if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) end = GetMousePosition(); + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY); + + DrawLineBezier(start, end, 2.0f, RED); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/docs/examples/src/shapes_logo_raylib.c b/docs/examples/src/shapes/shapes_logo_raylib.c index be94988c..be94988c 100644 --- a/docs/examples/src/shapes_logo_raylib.c +++ b/docs/examples/src/shapes/shapes_logo_raylib.c diff --git a/docs/examples/src/shapes_logo_raylib_anim.c b/docs/examples/src/shapes/shapes_logo_raylib_anim.c index c6d3796e..c6d3796e 100644 --- a/docs/examples/src/shapes_logo_raylib_anim.c +++ b/docs/examples/src/shapes/shapes_logo_raylib_anim.c diff --git a/docs/examples/src/text_bmfont_ttf.c b/docs/examples/src/text/text_bmfont_ttf.c index caece548..0778fd11 100644 --- a/docs/examples/src/text_bmfont_ttf.c +++ b/docs/examples/src/text/text_bmfont_ttf.c @@ -24,13 +24,13 @@ 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/fonts/bmfont.fnt"); // BMFont (AngelCode) - SpriteFont fontTtf = LoadSpriteFont("resources/fonts/pixantiqua.ttf"); // TTF font + SpriteFont fontBm = LoadSpriteFont("resources/bmfont.fnt"); // BMFont (AngelCode) + SpriteFont fontTtf = LoadSpriteFont("resources/pixantiqua.ttf"); // TTF font Vector2 fontPosition; - fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.size, 0).x/2; - fontPosition.y = screenHeight/2 - fontBm.size/2 - 80; + fontPosition.x = screenWidth/2 - MeasureTextEx(fontBm, msgBm, fontBm.baseSize, 0).x/2; + fontPosition.y = screenHeight/2 - fontBm.baseSize/2 - 80; SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -49,8 +49,8 @@ int main() ClearBackground(RAYWHITE); - DrawTextEx(fontBm, msgBm, fontPosition, fontBm.size, 0, MAROON); - DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.size*0.8f, 2, LIME); + DrawTextEx(fontBm, msgBm, fontPosition, fontBm.baseSize, 0, MAROON); + DrawTextEx(fontTtf, msgTtf, (Vector2){ 75.0f, 240.0f }, fontTtf.baseSize*0.8f, 2, LIME); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/docs/examples/src/text_bmfont_unordered.c b/docs/examples/src/text/text_bmfont_unordered.c index b29c5f8b..01561bec 100644 --- a/docs/examples/src/text_bmfont_unordered.c +++ b/docs/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/fonts/pixantiqua.fnt"); // BMFont (AngelCode) + SpriteFont font = LoadSpriteFont("resources/pixantiqua.fnt"); // BMFont (AngelCode) SetTargetFPS(60); //-------------------------------------------------------------------------------------- @@ -45,10 +45,10 @@ int main() ClearBackground(RAYWHITE); DrawText("Font name: PixAntiqua", 40, 50, 20, GRAY); - DrawText(FormatText("Font base size: %i", font.size), 40, 80, 20, GRAY); - DrawText(FormatText("Font chars number: %i", font.numChars), 40, 110, 20, GRAY); + DrawText(FormatText("Font base size: %i", font.baseSize), 40, 80, 20, GRAY); + DrawText(FormatText("Font chars number: %i", font.charsCount), 40, 110, 20, GRAY); - DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.size, 0, MAROON); + DrawTextEx(font, msg, (Vector2){ 40, 180 }, font.baseSize, 0, MAROON); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/docs/examples/src/text_format_text.c b/docs/examples/src/text/text_format_text.c index ca28be74..ca28be74 100644 --- a/docs/examples/src/text_format_text.c +++ b/docs/examples/src/text/text_format_text.c diff --git a/docs/examples/src/text/text_input_box.c b/docs/examples/src/text/text_input_box.c new file mode 100644 index 00000000..54eebf40 --- /dev/null +++ b/docs/examples/src/text/text_input_box.c @@ -0,0 +1,116 @@ +/******************************************************************************************* +* +* raylib [text] example - Input Box +* +* This example has been created using raylib 1.7 (www.raylib.com) +* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details) +* +* Copyright (c) 2017 Ramon Santamaria (@raysan5) +* +********************************************************************************************/ + +#include "raylib.h" + +#define MAX_INPUT_CHARS 9 + +int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + int screenWidth = 800; + int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [text] example - input box"); + + char name[MAX_INPUT_CHARS + 1] = "\0"; // NOTE: One extra space required for line ending char '\0' + int letterCount = 0; + + Rectangle textBox = { screenWidth/2 - 100, 180, 225, 50 }; + bool mouseOnText = false; + + int framesCounter = 0; + + SetTargetFPS(60); + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!WindowShouldClose()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (CheckCollisionPointRec(GetMousePosition(), textBox)) mouseOnText = true; + else mouseOnText = false; + + if (mouseOnText) + { + int key = GetKeyPressed(); + + // NOTE: Only allow keys in range [32..125] + if ((key >= 32) && (key <= 125) && (letterCount < MAX_INPUT_CHARS)) + { + name[letterCount] = (char)key; + letterCount++; + } + + if (key == KEY_BACKSPACE) + { + letterCount--; + name[letterCount] = '\0'; + + if (letterCount < 0) letterCount = 0; + } + } + + if (mouseOnText) framesCounter++; + else framesCounter = 0; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + DrawText("PLACE MOUSE OVER INPUT BOX!", 240, 140, 20, GRAY); + + DrawRectangleRec(textBox, LIGHTGRAY); + if (mouseOnText) DrawRectangleLines(textBox.x, textBox.y, textBox.width, textBox.height, RED); + else DrawRectangleLines(textBox.x, textBox.y, textBox.width, textBox.height, DARKGRAY); + + DrawText(name, textBox.x + 5, textBox.y + 8, 40, MAROON); + + DrawText(FormatText("INPUT CHARS: %i/%i", letterCount, MAX_INPUT_CHARS), 315, 250, 20, DARKGRAY); + + if (mouseOnText) + { + if (letterCount < MAX_INPUT_CHARS) + { + // Draw blinking underscore char + if (((framesCounter/20)%2) == 0) DrawText("_", textBox.x + 8 + MeasureText(name, 40), textBox.y + 12, 40, MAROON); + } + else DrawText("Press BACKSPACE to delete chars...", 230, 300, 20, GRAY); + } + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} + +// Check if any key is pressed +// NOTE: We limit keys check to keys between 32 (KEY_SPACE) and 126 +bool IsAnyKeyPressed() +{ + bool keyPressed = false; + int key = GetKeyPressed(); + + if ((key >= 32) && (key <= 126)) keyPressed = true; + + return keyPressed; +}
\ No newline at end of file diff --git a/docs/examples/src/text_rbmf_fonts.c b/docs/examples/src/text/text_raylib_fonts.c index b4bd851b..6d8ef2b6 100644 --- a/docs/examples/src/text_rbmf_fonts.c +++ b/docs/examples/src/text/text_raylib_fonts.c @@ -1,19 +1,21 @@ /******************************************************************************************* * -* raylib [text] example - raylib bitmap font (rbmf) loading and usage +* raylib [text] example - raylib font loading and usage * * 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.3 (www.raylib.com) +* This example has been created using raylib 1.7 (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) 2017 Ramon Santamaria (@raysan5) * ********************************************************************************************/ #include "raylib.h" +#define MAX_FONTS 8 + int main() { // Initialization @@ -21,21 +23,21 @@ int main() int screenWidth = 800; int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [text] example - rBMF fonts"); + InitWindow(screenWidth, screenHeight, "raylib [text] example - raylib fonts"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont fonts[8]; + SpriteFont fonts[MAX_FONTS]; - fonts[0] = LoadSpriteFont("resources/fonts/alagard.rbmf"); // rBMF font loading - fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // rBMF font loading - fonts[2] = LoadSpriteFont("resources/fonts/mecha.rbmf"); // rBMF font loading - fonts[3] = LoadSpriteFont("resources/fonts/setback.rbmf"); // rBMF font loading - fonts[4] = LoadSpriteFont("resources/fonts/romulus.rbmf"); // rBMF font loading - fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.rbmf"); // rBMF font loading - fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.rbmf"); // rBMF font loading - fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf"); // rBMF font loading + 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"); - const char *messages[8] = { "ALAGARD FONT designed by Hewett Tsoi", + const char *messages[MAX_FONTS] = { "ALAGARD FONT designed by Hewett Tsoi", "PIXELPLAY FONT designed by Aleksander Shevchuk", "MECHA FONT designed by Captain Falcon", "SETBACK FONT designed by Brian Kent (AEnigma)", @@ -44,17 +46,22 @@ int main() "ALPHA_BETA FONT designed by Brian Kent (AEnigma)", "JUPITER_CRASH FONT designed by Brian Kent (AEnigma)" }; - const int spacings[8] = { 2, 4, 8, 4, 3, 4, 4, 1 }; + const int spacings[MAX_FONTS] = { 2, 4, 8, 4, 3, 4, 4, 1 }; - Vector2 positions[8]; + Vector2 positions[MAX_FONTS]; - for (int i = 0; i < 8; i++) + for (int i = 0; i < MAX_FONTS; 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; + positions[i].x = screenWidth/2 - MeasureTextEx(fonts[i], messages[i], fonts[i].baseSize*2, spacings[i]).x/2; + positions[i].y = 60 + fonts[i].baseSize + 45*i; } - Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD }; + // Small Y position corrections + positions[3].y += 8; + positions[4].y += 2; + positions[7].y -= 8; + + Color colors[MAX_FONTS] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }; //-------------------------------------------------------------------------------------- // Main game loop @@ -74,9 +81,9 @@ int main() DrawText("free fonts included with raylib", 250, 20, 20, DARKGRAY); DrawLine(220, 50, 590, 50, DARKGRAY); - for (int i = 0; i < 8; i++) + for (int i = 0; i < MAX_FONTS; i++) { - DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].size*2, spacings[i], colors[i]); + DrawTextEx(fonts[i], messages[i], positions[i], fonts[i].baseSize*2, spacings[i], colors[i]); } EndDrawing(); @@ -85,10 +92,9 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - for (int i = 0; i < 8; i++) - { - UnloadSpriteFont(fonts[i]); // SpriteFont unloading - } + + // SpriteFonts unloading + for (int i = 0; i < MAX_FONTS; i++) UnloadSpriteFont(fonts[i]); CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/docs/examples/src/text_sprite_fonts.c b/docs/examples/src/text/text_sprite_fonts.c index c73eda85..aefbfd1f 100644 --- a/docs/examples/src/text_sprite_fonts.c +++ b/docs/examples/src/text/text_sprite_fonts.c @@ -25,20 +25,20 @@ 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/fonts/custom_mecha.png"); // SpriteFont loading - SpriteFont font2 = LoadSpriteFont("resources/fonts/custom_alagard.png"); // SpriteFont loading - SpriteFont font3 = LoadSpriteFont("resources/fonts/custom_jupiter_crash.png"); // SpriteFont loading + 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 Vector2 fontPosition1, fontPosition2, fontPosition3; - fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.size, -3).x/2; - fontPosition1.y = screenHeight/2 - font1.size/2 - 80; + fontPosition1.x = screenWidth/2 - MeasureTextEx(font1, msg1, font1.baseSize, -3).x/2; + fontPosition1.y = screenHeight/2 - font1.baseSize/2 - 80; - fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.size, -2).x/2; - fontPosition2.y = screenHeight/2 - font2.size/2 - 10; + fontPosition2.x = screenWidth/2 - MeasureTextEx(font2, msg2, font2.baseSize, -2).x/2; + fontPosition2.y = screenHeight/2 - font2.baseSize/2 - 10; - fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.size, 2).x/2; - fontPosition3.y = screenHeight/2 - font3.size/2 + 50; + fontPosition3.x = screenWidth/2 - MeasureTextEx(font3, msg3, font3.baseSize, 2).x/2; + fontPosition3.y = screenHeight/2 - font3.baseSize/2 + 50; //-------------------------------------------------------------------------------------- @@ -56,9 +56,9 @@ int main() ClearBackground(RAYWHITE); - DrawTextEx(font1, msg1, fontPosition1, font1.size, -3, WHITE); - DrawTextEx(font2, msg2, fontPosition2, font2.size, -2, WHITE); - DrawTextEx(font3, msg3, fontPosition3, font3.size, 2, WHITE); + DrawTextEx(font1, msg1, fontPosition1, font1.baseSize, -3, WHITE); + DrawTextEx(font2, msg2, fontPosition2, font2.baseSize, -2, WHITE); + DrawTextEx(font3, msg3, fontPosition3, font3.baseSize, 2, WHITE); EndDrawing(); //---------------------------------------------------------------------------------- diff --git a/docs/examples/src/text_ttf_loading.c b/docs/examples/src/text/text_ttf_loading.c index 33cda7f5..4e490399 100644 --- a/docs/examples/src/text_ttf_loading.c +++ b/docs/examples/src/text/text_ttf_loading.c @@ -25,13 +25,13 @@ int main() // NOTE: Textures/Fonts MUST be loaded after Window initialization (OpenGL context is required) // TTF SpriteFont loading with custom generation parameters - SpriteFont font = LoadSpriteFontTTF("resources/fonts/KAISG.ttf", 96, 0, 0); + SpriteFont font = LoadSpriteFontTTF("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.size; + float fontSize = font.baseSize; Vector2 fontPosition = { 40, screenHeight/2 + 50 }; Vector2 textSize; diff --git a/docs/examples/src/text_writing_anim.c b/docs/examples/src/text/text_writing_anim.c index 5563b561..5563b561 100644 --- a/docs/examples/src/text_writing_anim.c +++ b/docs/examples/src/text/text_writing_anim.c diff --git a/docs/examples/src/text_font_select.c b/docs/examples/src/text_font_select.c deleted file mode 100644 index fe586db8..00000000 --- a/docs/examples/src/text_font_select.c +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************************* -* -* raylib [text] example - Font selector -* -* 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 [text] example - font selector"); - - // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - SpriteFont fonts[8]; // SpriteFont array - - fonts[0] = LoadSpriteFont("resources/fonts/alagard.rbmf"); // SpriteFont loading - fonts[1] = LoadSpriteFont("resources/fonts/pixelplay.rbmf"); // SpriteFont loading - fonts[2] = LoadSpriteFont("resources/fonts/mecha.rbmf"); // SpriteFont loading - fonts[3] = LoadSpriteFont("resources/fonts/setback.rbmf"); // SpriteFont loading - fonts[4] = LoadSpriteFont("resources/fonts/romulus.rbmf"); // SpriteFont loading - fonts[5] = LoadSpriteFont("resources/fonts/pixantiqua.rbmf"); // SpriteFont loading - fonts[6] = LoadSpriteFont("resources/fonts/alpha_beta.rbmf"); // SpriteFont loading - fonts[7] = LoadSpriteFont("resources/fonts/jupiter_crash.rbmf"); // SpriteFont loading - - int currentFont = 0; // Selected font - - Color colors[8] = { MAROON, ORANGE, DARKGREEN, DARKBLUE, DARKPURPLE, LIME, GOLD, RED }; - - const char fontNames[8][20] = { "[0] Alagard", "[1] PixelPlay", "[2] MECHA", "[3] Setback", - "[4] Romulus", "[5] PixAntiqua", "[6] Alpha Beta", "[7] Jupiter Crash" }; - - const char text[50] = "THIS is THE FONT you SELECTED!"; // Main text - - Vector2 textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1); - - Vector2 mousePoint; - - Color btnNextOutColor = DARKBLUE; // Button color (outside line) - Color btnNextInColor = SKYBLUE; // Button color (inside) - - int framesCounter = 0; // Useful to count frames button is 'active' = clicked - - int positionY = 180; // Text selector and button Y position - - Rectangle btnNextRec = { 673, positionY, 109, 44 }; // Button rectangle (useful for collision) - - SetTargetFPS(60); // Set our game to run at 60 frames-per-second - //-------------------------------------------------------------------------------------- - - // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key - { - // Update - //---------------------------------------------------------------------------------- - - // Keyboard-based font selection (easy) - if (IsKeyPressed(KEY_RIGHT)) - { - if (currentFont < 7) currentFont++; - } - - if (IsKeyPressed(KEY_LEFT)) - { - if (currentFont > 0) currentFont--; - } - - if (IsKeyPressed('0')) currentFont = 0; - else if (IsKeyPressed('1')) currentFont = 1; - else if (IsKeyPressed('2')) currentFont = 2; - else if (IsKeyPressed('3')) currentFont = 3; - else if (IsKeyPressed('4')) currentFont = 4; - else if (IsKeyPressed('5')) currentFont = 5; - else if (IsKeyPressed('6')) currentFont = 6; - else if (IsKeyPressed('7')) currentFont = 7; - - // Mouse-based font selection (NEXT button logic) - mousePoint = GetMousePosition(); - - if (CheckCollisionPointRec(mousePoint, btnNextRec)) - { - // Mouse hover button logic - if (framesCounter == 0) - { - btnNextOutColor = DARKPURPLE; - btnNextInColor = PURPLE; - } - - if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) - { - framesCounter = 20; // Frames button is 'active' - btnNextOutColor = MAROON; - btnNextInColor = RED; - } - } - else - { - // Mouse not hover button - btnNextOutColor = DARKBLUE; - btnNextInColor = SKYBLUE; - } - - if (framesCounter > 0) framesCounter--; - - if (framesCounter == 1) // We change font on frame 1 - { - currentFont++; - if (currentFont > 7) currentFont = 0; - } - - // Text measurement for better positioning on screen - textSize = MeasureTextEx(fonts[currentFont], text, fonts[currentFont].size*3, 1); - //---------------------------------------------------------------------------------- - - // Draw - //---------------------------------------------------------------------------------- - BeginDrawing(); - - ClearBackground(RAYWHITE); - - DrawText("font selector - use arroys, button or numbers", 160, 80, 20, DARKGRAY); - DrawLine(120, 120, 680, 120, DARKGRAY); - - DrawRectangle(18, positionY, 644, 44, DARKGRAY); - DrawRectangle(20, positionY + 2, 640, 40, LIGHTGRAY); - DrawText(fontNames[currentFont], 30, positionY + 13, 20, BLACK); - DrawText("< >", 610, positionY + 8, 30, BLACK); - - DrawRectangleRec(btnNextRec, btnNextOutColor); - DrawRectangle(675, positionY + 2, 105, 40, btnNextInColor); - DrawText("NEXT", 700, positionY + 13, 20, btnNextOutColor); - - DrawTextEx(fonts[currentFont], text, (Vector2){ screenWidth/2 - textSize.x/2, - 260 + (70 - textSize.y)/2 }, fonts[currentFont].size*3, - 1, colors[currentFont]); - - EndDrawing(); - //---------------------------------------------------------------------------------- - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - for (int i = 0; i < 8; i++) UnloadSpriteFont(fonts[i]); // SpriteFont(s) unloading - - CloseWindow(); // Close window and OpenGL context - //-------------------------------------------------------------------------------------- - - return 0; -}
\ No newline at end of file diff --git a/docs/examples/src/textures_image_drawing.c b/docs/examples/src/textures/textures_image_drawing.c index 1c6a1fb9..1c6a1fb9 100644 --- a/docs/examples/src/textures_image_drawing.c +++ b/docs/examples/src/textures/textures_image_drawing.c diff --git a/docs/examples/src/textures_image_loading.c b/docs/examples/src/textures/textures_image_loading.c index 54c73586..54c73586 100644 --- a/docs/examples/src/textures_image_loading.c +++ b/docs/examples/src/textures/textures_image_loading.c diff --git a/docs/examples/src/textures_image_processing.c b/docs/examples/src/textures/textures_image_processing.c index 58b746e0..58b746e0 100644 --- a/docs/examples/src/textures_image_processing.c +++ b/docs/examples/src/textures/textures_image_processing.c diff --git a/docs/examples/src/textures_logo_raylib.c b/docs/examples/src/textures/textures_logo_raylib.c index f2f93128..f2f93128 100644 --- a/docs/examples/src/textures_logo_raylib.c +++ b/docs/examples/src/textures/textures_logo_raylib.c diff --git a/docs/examples/src/textures_particles_trail_blending.c b/docs/examples/src/textures/textures_particles_blending.c index 0b47c790..842ac77d 100644 --- a/docs/examples/src/textures_particles_trail_blending.c +++ b/docs/examples/src/textures/textures_particles_blending.c @@ -1,11 +1,11 @@ /******************************************************************************************* * -* raylib example - particles trail blending +* raylib example - particles blending * -* This example has been created using raylib 1.3 (www.raylib.com) +* This example has been created using raylib 1.7 (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) 2017 Ramon Santamaria (@raysan5) * ********************************************************************************************/ @@ -30,7 +30,7 @@ int main() int screenWidth = 800; int screenHeight = 450; - InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles trail blending"); + InitWindow(screenWidth, screenHeight, "raylib [textures] example - particles blending"); // Particles pool, reuse them! Particle mouseTail[MAX_PARTICLES]; diff --git a/docs/examples/src/textures_raw_data.c b/docs/examples/src/textures/textures_raw_data.c index d1922180..b038792b 100644 --- a/docs/examples/src/textures_raw_data.c +++ b/docs/examples/src/textures/textures_raw_data.c @@ -27,9 +27,9 @@ int main() // 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 + Image fudesumiRaw = LoadImageRaw("resources/fudesumi.raw", 384, 512, UNCOMPRESSED_R8G8B8A8, 0); + Texture2D fudesumi = LoadTextureFromImage(fudesumiRaw); // Upload CPU (RAM) image to GPU (VRAM) + UnloadImage(fudesumiRaw); // Unload CPU (RAM) image data // Generate a checked texture by code (1024x1024 pixels) int width = 1024; @@ -42,8 +42,8 @@ int main() { 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; + if (((x/32+y/32)/1)%2 == 0) pixels[y*height + x] = ORANGE; + else pixels[y*height + x] = GOLD; } } @@ -70,12 +70,14 @@ int main() ClearBackground(RAYWHITE); - DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.3f)); - DrawTexture(sonic, 330, -20, WHITE); + DrawTexture(checked, screenWidth/2 - checked.width/2, screenHeight/2 - checked.height/2, Fade(WHITE, 0.5f)); + DrawTexture(fudesumi, 430, -30, 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); + DrawText("CHECKED TEXTURE ", 84, 100, 30, BROWN); + DrawText("GENERATED by CODE", 72, 164, 30, BROWN); + DrawText("and RAW IMAGE LOADING", 46, 226, 30, BROWN); + + DrawText("(c) Fudesumi sprite by Eiden Marsal", 310, screenHeight - 20, 10, BROWN); EndDrawing(); //---------------------------------------------------------------------------------- @@ -83,7 +85,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(sonic); // Texture unloading + UnloadTexture(fudesumi); // Texture unloading UnloadTexture(checked); // Texture unloading CloseWindow(); // Close window and OpenGL context diff --git a/docs/examples/src/textures_rectangle.c b/docs/examples/src/textures/textures_rectangle.c index cca5b216..c90db8ac 100644 --- a/docs/examples/src/textures_rectangle.c +++ b/docs/examples/src/textures/textures_rectangle.c @@ -11,6 +11,9 @@ #include "raylib.h" +#define MAX_FRAME_SPEED 15 +#define MIN_FRAME_SPEED 1 + int main() { // Initialization @@ -21,11 +24,16 @@ int main() InitWindow(screenWidth, screenHeight, "raylib [texture] example - texture rectangle"); // NOTE: Textures MUST be loaded after Window initialization (OpenGL context is required) - Texture2D guybrush = LoadTexture("resources/guybrush.png"); // Texture loading + Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading - Vector2 position = { 350.0f, 240.0f }; - Rectangle frameRec = { 0, 0, guybrush.width/7, guybrush.height }; + Vector2 position = { 350.0f, 280.0f }; + Rectangle frameRec = { 0, 0, scarfy.width/6, scarfy.height }; int currentFrame = 0; + + int framesCounter = 0; + int framesSpeed = 8; // Number of spritesheet frames shown by second + + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- // Main game loop @@ -33,14 +41,23 @@ int main() { // Update //---------------------------------------------------------------------------------- - if (IsKeyPressed(KEY_RIGHT)) + framesCounter++; + + if (framesCounter >= (60/framesSpeed)) { + framesCounter = 0; currentFrame++; - if (currentFrame > 6) currentFrame = 0; + if (currentFrame > 5) currentFrame = 0; - frameRec.x = currentFrame*guybrush.width/7; + frameRec.x = currentFrame*scarfy.width/6; } + + if (IsKeyPressed(KEY_RIGHT)) framesSpeed++; + else if (IsKeyPressed(KEY_LEFT)) framesSpeed--; + + if (framesSpeed > MAX_FRAME_SPEED) framesSpeed = MAX_FRAME_SPEED; + else if (framesSpeed < MIN_FRAME_SPEED) framesSpeed = MIN_FRAME_SPEED; //---------------------------------------------------------------------------------- // Draw @@ -49,19 +66,23 @@ int main() ClearBackground(RAYWHITE); - DrawTexture(guybrush, 35, 40, WHITE); - DrawRectangleLines(35, 40, guybrush.width, guybrush.height, LIME); - - DrawTextureRec(guybrush, frameRec, position, WHITE); // Draw part of the texture + DrawTexture(scarfy, 15, 40, WHITE); + DrawRectangleLines(15, 40, scarfy.width, scarfy.height, LIME); + DrawRectangleLines(15 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); - DrawRectangleLines(35 + frameRec.x, 40 + frameRec.y, frameRec.width, frameRec.height, RED); + DrawText("FRAME SPEED: ", 165, 210, 10, DARKGRAY); + DrawText(FormatText("%02i FPS", framesSpeed), 575, 210, 10, DARKGRAY); + DrawText("PRESS RIGHT/LEFT KEYS to CHANGE SPEED!", 290, 240, 10, DARKGRAY); - DrawText("PRESS RIGHT KEY to", 540, 310, 10, GRAY); - DrawText("CHANGE DRAWING RECTANGLE", 520, 330, 10, GRAY); + for (int i = 0; i < MAX_FRAME_SPEED; i++) + { + if (i < framesSpeed) DrawRectangle(250 + 21*i, 205, 20, 20, RED); + DrawRectangleLines(250 + 21*i, 205, 20, 20, MAROON); + } - 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); + DrawTextureRec(scarfy, frameRec, position, WHITE); // Draw part of the texture + + DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -69,7 +90,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(guybrush); // Texture unloading + UnloadTexture(scarfy); // Texture unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/docs/examples/src/textures_srcrec_dstrec.c b/docs/examples/src/textures/textures_srcrec_dstrec.c index 6d824ce6..53ffd1d0 100644 --- a/docs/examples/src/textures_srcrec_dstrec.c +++ b/docs/examples/src/textures/textures_srcrec_dstrec.c @@ -21,10 +21,10 @@ 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 guybrush = LoadTexture("resources/guybrush.png"); // Texture loading + Texture2D scarfy = LoadTexture("resources/scarfy.png"); // Texture loading - int frameWidth = guybrush.width/7; - int frameHeight = guybrush.height; + int frameWidth = scarfy.width/6; + int frameHeight = scarfy.height; // NOTE: Source rectangle (part of the texture to use for drawing) Rectangle sourceRec = { 0, 0, frameWidth, frameHeight }; @@ -59,10 +59,12 @@ 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(guybrush, sourceRec, destRec, origin, rotation, WHITE); + DrawTexturePro(scarfy, sourceRec, destRec, origin, rotation, WHITE); DrawLine(destRec.x, 0, destRec.x, screenHeight, GRAY); DrawLine(0, destRec.y, screenWidth, destRec.y, GRAY); + + DrawText("(c) Scarfy sprite by Eiden Marsal", screenWidth - 200, screenHeight - 20, 10, GRAY); EndDrawing(); //---------------------------------------------------------------------------------- @@ -70,7 +72,7 @@ int main() // De-Initialization //-------------------------------------------------------------------------------------- - UnloadTexture(guybrush); // Texture unloading + UnloadTexture(scarfy); // Texture unloading CloseWindow(); // Close window and OpenGL context //-------------------------------------------------------------------------------------- diff --git a/docs/examples/src/textures_to_image.c b/docs/examples/src/textures/textures_to_image.c index 37c3b5a0..37c3b5a0 100644 --- a/docs/examples/src/textures_to_image.c +++ b/docs/examples/src/textures/textures_to_image.c diff --git a/docs/examples/src/textures_formats_loading.c b/docs/examples/src/textures_formats_loading.c deleted file mode 100644 index f416ce38..00000000 --- a/docs/examples/src/textures_formats_loading.c +++ /dev/null @@ -1,244 +0,0 @@ -/******************************************************************************************* -* -* 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 = 450; - - 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, 30 + 32*i, 150, 30 }; - else selectRecs[i] = (Rectangle){ 40 + 152, 30 + 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, -10, 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, 10, 10, DARKGRAY); - DrawText("Required GPU memory size (VRAM):", 40, 427, 10, DARKGRAY); - DrawText(FormatText("%4.0f KB", textureSizes[selectedFormat]), 240, 420, 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 |
