diff options
| author | Ray <[email protected]> | 2021-03-26 00:12:29 +0100 |
|---|---|---|
| committer | Ray <[email protected]> | 2021-03-26 00:12:29 +0100 |
| commit | f9bab14fdb61ec7b6d407a4d3f742414c2842d50 (patch) | |
| tree | baabae88bcd789e87d7d7e417179e6e44eb58a08 /examples | |
| parent | c6828070dccb05d5d568d5f796e4a4760b45b8c5 (diff) | |
| download | raylib-f9bab14fdb61ec7b6d407a4d3f742414c2842d50.tar.gz raylib-f9bab14fdb61ec7b6d407a4d3f742414c2842d50.zip | |
REVIEWED: DrawMeshInstanced()
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/shaders/shaders_rlgl_mesh_instanced.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/examples/shaders/shaders_rlgl_mesh_instanced.c b/examples/shaders/shaders_rlgl_mesh_instanced.c index 3477b0cf..e786b8a0 100644 --- a/examples/shaders/shaders_rlgl_mesh_instanced.c +++ b/examples/shaders/shaders_rlgl_mesh_instanced.c @@ -59,15 +59,15 @@ int main(void) camera.fovy = 45.0f; camera.projection = CAMERA_PERSPECTIVE; - const int count = 10000; // Number of instances to display + const int instances = 10000; // Number of instances to display Mesh cube = GenMeshCube(1.0f, 1.0f, 1.0f); - Matrix *rotations = RL_MALLOC(count*sizeof(Matrix)); // Rotation state of instances - Matrix *rotationsInc = RL_MALLOC(count*sizeof(Matrix)); // Per-frame rotation animation of instances - Matrix *translations = RL_MALLOC(count*sizeof(Matrix)); // Locations of instances + Matrix *rotations = RL_MALLOC(instances*sizeof(Matrix)); // Rotation state of instances + Matrix *rotationsInc = RL_MALLOC(instances*sizeof(Matrix)); // Per-frame rotation animation of instances + Matrix *translations = RL_MALLOC(instances*sizeof(Matrix)); // Locations of instances // Scatter random cubes around - for (int i = 0; i < count; i++) + for (int i = 0; i < instances; i++) { x = GetRandomValue(-50, 50); y = GetRandomValue(-50, 50); @@ -84,7 +84,7 @@ int main(void) rotations[i] = MatrixIdentity(); } - Matrix *transforms = RL_MALLOC(count*sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl + Matrix *transforms = RL_MALLOC(instances*sizeof(Matrix)); // Pre-multiplied transformations passed to rlgl Shader shader = LoadShader(TextFormat("resources/shaders/glsl%i/base_lighting_instanced.vs", GLSL_VERSION), TextFormat("resources/shaders/glsl%i/lighting.fs", GLSL_VERSION)); @@ -107,19 +107,18 @@ int main(void) SetCameraMode(camera, CAMERA_ORBITAL); // Set an orbital camera mode int textPositionY = 300; - - int framesCounter = 0; // Simple frames counter to manage animation + int framesCounter = 0; // Simple frames counter to manage animation - SetTargetFPS(fps); // Set our game to run at 60 frames-per-second + SetTargetFPS(fps); // 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 { // Update //---------------------------------------------------------------------------------- - UpdateCamera(&camera); + textPositionY = 300; framesCounter++; if (IsKeyDown(KEY_UP)) amp += 0.5f; @@ -148,7 +147,7 @@ int main(void) SetShaderValue(shader, shader.locs[SHADER_LOC_VECTOR_VIEW], cameraPos, SHADER_UNIFORM_VEC3); // Apply per-instance transformations - for (int i = 0; i < count; i++) + for (int i = 0; i < instances; i++) { rotations[i] = MatrixMultiply(rotations[i], rotationsInc[i]); transforms[i] = MatrixMultiply(rotations[i], translations[i]); @@ -164,6 +163,8 @@ int main(void) transforms[i] = MatrixMultiply(transforms[i], MatrixTranslate(0.0f, y, 0.0f)); } + + UpdateCamera(&camera); //---------------------------------------------------------------------------------- // Draw @@ -173,7 +174,7 @@ int main(void) ClearBackground(RAYWHITE); BeginMode3D(camera); - DrawMeshInstanced(cube, material, transforms, count); + DrawMeshInstanced(cube, material, transforms, instances); EndMode3D(); DrawText("A CUBE OF DANCING CUBES!", 490, 10, 20, MAROON); |
