diff --git a/src/rmodels.c b/src/rmodels.c index 6b2b4b9f0..8f80cace4 100644 --- a/src/rmodels.c +++ b/src/rmodels.c @@ -2944,7 +2944,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) int mapHeight = cubicmap.height; // NOTE: Max possible number of triangles numCubes*(12 triangles by cube) - int maxTriangles = cubicmap.width*cubicmap.height*12; + int maxTriangles = mapWidth * mapHeight * 12; int vCounter = 0; // Used to count vertices int tcCounter = 0; // Used to count texcoords @@ -2996,7 +2996,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) Vector3 v8 = { w*(x + 0.5f), 0, h*(z + 0.5f) }; // We check pixel color to be WHITE -> draw full cube - if (COLOR_EQUAL(pixels[z*cubicmap.width + x], WHITE)) + if (COLOR_EQUAL(pixels[z*mapWidth + x], WHITE)) { // Define triangles and checking collateral cubes //------------------------------------------------ @@ -3053,7 +3053,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) tcCounter += 6; // Checking cube on bottom of current cube - if (((z < cubicmap.height - 1) && COLOR_EQUAL(pixels[(z + 1)*cubicmap.width + x], BLACK)) || (z == cubicmap.height - 1)) + if (((z < mapHeight - 1) && COLOR_EQUAL(pixels[(z + 1)*mapWidth + x], BLACK)) || (z == mapHeight - 1)) { // Define front triangles (2 tris, 6 vertex) --> v2 v7 v3, v3 v7 v8 // NOTE: Collateral occluded faces are not generated @@ -3083,7 +3083,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) } // Checking cube on top of current cube - if (((z > 0) && COLOR_EQUAL(pixels[(z - 1)*cubicmap.width + x], BLACK)) || (z == 0)) + if (((z > 0) && COLOR_EQUAL(pixels[(z - 1)*mapWidth + x], BLACK)) || (z == 0)) { // Define back triangles (2 tris, 6 vertex) --> v1 v5 v6, v1 v4 v5 // NOTE: Collateral occluded faces are not generated @@ -3113,7 +3113,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) } // Checking cube on right of current cube - if (((x < cubicmap.width - 1) && COLOR_EQUAL(pixels[z*cubicmap.width + (x + 1)], BLACK)) || (x == cubicmap.width - 1)) + if (((x < mapWidth - 1) && COLOR_EQUAL(pixels[z*mapWidth + (x + 1)], BLACK)) || (x == mapWidth - 1)) { // Define right triangles (2 tris, 6 vertex) --> v3 v8 v4, v4 v8 v5 // NOTE: Collateral occluded faces are not generated @@ -3143,7 +3143,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) } // Checking cube on left of current cube - if (((x > 0) && COLOR_EQUAL(pixels[z*cubicmap.width + (x - 1)], BLACK)) || (x == 0)) + if (((x > 0) && COLOR_EQUAL(pixels[z*mapWidth + (x - 1)], BLACK)) || (x == 0)) { // Define left triangles (2 tris, 6 vertex) --> v1 v7 v2, v1 v6 v7 // NOTE: Collateral occluded faces are not generated @@ -3173,7 +3173,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) } } // We check pixel color to be BLACK, we will only draw floor and roof - else if (COLOR_EQUAL(pixels[z*cubicmap.width + x], BLACK)) + else if (COLOR_EQUAL(pixels[z*mapWidth + x], BLACK)) { // Define top triangles (2 tris, 6 vertex --> v1-v2-v3, v1-v3-v4) mapVertices[vCounter] = v1;