2727 #define GLSL_VERSION 100
2828#endif
2929
30+ #define MAX_INSTANCES 10000
31+
3032//------------------------------------------------------------------------------------
3133// Program main entry point
3234//------------------------------------------------------------------------------------
@@ -56,15 +58,14 @@ int main(void)
5658 camera .fovy = 45.0f ;
5759 camera .projection = CAMERA_PERSPECTIVE ;
5860
59- const int instances = 10000 ; // Number of instances to display
6061 Mesh cube = GenMeshCube (1.0f , 1.0f , 1.0f );
6162
62- Matrix * rotations = RL_MALLOC (instances * sizeof (Matrix )); // Rotation state of instances
63- Matrix * rotationsInc = RL_MALLOC (instances * sizeof (Matrix )); // Per-frame rotation animation of instances
64- Matrix * translations = RL_MALLOC (instances * sizeof (Matrix )); // Locations of instances
63+ Matrix * rotations = RL_MALLOC (MAX_INSTANCES * sizeof (Matrix )); // Rotation state of instances
64+ Matrix * rotationsInc = RL_MALLOC (MAX_INSTANCES * sizeof (Matrix )); // Per-frame rotation animation of instances
65+ Matrix * translations = RL_MALLOC (MAX_INSTANCES * sizeof (Matrix )); // Locations of instances
6566
6667 // Scatter random cubes around
67- for (int i = 0 ; i < instances ; i ++ )
68+ for (int i = 0 ; i < MAX_INSTANCES ; i ++ )
6869 {
6970 x = GetRandomValue (-50 , 50 );
7071 y = GetRandomValue (-50 , 50 );
@@ -81,7 +82,7 @@ int main(void)
8182 rotations [i ] = MatrixIdentity ();
8283 }
8384
84- Matrix * transforms = RL_MALLOC (instances * sizeof (Matrix )); // Pre-multiplied transformations passed to rlgl
85+ Matrix * transforms = RL_MALLOC (MAX_INSTANCES * sizeof (Matrix )); // Pre-multiplied transformations passed to rlgl
8586
8687 Shader shader = LoadShader (TextFormat ("resources/shaders/glsl%i/base_lighting_instanced.vs" , GLSL_VERSION ),
8788 TextFormat ("resources/shaders/glsl%i/lighting.fs" , GLSL_VERSION ));
@@ -146,7 +147,7 @@ int main(void)
146147 SetShaderValue (shader , shader .locs [SHADER_LOC_VECTOR_VIEW ], cameraPos , SHADER_UNIFORM_VEC3 );
147148
148149 // Apply per-instance transformations
149- for (int i = 0 ; i < instances ; i ++ )
150+ for (int i = 0 ; i < MAX_INSTANCES ; i ++ )
150151 {
151152 rotations [i ] = MatrixMultiply (rotations [i ], rotationsInc [i ]);
152153 transforms [i ] = MatrixMultiply (rotations [i ], translations [i ]);
@@ -174,7 +175,7 @@ int main(void)
174175
175176 BeginMode3D (camera );
176177 //DrawMesh(cube, material, MatrixIdentity());
177- DrawMeshInstanced (cube , material , transforms , instances );
178+ DrawMeshInstanced (cube , material , transforms , MAX_INSTANCES );
178179 EndMode3D ();
179180
180181 DrawText ("A CUBE OF DANCING CUBES!" , 490 , 10 , 20 , MAROON );
0 commit comments