diff --git a/resources/examples/raylib/guy.iqm b/resources/examples/raylib/guy.iqm new file mode 100644 index 000000000..36bed5e0f Binary files /dev/null and b/resources/examples/raylib/guy.iqm differ diff --git a/resources/examples/raylib/guyanim.iqm b/resources/examples/raylib/guyanim.iqm new file mode 100644 index 000000000..824a68a3b Binary files /dev/null and b/resources/examples/raylib/guyanim.iqm differ diff --git a/resources/examples/raylib/guytex.png b/resources/examples/raylib/guytex.png new file mode 100644 index 000000000..05a58eeaf Binary files /dev/null and b/resources/examples/raylib/guytex.png differ diff --git a/resources/examples/raylib/raybunny.png b/resources/examples/raylib/raybunny.png new file mode 100644 index 000000000..b608147bc Binary files /dev/null and b/resources/examples/raylib/raybunny.png differ diff --git a/resources/examples/raylib/raylib_arkanoid.c3 b/resources/examples/raylib/raylib_arkanoid.c3 index 729dab18a..8f51a0f82 100644 --- a/resources/examples/raylib/raylib_arkanoid.c3 +++ b/resources/examples/raylib/raylib_arkanoid.c3 @@ -1,6 +1,3 @@ -module arkanoid; -import raylib55; -import std::math; /** * * raylib - classic game: arkanoid @@ -11,6 +8,9 @@ import std::math; * Copyright (c) 2015 Ramon Santamaria (@raysan5) */ +module arkanoid; +import raylib55, std::math; + const int SCREEN_WIDTH = 800; const int SCREEN_HEIGHT = 450; diff --git a/resources/examples/raylib/raylib_audio_module_playing.c3 b/resources/examples/raylib/raylib_audio_module_playing.c3 index c24504eeb..8d4373587 100644 --- a/resources/examples/raylib/raylib_audio_module_playing.c3 +++ b/resources/examples/raylib/raylib_audio_module_playing.c3 @@ -1,5 +1,3 @@ -module arkanoid; -import raylib55; /******************************************************************************************* * * raylib [audio] example - module playing @@ -15,6 +13,8 @@ import raylib55; * converted to C3 by Christoffer Lerno * ********************************************************************************************/ +module raylib_audio_module; +import raylib55; const MAX_CIRCLES = 64; diff --git a/resources/examples/raylib/raylib_models_animation_playing.c3 b/resources/examples/raylib/raylib_models_animation_playing.c3 new file mode 100644 index 000000000..25e0fbb47 --- /dev/null +++ b/resources/examples/raylib/raylib_models_animation_playing.c3 @@ -0,0 +1,112 @@ +module raylib_models; +import raylib55; +/******************************************************************************************* +* +* raylib [models] example - animation playing +* +* Example complexity rating: [★★☆☆] 2/4 +* +* Example originally created with raylib 2.5, last time updated with raylib 3.5 +* +* Example contributed by Culacant (@culacant) 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) 2019-2025 Culacant (@culacant) and Ramon Santamaria (@raysan5) +* converted to C3 by Christoffer Lerno +* +******************************************************************************************** +* +* NOTE: To export a model from blender, make sure it is not posed, the vertices need to be +* in the same position as they would be in edit mode and the scale of your models is +* set to 0. Scaling can be done from the export menu +* +********************************************************************************************/ + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +fn int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int SCREEN_WIDTH = 800; + const int SCREEN_HEIGHT = 450; + + rl::init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [models] example - animation playing"); + + // Define the camera to look into our 3d world + RLCamera camera = { + .position = { .xyz = 10 }, // Camera position + .target = { .xyz = 0 }, // Camera looking at point + .up = { 0, 1, 0 }, // Camera up vector (rotation towards target) + .fovy = 45, // Camera field-of-view Y + .projection = PERSPECTIVE // Camera mode type + }; + + RLModel model = rl::load_model("guy.iqm"); // Load the animated model mesh and basic data + RLTexture2D texture = rl::load_texture("guytex.png"); // Load model texture and set material + model.materials[0].set_texture(DIFFUSE, texture); // Set model material map texture + + RLVector3 position; // Set model position to zero + + // Load animation data + RLModelAnimation[] anims = rl::load_model_animations("guyanim.iqm"); + int anim_frame_counter = 0; + + rl::disable_cursor(); // Catch cursor + rl::set_target_fps(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!rl::window_should_close()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + rl::update_camera(&camera, FIRST_PERSON); + + // Play animation when spacebar is held down + if (rl::is_key_down(SPACE)) + { + anim_frame_counter++; + rl::update_model_animation(model, anims[0], anim_frame_counter); + if (anim_frame_counter >= anims[0].frame_count) anim_frame_counter = 0; + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + rl::@drawing() + { + rl::clear_background(rl::RAYWHITE); + rl::@mode3d(camera) + { + rl::draw_model_ex(model, position, { 1, 0, 0 }, -90, (RLVector3)1, rl::WHITE); + + foreach (RLTransform pose : anims[0].frame_poses[anim_frame_counter][:model.bone_count]) + { + rl::draw_cube(pose.translation, 0.2f, 0.2f, 0.2f, rl::RED); + } + + rl::draw_grid(10, 1); // Draw a grid + }; + + rl::draw_text("PRESS SPACE to PLAY MODEL ANIMATION", 10, 10, 20, rl::MAROON); + rl::draw_text("(c) Guy IQM 3D model by @culacant", SCREEN_WIDTH - 200, SCREEN_HEIGHT - 20, 10, rl::GRAY); + + }; + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + rl::unload_texture(texture); // Unload texture + rl::unload_model_animations(anims); // Unload model animations data + rl::unload_model(model); // Unload model + + rl::close_window(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file diff --git a/resources/examples/raylib/raylib_textures_bunnymark.c3 b/resources/examples/raylib/raylib_textures_bunnymark.c3 new file mode 100644 index 000000000..5e7026654 --- /dev/null +++ b/resources/examples/raylib/raylib_textures_bunnymark.c3 @@ -0,0 +1,133 @@ +/******************************************************************************************* +* +* raylib [textures] example - bunnymark +* +* Example complexity rating: [★★★☆] 3/4 +* +* Example originally created with raylib 1.6, last time updated with raylib 2.5 +* +* 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) 2014-2025 Ramon Santamaria (@raysan5) +* converted to C3 by Christoffer Lerno +* +********************************************************************************************/ +module raylib_audio_module; +import raylib55; + +const int MAX_BUNNIES = 50000; // 50K bunnies limit + +// This is the maximum amount of elements (quads) per batch +// NOTE: This value is defined in [rlgl] module and can be changed there +const int MAX_BATCH_ELEMENTS = 8192; + +//---------------------------------------------------------------------------------- +// Types and Structures Definition +//---------------------------------------------------------------------------------- +struct Bunny +{ + RLVector2 position; + RLVector2 speed; + RLColor color; +} + +//------------------------------------------------------------------------------------ +// Program main entry point +//------------------------------------------------------------------------------------ +fn int main() +{ + // Initialization + //-------------------------------------------------------------------------------------- + const int SCREEN_WIDTH = 800; + const int SCREEN_HEIGHT = 450; + + rl::init_window(SCREEN_WIDTH, SCREEN_HEIGHT, "raylib [textures] example - bunnymark"); + + // Load bunny texture + RLTexture2D tex_bunny = rl::load_texture("raybunny.png"); + + Bunny[] bunnies = mem::alloc_array(Bunny, MAX_BUNNIES); // Bunnies array + + int bunnies_count = 0; // Bunnies counter + + rl::set_target_fps(60); // Set our game to run at 60 frames-per-second + //-------------------------------------------------------------------------------------- + + // Main game loop + while (!rl::window_should_close()) // Detect window close button or ESC key + { + // Update + //---------------------------------------------------------------------------------- + if (rl::is_mouse_button_down(LEFT)) + { + // Create more bunnies + for (int i = 0; i < 100; i++) + { + if (bunnies_count < MAX_BUNNIES) + { + bunnies[bunnies_count] = { + .position = rl::get_mouse_position(), + .speed = { rl::get_random_value(-250, 250) / 60.0f, rl::get_random_value(-250, 250) / 60.0f }, + .color = { (char)rl::get_random_value(50, 240), (char)rl::get_random_value(80, 240), (char)rl::get_random_value(100, 240), 255 } + }; + bunnies_count++; + } + } + } + + // Update bunnies + foreach (&bunny : bunnies[:bunnies_count]) + { + bunny.position += bunny.speed; + if (bunny.position.x + tex_bunny.width / 2.0f > rl::get_screen_width() + || bunny.position.x + tex_bunny.width / 2.0f < 0) + { + bunny.speed.x *= -1; + } + if (bunny.position.y + tex_bunny.height / 2.0f > rl::get_screen_height() + || bunny.position.y + tex_bunny.height / 2.0f - 40 < 0) + { + bunny.speed.y *= -1; + } + } + //---------------------------------------------------------------------------------- + + // Draw + //---------------------------------------------------------------------------------- + rl::@drawing() + { + rl::clear_background(rl::RAYWHITE); + + foreach (&bunny : bunnies[:bunnies_count]) + { + // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS), + // a draw call is launched and buffer starts being filled again; + // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU... + // Process of sending data is costly and it could happen that GPU data has not been completely + // processed for drawing while new data is tried to be sent (updating current in-use buffers) + // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies + rl::draw_texture(tex_bunny, (int)bunny.position.x, (int)bunny.position.y, bunny.color); + } + + rl::draw_rectangle(0, 0, SCREEN_WIDTH, 40, rl::BLACK); + rl::draw_text(rl::text_format("bunnies: %i", bunnies_count), 120, 10, 20, rl::GREEN); + rl::draw_text(rl::text_format("batched draw calls: %i", 1 + bunnies_count / MAX_BATCH_ELEMENTS), 320, 10, 20, rl::MAROON); + + rl::draw_fps(10, 10); + + }; + //---------------------------------------------------------------------------------- + } + + // De-Initialization + //-------------------------------------------------------------------------------------- + free(bunnies); // Unload bunnies data array + + rl::unload_texture(tex_bunny); // Unload bunny texture + + rl::close_window(); // Close window and OpenGL context + //-------------------------------------------------------------------------------------- + + return 0; +} \ No newline at end of file