MCPcopy Create free account
hub / github.com/RobLoach/raylib-cpp / main

Function main

examples/textures/textures_bunnymark.cpp:47–109  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

45};
46
47int main(void)
48{
49 // Initialization
50 //--------------------------------------------------------------------------------------
51 const int screenWidth = 800;
52 const int screenHeight = 450;
53
54 raylib::Window window(screenWidth, screenHeight, "raylib [textures] example - bunnymark");
55
56 // Load bunny texture
57 raylib::Texture2D texBunny("resources/wabbit_alpha.png");
58
59 std::list<Bunny> bunnies;
60
61 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
62 //--------------------------------------------------------------------------------------
63
64 // Main game loop
65 while (!window.ShouldClose()) { // Detect window close button or ESC key
66 // Update
67 //----------------------------------------------------------------------------------
68 if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
69 // Create more bunnies
70 for (int i = 0; i < 100; i++) {
71 bunnies.emplace_back();
72 }
73 }
74
75 // Update bunnies
76
77 for (Bunny& bunny: bunnies) {
78 bunny.Update(texBunny);
79 }
80 //----------------------------------------------------------------------------------
81
82 // Draw
83 //----------------------------------------------------------------------------------
84 BeginDrawing();
85 {
86 window.ClearBackground(RAYWHITE);
87
88 for (Bunny& bunny : bunnies) {
89 // NOTE: When internal batch buffer limit is reached (MAX_BATCH_ELEMENTS),
90 // a draw call is launched and buffer starts being filled again;
91 // before issuing a draw call, updated vertex data from internal CPU buffer is send to GPU...
92 // Process of sending data is costly and it could happen that GPU data has not been completely
93 // processed for drawing while new data is tried to be sent (updating current in-use buffers)
94 // it could generates a stall and consequently a frame drop, limiting the number of drawn bunnies
95 texBunny.Draw(bunny.position, bunny.color);
96 }
97
98 DrawRectangle(0, 0, screenWidth, 40, BLACK);
99 raylib::DrawText(TextFormat("bunnies: %i", bunnies.size()), 120, 10, 20, GREEN);
100 raylib::DrawText(TextFormat("batched draw calls: %i", 1 + bunnies.size()/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);
101
102 DrawFPS(10, 10);
103 }
104 EndDrawing();

Callers

nothing calls this directly

Calls 5

ShouldCloseMethod · 0.80
DrawRectangleFunction · 0.50
DrawTextFunction · 0.50
UpdateMethod · 0.45
DrawMethod · 0.45

Tested by

no test coverage detected