summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorRay <[email protected]>2019-05-06 16:38:58 +0200
committerRay <[email protected]>2019-05-06 16:38:58 +0200
commit621965cb8cbb743820dd66bdde61fc3c79b156a8 (patch)
tree1cfbdf38c6ff775675999d33487327107d887a6a /examples
parent8bafe03ee001b7af6ab638941683f42feb1aef65 (diff)
downloadraylib-621965cb8cbb743820dd66bdde61fc3c79b156a8.tar.gz
raylib-621965cb8cbb743820dd66bdde61fc3c79b156a8.zip
Move bunnymark example to another module
Diffstat (limited to 'examples')
-rw-r--r--examples/others/resources/wabbit_alpha.pngbin449 -> 0 bytes
-rw-r--r--examples/textures/resources/wabbit_alpha.pngbin0 -> 561 bytes
-rw-r--r--examples/textures/textures_bunnymark.c (renamed from examples/others/bunnymark.c)59
3 files changed, 37 insertions, 22 deletions
diff --git a/examples/others/resources/wabbit_alpha.png b/examples/others/resources/wabbit_alpha.png
deleted file mode 100644
index 79c31675..00000000
--- a/examples/others/resources/wabbit_alpha.png
+++ /dev/null
Binary files differ
diff --git a/examples/textures/resources/wabbit_alpha.png b/examples/textures/resources/wabbit_alpha.png
new file mode 100644
index 00000000..1a5eb0b4
--- /dev/null
+++ b/examples/textures/resources/wabbit_alpha.png
Binary files differ
diff --git a/examples/others/bunnymark.c b/examples/textures/textures_bunnymark.c
index 8b524b01..76078838 100644
--- a/examples/others/bunnymark.c
+++ b/examples/textures/textures_bunnymark.c
@@ -1,18 +1,23 @@
/*******************************************************************************************
*
-* raylib example - Bunnymark
+* raylib [textures] example - Bunnymark
*
* This example has been created using raylib 1.6 (www.raylib.com)
* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
*
-* Copyright (c) 2014 Ramon Santamaria (@raysan5)
+* Copyright (c) 2014-2019 Ramon Santamaria (@raysan5)
*
********************************************************************************************/
#include "raylib.h"
-#include <stdlib.h> // Required for: malloc(), free()
-#define MAX_BUNNIES 100000 // 100K bunnies
+#include <stdlib.h> // Required for: malloc(), free()
+
+#define MAX_BUNNIES 100000 // 100K 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
+#define MAX_BATCH_ELEMENTS 8192
typedef struct Bunny {
Vector2 position;
@@ -24,10 +29,10 @@ int main()
{
// Initialization
//--------------------------------------------------------------------------------------
- int screenWidth = 1280;
- int screenHeight = 960;
+ const int screenWidth = 800;
+ const int screenHeight = 450;
- InitWindow(screenWidth, screenHeight, "raylib example - Bunnymark");
+ InitWindow(screenWidth, screenHeight, "raylib [textures] example - bunnymark");
Texture2D texBunny = LoadTexture("resources/wabbit_alpha.png");
@@ -49,8 +54,11 @@ int main()
for (int i = 0; i < 100; i++)
{
bunnies[bunniesCount].position = GetMousePosition();
- bunnies[bunniesCount].speed.x = (float)GetRandomValue(250, 500)/60.0f;
- bunnies[bunniesCount].speed.y = (float)(GetRandomValue(250, 500) - 500)/60.0f;
+ bunnies[bunniesCount].speed.x = (float)GetRandomValue(-250, 250)/60.0f;
+ bunnies[bunniesCount].speed.y = (float)GetRandomValue(-250, 250)/60.0f;
+ bunnies[bunniesCount].color = (Color){ GetRandomValue(50, 240),
+ GetRandomValue(80, 240),
+ GetRandomValue(100, 240), 255 };
bunniesCount++;
}
}
@@ -61,8 +69,10 @@ int main()
bunnies[i].position.x += bunnies[i].speed.x;
bunnies[i].position.y += bunnies[i].speed.y;
- if ((bunnies[i].position.x > GetScreenWidth()) || (bunnies[i].position.x < 0)) bunnies[i].speed.x *= -1;
- if ((bunnies[i].position.y > GetScreenHeight()) || (bunnies[i].position.y < 0)) bunnies[i].speed.y *= -1;
+ if (((bunnies[i].position.x + texBunny.width/2) > GetScreenWidth()) ||
+ ((bunnies[i].position.x + texBunny.width/2) < 0)) bunnies[i].speed.x *= -1;
+ if (((bunnies[i].position.y + texBunny.height/2) > GetScreenHeight()) ||
+ ((bunnies[i].position.y + texBunny.height/2 - 40) < 0)) bunnies[i].speed.y *= -1;
}
//----------------------------------------------------------------------------------
@@ -74,17 +84,20 @@ int main()
for (int i = 0; i < bunniesCount; i++)
{
- // NOTE: When internal QUADS batch limit is reached, a draw call is launched and
- // batching buffer starts being filled again; before launching the draw call,
- // updated vertex data from internal buffer is send to GPU... it seems it generates
- // a stall and consequently a frame drop, limiting number of bunnies drawn at 60 fps
- DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, RAYWHITE);
+ // 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
+ DrawTexture(texBunny, bunnies[i].position.x, bunnies[i].position.y, bunnies[i].color);
}
- DrawRectangle(0, 0, screenWidth, 40, LIGHTGRAY);
- DrawText("raylib bunnymark", 10, 10, 20, DARKGRAY);
- DrawText(FormatText("bunnies: %i", bunniesCount), 400, 10, 20, RED);
- DrawFPS(260, 10);
+ DrawRectangle(0, 0, screenWidth, 40, BLACK);
+ DrawText(FormatText("bunnies: %i", bunniesCount), 120, 10, 20, GREEN);
+ DrawText(FormatText("batched draw calls: %i", 1 + bunniesCount/MAX_BATCH_ELEMENTS), 320, 10, 20, MAROON);
+
+ DrawFPS(10, 10);
EndDrawing();
//----------------------------------------------------------------------------------
@@ -92,9 +105,11 @@ int main()
// De-Initialization
//--------------------------------------------------------------------------------------
- free(bunnies);
+ free(bunnies); // Unload bunnies data array
+
+ UnloadTexture(texBunny); // Unload bunny texture
- CloseWindow(); // Close window and OpenGL context
+ CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0;