diff options
| author | Ray <[email protected]> | 2023-11-08 17:41:08 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2023-11-08 17:41:08 +0100 |
| commit | bbf0c3a46d27b723e73483bdd787c7713b31fe1a (patch) | |
| tree | d0cb4223f357366f8eeb0171337f20f913100fd4 /examples | |
| parent | fe757b626703f91d59e04599ee033e993e00232b (diff) | |
| download | raylib-bbf0c3a46d27b723e73483bdd787c7713b31fe1a.tar.gz raylib-bbf0c3a46d27b723e73483bdd787c7713b31fe1a.zip | |
REVIEWED: Added new examples to VS2022 solution
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/Makefile | 141 | ||||
| -rw-r--r-- | examples/Makefile.Web | 141 | ||||
| -rw-r--r-- | examples/core/core_3d_camera_free.c | 2 | ||||
| -rw-r--r-- | examples/core/core_automation_events.png | bin | 0 -> 17155 bytes | |||
| -rw-r--r-- | examples/core/core_input_gamepad_info.c | 45 | ||||
| -rw-r--r-- | examples/shaders/shader_texture_tiling.c | 94 | ||||
| -rw-r--r-- | examples/shaders/shaders_custom_uniform.c | 2 | ||||
| -rw-r--r-- | examples/shaders/shaders_deferred_render.png | bin | 90692 -> 81327 bytes | |||
| -rw-r--r-- | examples/shaders/shaders_texture_tiling.c | 105 | ||||
| -rw-r--r-- | examples/shaders/shaders_texture_tiling.png | bin | 0 -> 139191 bytes | |||
| -rw-r--r-- | examples/shapes/shapes_lines_bezier.c | 6 | ||||
| -rw-r--r-- | examples/shapes/shapes_splines_drawing.c | 2 | ||||
| -rw-r--r-- | examples/shapes/shapes_top_down_lights.c | 1 |
13 files changed, 283 insertions, 256 deletions
diff --git a/examples/Makefile b/examples/Makefile index e126ab60..5cd8e6bb 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -428,97 +428,99 @@ endif # Define source code object files required #------------------------------------------------------------------------------------------------ CORE = \ - core/core_basic_window \ - core/core_basic_screen_manager \ - core/core_input_keys \ - core/core_input_mouse \ - core/core_input_mouse_wheel \ - core/core_input_gamepad \ - core/core_input_gamepad_info \ - core/core_input_multitouch \ - core/core_input_gestures \ - core/core_input_gestures_web \ core/core_2d_camera \ - core/core_2d_camera_platformer \ core/core_2d_camera_mouse_zoom \ + core/core_2d_camera_platformer \ core/core_2d_camera_split_screen \ - core/core_3d_camera_mode \ - core/core_3d_camera_free \ core/core_3d_camera_first_person \ + core/core_3d_camera_free \ + core/core_3d_camera_mode \ core/core_3d_camera_split_screen \ core/core_3d_picking \ - core/core_world_screen \ + core/core_automation_events \ + core/core_basic_screen_manager \ + core/core_basic_window \ + core/core_custom_frame_control \ core/core_custom_logging \ core/core_drop_files \ + core/core_input_gamepad \ + core/core_input_gamepad_info \ + core/core_input_gestures \ + core/core_input_gestures_web \ + core/core_input_keys \ + core/core_input_mouse \ + core/core_input_mouse_wheel \ + core/core_input_multitouch \ + core/core_loading_thread \ core/core_random_values \ core/core_scissor_test \ + core/core_smooth_pixelperfect \ core/core_storage_values \ core/core_vr_simulator \ - core/core_loading_thread \ core/core_window_flags \ core/core_window_letterbox \ core/core_window_should_close \ - core/core_smooth_pixelperfect \ - core/core_custom_frame_control + core/core_world_screen SHAPES = \ shapes/shapes_basic_shapes \ shapes/shapes_bouncing_ball \ - shapes/shapes_colors_palette \ - shapes/shapes_logo_raylib \ - shapes/shapes_logo_raylib_anim \ - shapes/shapes_rectangle_scaling \ - shapes/shapes_lines_bezier \ shapes/shapes_collision_area \ - shapes/shapes_following_eyes \ + shapes/shapes_colors_palette \ + shapes/shapes_draw_circle_sector \ + shapes/shapes_draw_rectangle_rounded \ + shapes/shapes_draw_ring \ shapes/shapes_easings_ball_anim \ shapes/shapes_easings_box_anim \ shapes/shapes_easings_rectangle_array \ - shapes/shapes_draw_ring \ - shapes/shapes_draw_circle_sector \ - shapes/shapes_draw_rectangle_rounded \ + shapes/shapes_following_eyes \ + shapes/shapes_lines_bezier \ + shapes/shapes_logo_raylib \ + shapes/shapes_logo_raylib_anim \ + shapes/shapes_rectangle_scaling \ + shapes/shapes_splines_drawing \ shapes/shapes_top_down_lights TEXTURES = \ - textures/textures_logo_raylib \ - textures/textures_mouse_painting \ - textures/textures_srcrec_dstrec \ + textures/textures_background_scrolling \ + textures/textures_blend_modes \ + textures/textures_bunnymark \ + textures/textures_draw_tiled \ + textures/textures_fog_of_war \ + textures/textures_gif_player \ textures/textures_image_drawing \ textures/textures_image_generation \ textures/textures_image_loading \ textures/textures_image_processing \ textures/textures_image_rotate \ textures/textures_image_text \ - textures/textures_to_image \ - textures/textures_raw_data \ - textures/textures_particles_blending \ + textures/textures_logo_raylib \ + textures/textures_mouse_painting \ textures/textures_npatch_drawing \ - textures/textures_background_scrolling \ + textures/textures_particles_blending \ + textures/textures_polygon \ + textures/textures_raw_data \ textures/textures_sprite_anim \ textures/textures_sprite_button \ textures/textures_sprite_explosion \ + textures/textures_srcrec_dstrec \ + textures/textures_svg_loading \ textures/textures_textured_curve \ - textures/textures_bunnymark \ - textures/textures_blend_modes \ - textures/textures_draw_tiled \ - textures/textures_polygon \ - textures/textures_gif_player \ - textures/textures_fog_of_war \ - textures/textures_svg_loading + textures/textures_to_image TEXT = \ - text/text_raylib_fonts \ - text/text_font_spritefont \ - text/text_font_loading \ + text/text_codepoints_loading \ + text/text_draw_3d \ text/text_font_filters \ + text/text_font_loading \ text/text_font_sdf \ + text/text_font_spritefont \ text/text_format_text \ text/text_input_box \ - text/text_writing_anim \ + text/text_raylib_fonts \ text/text_rectangle_bounds \ text/text_unicode \ - text/text_draw_3d \ - text/text_codepoints_loading + text/text_writing_anim MODELS = \ models/models_animation \ @@ -528,51 +530,52 @@ MODELS = \ models/models_draw_cube_texture \ models/models_first_person_maze \ models/models_geometric_shapes \ - models/models_mesh_generation \ - models/models_mesh_picking \ + models/models_heightmap \ models/models_loading \ - models/models_loading_vox \ models/models_loading_gltf \ models/models_loading_m3d \ + models/models_loading_vox \ + models/models_mesh_generation \ + models/models_mesh_picking \ models/models_orthographic_projection \ models/models_rlgl_solar_system \ models/models_skybox \ - models/models_yaw_pitch_roll \ - models/models_heightmap \ - models/models_waving_cubes + models/models_waving_cubes \ + models/models_yaw_pitch_roll SHADERS = \ - shaders/shaders_model_shader \ - shaders/shaders_shapes_textures \ + shaders/shaders_basic_lighting \ shaders/shaders_custom_uniform \ - shaders/shaders_postprocessing \ - shaders/shaders_palette_switch \ - shaders/shaders_raymarching \ - shaders/shaders_texture_drawing \ - shaders/shaders_texture_waves \ - shaders/shaders_texture_outline \ - shaders/shaders_julia_set \ + shaders/shaders_deferred_render \ shaders/shaders_eratosthenes \ - shaders/shaders_basic_lighting \ shaders/shaders_fog \ - shaders/shaders_simple_mask \ - shaders/shaders_spotlight \ shaders/shaders_hot_reloading \ + shaders/shaders_hybrid_render \ + shaders/shaders_julia_set \ shaders/shaders_lightmap \ shaders/shaders_mesh_instancing \ + shaders/shaders_model_shader \ shaders/shaders_multi_sample2d \ - shaders/shaders_write_depth \ - shaders/shaders_hybrid_render \ - shaders/shaders_deferred_render + shaders/shaders_palette_switch \ + shaders/shaders_postprocessing \ + shaders/shaders_raymarching \ + shaders/shaders_shapes_textures \ + shaders/shaders_simple_mask \ + shaders/shaders_spotlight \ + shaders/shaders_texture_drawing \ + shaders/shaders_texture_outline \ + shaders/shaders_texture_tiling \ + shaders/shaders_texture_waves \ + shaders/shaders_write_depth AUDIO = \ + audio/audio_mixed_processor \ audio/audio_module_playing \ audio/audio_music_stream \ audio/audio_raw_stream \ audio/audio_sound_loading \ audio/audio_sound_multi \ - audio/audio_stream_effects \ - audio/audio_mixed_processor + audio/audio_stream_effects OTHERS = \ others/easings_testbed \ diff --git a/examples/Makefile.Web b/examples/Makefile.Web index c57453ab..3e71206e 100644 --- a/examples/Makefile.Web +++ b/examples/Makefile.Web @@ -334,97 +334,99 @@ endif # Define source code object files required #------------------------------------------------------------------------------------------------ CORE = \ - core/core_basic_window \ - core/core_basic_screen_manager \ - core/core_input_keys \ - core/core_input_mouse \ - core/core_input_mouse_wheel \ - core/core_input_gamepad \ - core/core_input_gamepad_info \ - core/core_input_multitouch \ - core/core_input_gestures \ - core/core_input_gestures_web \ core/core_2d_camera \ - core/core_2d_camera_platformer \ core/core_2d_camera_mouse_zoom \ + core/core_2d_camera_platformer \ core/core_2d_camera_split_screen \ - core/core_3d_camera_mode \ - core/core_3d_camera_free \ core/core_3d_camera_first_person \ + core/core_3d_camera_free \ + core/core_3d_camera_mode \ core/core_3d_camera_split_screen \ core/core_3d_picking \ - core/core_world_screen \ + core/core_automation_events \ + core/core_basic_screen_manager \ + core/core_basic_window \ + core/core_custom_frame_control \ core/core_custom_logging \ core/core_drop_files \ + core/core_input_gamepad \ + core/core_input_gamepad_info \ + core/core_input_gestures \ + core/core_input_gestures_web \ + core/core_input_keys \ + core/core_input_mouse \ + core/core_input_mouse_wheel \ + core/core_input_multitouch \ + core/core_loading_thread \ core/core_random_values \ core/core_scissor_test \ + core/core_smooth_pixelperfect \ core/core_storage_values \ core/core_vr_simulator \ core/core_window_flags \ core/core_window_letterbox \ core/core_window_should_close \ - core/core_smooth_pixelperfect \ - core/core_custom_frame_control \ - core/core_loading_thread + core/core_world_screen SHAPES = \ shapes/shapes_basic_shapes \ shapes/shapes_bouncing_ball \ - shapes/shapes_colors_palette \ - shapes/shapes_logo_raylib \ - shapes/shapes_logo_raylib_anim \ - shapes/shapes_rectangle_scaling \ - shapes/shapes_lines_bezier \ shapes/shapes_collision_area \ - shapes/shapes_following_eyes \ + shapes/shapes_colors_palette \ + shapes/shapes_draw_circle_sector \ + shapes/shapes_draw_rectangle_rounded \ + shapes/shapes_draw_ring \ shapes/shapes_easings_ball_anim \ shapes/shapes_easings_box_anim \ shapes/shapes_easings_rectangle_array \ - shapes/shapes_draw_ring \ - shapes/shapes_draw_circle_sector \ - shapes/shapes_draw_rectangle_rounded \ + shapes/shapes_following_eyes \ + shapes/shapes_lines_bezier \ + shapes/shapes_logo_raylib \ + shapes/shapes_logo_raylib_anim \ + shapes/shapes_rectangle_scaling \ + shapes/shapes_splines_drawing \ shapes/shapes_top_down_lights TEXTURES = \ - textures/textures_logo_raylib \ - textures/textures_mouse_painting \ - textures/textures_srcrec_dstrec \ + textures/textures_background_scrolling \ + textures/textures_blend_modes \ + textures/textures_bunnymark \ + textures/textures_draw_tiled \ + textures/textures_fog_of_war \ + textures/textures_gif_player \ textures/textures_image_drawing \ textures/textures_image_generation \ textures/textures_image_loading \ textures/textures_image_processing \ textures/textures_image_rotate \ textures/textures_image_text \ - textures/textures_to_image \ - textures/textures_raw_data \ - textures/textures_particles_blending \ + textures/textures_logo_raylib \ + textures/textures_mouse_painting \ textures/textures_npatch_drawing \ - textures/textures_background_scrolling \ + textures/textures_particles_blending \ + textures/textures_polygon \ + textures/textures_raw_data \ textures/textures_sprite_anim \ textures/textures_sprite_button \ textures/textures_sprite_explosion \ + textures/textures_srcrec_dstrec \ + textures/textures_svg_loading \ textures/textures_textured_curve \ - textures/textures_bunnymark \ - textures/textures_blend_modes \ - textures/textures_draw_tiled \ - textures/textures_polygon \ - textures/textures_gif_player \ - textures/textures_fog_of_war \ - textures/textures_svg_loading + textures/textures_to_image TEXT = \ - text/text_raylib_fonts \ - text/text_font_spritefont \ - text/text_font_loading \ + text/text_codepoints_loading \ + text/text_draw_3d \ text/text_font_filters \ + text/text_font_loading \ text/text_font_sdf \ + text/text_font_spritefont \ text/text_format_text \ text/text_input_box \ - text/text_writing_anim \ + text/text_raylib_fonts \ text/text_rectangle_bounds \ text/text_unicode \ - text/text_draw_3d \ - text/text_codepoints_loading + text/text_writing_anim MODELS = \ models/models_animation \ @@ -434,51 +436,52 @@ MODELS = \ models/models_draw_cube_texture \ models/models_first_person_maze \ models/models_geometric_shapes \ - models/models_mesh_generation \ - models/models_mesh_picking \ + models/models_heightmap \ models/models_loading \ - models/models_loading_vox \ models/models_loading_gltf \ models/models_loading_m3d \ + models/models_loading_vox \ + models/models_mesh_generation \ + models/models_mesh_picking \ models/models_orthographic_projection \ models/models_rlgl_solar_system \ models/models_skybox \ - models/models_yaw_pitch_roll \ - models/models_heightmap \ - models/models_waving_cubes + models/models_waving_cubes \ + models/models_yaw_pitch_roll SHADERS = \ - shaders/shaders_model_shader \ - shaders/shaders_shapes_textures \ + shaders/shaders_basic_lighting \ shaders/shaders_custom_uniform \ - shaders/shaders_postprocessing \ - shaders/shaders_palette_switch \ - shaders/shaders_raymarching \ - shaders/shaders_texture_drawing \ - shaders/shaders_texture_waves \ - shaders/shaders_texture_outline \ - shaders/shaders_julia_set \ + shaders/shaders_deferred_render \ shaders/shaders_eratosthenes \ - shaders/shaders_basic_lighting \ shaders/shaders_fog \ - shaders/shaders_simple_mask \ - shaders/shaders_spotlight \ shaders/shaders_hot_reloading \ + shaders/shaders_hybrid_render \ + shaders/shaders_julia_set \ shaders/shaders_lightmap \ shaders/shaders_mesh_instancing \ + shaders/shaders_model_shader \ shaders/shaders_multi_sample2d \ - shaders/shaders_write_depth \ - shaders/shaders_hybrid_render \ - shaders/shaders_deferred_render + shaders/shaders_palette_switch \ + shaders/shaders_postprocessing \ + shaders/shaders_raymarching \ + shaders/shaders_shapes_textures \ + shaders/shaders_simple_mask \ + shaders/shaders_spotlight \ + shaders/shaders_texture_drawing \ + shaders/shaders_texture_outline \ + shaders/shaders_texture_tiling \ + shaders/shaders_texture_waves \ + shaders/shaders_write_depth AUDIO = \ + audio/audio_mixed_processor \ audio/audio_module_playing \ audio/audio_music_stream \ audio/audio_raw_stream \ audio/audio_sound_loading \ audio/audio_sound_multi \ - audio/audio_stream_effects \ - audio/audio_mixed_processor + audio/audio_stream_effects OTHERS = \ others/easings_testbed \ diff --git a/examples/core/core_3d_camera_free.c b/examples/core/core_3d_camera_free.c index ec849758..3c30a426 100644 --- a/examples/core/core_3d_camera_free.c +++ b/examples/core/core_3d_camera_free.c @@ -47,7 +47,7 @@ int main(void) //---------------------------------------------------------------------------------- UpdateCamera(&camera, CAMERA_FREE); - if (IsKeyDown('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; + if (IsKeyPressed('Z')) camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; //---------------------------------------------------------------------------------- // Draw diff --git a/examples/core/core_automation_events.png b/examples/core/core_automation_events.png Binary files differnew file mode 100644 index 00000000..49cf3282 --- /dev/null +++ b/examples/core/core_automation_events.png diff --git a/examples/core/core_input_gamepad_info.c b/examples/core/core_input_gamepad_info.c index 55f0354b..9aebb815 100644 --- a/examples/core/core_input_gamepad_info.c +++ b/examples/core/core_input_gamepad_info.c @@ -31,40 +31,49 @@ int main(void) InitWindow(screenWidth, screenHeight, "raylib [core] example - gamepad information"); SetTargetFPS(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- // Main game loop - while (!WindowShouldClose()) // Detect window close button or ESC key + while (!WindowShouldClose()) // Detect window close button or ESC key { - int y = 10; + // Update + //---------------------------------------------------------------------------------- + // TODO: Update your variables here + //---------------------------------------------------------------------------------- + // Draw + //---------------------------------------------------------------------------------- BeginDrawing(); - ClearBackground(RAYWHITE); + ClearBackground(RAYWHITE); - for (int i = 0; i < 4; i++) // by default rcore.h has a MAX_GAMEPADS of 4 so mimmic that here. - { - if (IsGamepadAvailable(i)) + for (int i = 0, y = 10; i < 4; i++) // MAX_GAMEPADS = 4 { - DrawText(TextFormat("Gamepad name: %s", GetGamepadName(i)), 10, y, 20, BLACK); - y += 30; - DrawText(TextFormat("\tAxis count: %d", GetGamepadAxisCount(i)), 10, y, 20, BLACK); - y += 30; - for (int axis = 0; axis < GetGamepadAxisCount(i); axis++) + if (IsGamepadAvailable(i)) { - DrawText(TextFormat("\tAxis %d = %f", axis, GetGamepadAxisMovement(i, axis)), 10, y, 20, BLACK); + DrawText(TextFormat("Gamepad name: %s", GetGamepadName(i)), 10, y, 20, BLACK); y += 30; - } - for (int button = 0; button < 32; button++) - { - DrawText(TextFormat("\tButton %d = %d", button, IsGamepadButtonDown(i, button)), 10, y, 20, BLACK); + DrawText(TextFormat("\tAxis count: %d", GetGamepadAxisCount(i)), 10, y, 20, BLACK); y += 30; + + for (int axis = 0; axis < GetGamepadAxisCount(i); axis++) + { + DrawText(TextFormat("\tAxis %d = %f", axis, GetGamepadAxisMovement(i, axis)), 10, y, 20, BLACK); + y += 30; + } + + for (int button = 0; button < 32; button++) + { + DrawText(TextFormat("\tButton %d = %d", button, IsGamepadButtonDown(i, button)), 10, y, 20, BLACK); + y += 30; + } } } - } - DrawFPS(GetScreenWidth() - 100, 100); + DrawFPS(GetScreenWidth() - 100, 100); EndDrawing(); + //---------------------------------------------------------------------------------- } // De-Initialization diff --git a/examples/shaders/shader_texture_tiling.c b/examples/shaders/shader_texture_tiling.c deleted file mode 100644 index 868d6b8f..00000000 --- a/examples/shaders/shader_texture_tiling.c +++ /dev/null @@ -1,94 +0,0 @@ -/******************************************************************************************* -* -* raylib [textures] example - Texture Tiling -* -* Example demonstrates how to tile a texture on a 3D model using raylib. -* -* Example contributed by Luís Almeida (https://github.com/luis605) -* -* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, -* BSD-like license that allows static linking with closed source software -* -* Copyright (c) 2023 Luís Almeida (https://github.com/luis605) -* -********************************************************************************************/ - -#include "raylib.h" - -//------------------------------------------------------------------------------------ -// Program main entry point -//------------------------------------------------------------------------------------ - -int main(void) -{ - const int screenWidth = 800; - const int screenHeight = 600; - - // Initialization - //-------------------------------------------------------------------------------------- - InitWindow(screenWidth, screenHeight, "Raylib Texture Tiling"); - - SetTargetFPS(60); - - // Load a texture - Texture2D texture = LoadTexture("resources/raylib_logo.png"); - - // Create a cube mesh - Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); - - // Load the texture onto the GPU - Model model = LoadModelFromMesh(cube); - model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; - - // Set the tiling of the texture - float tiling[2] = {3.0f, 3.0f}; - Shader shader = LoadShader(0, "resources/shaders/glsl330/tiling.fs"); // Create a custom shader in a .glsl file - SetShaderValue(shader, GetShaderLocation(shader, "tiling"), tiling, SHADER_UNIFORM_VEC2); - model.materials[0].shader = shader; - - // Camera setup - Camera camera = { 0 }; - camera.position = (Vector3){ 3.0f, 3.0f, 3.0f }; - camera.target = (Vector3){ 0.0f, 0.0f, 0.0f }; - camera.up = (Vector3){ 0.0f, 1.0f, 0.0f }; - camera.fovy = 45.0f; - camera.projection = CAMERA_PERSPECTIVE; - - // Main game loop - while (!WindowShouldClose()) - { - // Update - //---------------------------------------------------------------------------------- - - BeginDrawing(); - ClearBackground(RAYWHITE); - UpdateCamera(&camera, CAMERA_FREE); - - // Draw the model - { - BeginMode3D(camera); - BeginShaderMode(shader); - - DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 5.0f, WHITE); - - EndShaderMode(); - EndMode3D(); - } - - DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY); - - EndDrawing(); - } - - // De-Initialization - //-------------------------------------------------------------------------------------- - - UnloadTexture(texture); // Unload texture - UnloadModel(model); // Unload model - UnloadShader(shader); // Unload shader - - - CloseWindow(); // Close window and OpenGL context - - return 0; -} diff --git a/examples/shaders/shaders_custom_uniform.c b/examples/shaders/shaders_custom_uniform.c index 0a1a7642..b3b80400 100644 --- a/examples/shaders/shaders_custom_uniform.c +++ b/examples/shaders/shaders_custom_uniform.c @@ -1,6 +1,6 @@ /******************************************************************************************* * -* raylib [shaders] example - Apply a postprocessing shader and connect a custom uniform variable +* raylib [shaders] example - Postprocessing with custom uniform variable * * 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. diff --git a/examples/shaders/shaders_deferred_render.png b/examples/shaders/shaders_deferred_render.png Binary files differindex 44129f0f..90fa0129 100644 --- a/examples/shaders/shaders_deferred_render.png +++ b/examples/shaders/shaders_deferred_render.png diff --git a/examples/shaders/shaders_texture_tiling.c b/examples/shaders/shaders_texture_tiling.c new file mode 100644 index 00000000..0d07bdff --- /dev/null +++ b/examples/shaders/shaders_texture_tiling.c @@ -0,0 +1,105 @@ +/******************************************************************************************* +* +* raylib [shaders] example - texture tiling +* +* Example demonstrates how to tile a texture on a 3D model using raylib. +* +* Example contributed by Luis Almeida (@luis605) and reviewed by Ramon Santamaria (@raysan5) +* +* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, +* BSD-like license that allows static linking with closed source software +* +* Copyright (c) 2023 Luis Almeida (@luis605) +* +********************************************************************************************/ + +#include "raylib.h" + +#if defined(PLATFORM_DESKTOP) + #define GLSL_VERSION 330 +#else // PLATFORM_ANDROID, PLATFORM_WEB + #define GLSL_VERSION 100 +#endif + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +int main(void) +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int screenWidth = 800; + const int screenHeight = 450; + + InitWindow(screenWidth, screenHeight, "raylib [shaders] example - texture tiling"); + + // Define the camera to look into our 3d world + Camera3D camera = { 0 }; + camera.position = (Vector3){ 4.0f, 4.0f, 4.0f }; // Camera position + camera.target = (Vector3){ 0.0f, 0.5f, 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.projection = CAMERA_PERSPECTIVE; // Camera projection type + + // Load a cube model + Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); + Model model = LoadModelFromMesh(cube); + + // Load a texture and assign to cube model + Texture2D texture = LoadTexture("resources/cubicmap_atlas.png"); + model.materials[0].maps[MATERIAL_MAP_DIFFUSE].texture = texture; + + // Set the texture tiling using a shader + float tiling[2] = { 3.0f, 3.0f }; + Shader shader = LoadShader(0, TextFormat("resources/shaders/glsl%i/tiling.fs", GLSL_VERSION)); + SetShaderValue(shader, GetShaderLocation(shader, "tiling"), tiling, SHADER_UNIFORM_VEC2); + model.materials[0].shader = shader; + + DisableCursor(); // Limit cursor to relative movement inside the window + + 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, CAMERA_FREE); + + if (IsKeyPressed('Z')) camera.target = (Vector3){ 0.0f, 0.5f, 0.0f }; + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + BeginDrawing(); + + ClearBackground(RAYWHITE); + + BeginMode3D(camera); + + BeginShaderMode(shader); + DrawModel(model, (Vector3){ 0.0f, 0.0f, 0.0f }, 2.0f, WHITE); + EndShaderMode(); + + DrawGrid(10, 1.0f); + + EndMode3D(); + + DrawText("Use mouse to rotate the camera", 10, 10, 20, DARKGRAY); + + EndDrawing(); + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + UnloadModel(model); // Unload model + UnloadShader(shader); // Unload shader + UnloadTexture(texture); // Unload texture + + CloseWindow(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} diff --git a/examples/shaders/shaders_texture_tiling.png b/examples/shaders/shaders_texture_tiling.png Binary files differnew file mode 100644 index 00000000..5dfe76ef --- /dev/null +++ b/examples/shaders/shaders_texture_tiling.png diff --git a/examples/shapes/shapes_lines_bezier.c b/examples/shapes/shapes_lines_bezier.c index 5bd916ee..785d73a6 100644 --- a/examples/shapes/shapes_lines_bezier.c +++ b/examples/shapes/shapes_lines_bezier.c @@ -60,11 +60,11 @@ int main(void) DrawText("USE MOUSE LEFT-RIGHT CLICK to DEFINE LINE START and END POINTS", 15, 20, 20, GRAY); - // Draw line cubic-bezier, in-out interpolation (easing), no control points + // Draw line Cubic Bezier, in-out interpolation (easing), no control points DrawLineBezier(start, end, 3.0f, BLUE); - // Draw spline cubic-bezier with control points - DrawSplineBezierCubic(start, startControl, endControl, end, 2.0f, RED); + // Draw spline Cubic Bezier with control points + DrawSplineSegmentBezierCubic(start, startControl, endControl, end, 2.0f, RED); DrawLineEx(start, startControl, 1.0, LIGHTGRAY); DrawLineEx(end, endControl, 1.0, LIGHTGRAY); diff --git a/examples/shapes/shapes_splines_drawing.c b/examples/shapes/shapes_splines_drawing.c index 58fcaf69..cfac931b 100644 --- a/examples/shapes/shapes_splines_drawing.c +++ b/examples/shapes/shapes_splines_drawing.c @@ -167,7 +167,7 @@ int main(void) // Draw spline: cubic-bezier (with control points) for (int i = 0; i < pointCount - 1; i++) { - DrawSplineBezierCubic(points[i], control[i].start, control[i].end, points[i + 1], 2.0f, RED); + DrawSplineSegmentBezierCubic(points[i], control[i].start, control[i].end, points[i + 1], 10.0f, RED); // Every cubic bezier point should have two control points DrawCircleV(control[i].start, 4, GOLD); diff --git a/examples/shapes/shapes_top_down_lights.c b/examples/shapes/shapes_top_down_lights.c index b09137cb..f22cf3c1 100644 --- a/examples/shapes/shapes_top_down_lights.c +++ b/examples/shapes/shapes_top_down_lights.c @@ -335,6 +335,7 @@ int main(void) DrawFPS(screenWidth - 80, 10); DrawText("Drag to move light #1", 10, 10, 10, DARKGREEN); DrawText("Right click to add new light", 10, 30, 10, DARKGREEN); + EndDrawing(); //---------------------------------------------------------------------------------- } |
