REVIEWED: Replace GetImageData() by LoadImageColors()
This commit is contained in:
parent
b7b718a545
commit
b2215cf017
20
src/models.c
20
src/models.c
@ -1752,7 +1752,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
||||
int mapX = heightmap.width;
|
||||
int mapZ = heightmap.height;
|
||||
|
||||
Color *pixels = GetImageData(heightmap);
|
||||
Color *pixels = LoadImageColors(heightmap);
|
||||
|
||||
// NOTE: One vertex per pixel
|
||||
mesh.triangleCount = (mapX-1)*(mapZ-1)*2; // One quad every four pixels
|
||||
@ -1868,7 +1868,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size)
|
||||
}
|
||||
}
|
||||
|
||||
RL_FREE(pixels);
|
||||
UnloadImageColors(pixels); // Unload pixels color data
|
||||
|
||||
// Upload vertex data to GPU (static mesh)
|
||||
rlLoadMesh(&mesh, false);
|
||||
@ -1885,7 +1885,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
Mesh mesh = { 0 };
|
||||
mesh.vboId = (unsigned int *)RL_CALLOC(DEFAULT_MESH_VERTEX_BUFFERS, sizeof(unsigned int));
|
||||
|
||||
Color *cubicmapPixels = GetImageData(cubicmap);
|
||||
Color *pixels = LoadImageColors(cubicmap);
|
||||
|
||||
int mapWidth = cubicmap.width;
|
||||
int mapHeight = cubicmap.height;
|
||||
@ -1943,7 +1943,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(cubicmapPixels[z*cubicmap.width + x], WHITE))
|
||||
if (COLOR_EQUAL(pixels[z*cubicmap.width + x], WHITE))
|
||||
{
|
||||
// Define triangles and checking collateral cubes
|
||||
//------------------------------------------------
|
||||
@ -2000,7 +2000,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
tcCounter += 6;
|
||||
|
||||
// Checking cube on bottom of current cube
|
||||
if (((z < cubicmap.height - 1) && COLOR_EQUAL(cubicmapPixels[(z + 1)*cubicmap.width + x], BLACK)) || (z == cubicmap.height - 1))
|
||||
if (((z < cubicmap.height - 1) && COLOR_EQUAL(pixels[(z + 1)*cubicmap.width + x], BLACK)) || (z == cubicmap.height - 1))
|
||||
{
|
||||
// Define front triangles (2 tris, 6 vertex) --> v2 v7 v3, v3 v7 v8
|
||||
// NOTE: Collateral occluded faces are not generated
|
||||
@ -2030,7 +2030,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
}
|
||||
|
||||
// Checking cube on top of current cube
|
||||
if (((z > 0) && COLOR_EQUAL(cubicmapPixels[(z - 1)*cubicmap.width + x], BLACK)) || (z == 0))
|
||||
if (((z > 0) && COLOR_EQUAL(pixels[(z - 1)*cubicmap.width + x], BLACK)) || (z == 0))
|
||||
{
|
||||
// Define back triangles (2 tris, 6 vertex) --> v1 v5 v6, v1 v4 v5
|
||||
// NOTE: Collateral occluded faces are not generated
|
||||
@ -2060,7 +2060,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
}
|
||||
|
||||
// Checking cube on right of current cube
|
||||
if (((x < cubicmap.width - 1) && COLOR_EQUAL(cubicmapPixels[z*cubicmap.width + (x + 1)], BLACK)) || (x == cubicmap.width - 1))
|
||||
if (((x < cubicmap.width - 1) && COLOR_EQUAL(pixels[z*cubicmap.width + (x + 1)], BLACK)) || (x == cubicmap.width - 1))
|
||||
{
|
||||
// Define right triangles (2 tris, 6 vertex) --> v3 v8 v4, v4 v8 v5
|
||||
// NOTE: Collateral occluded faces are not generated
|
||||
@ -2090,7 +2090,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
}
|
||||
|
||||
// Checking cube on left of current cube
|
||||
if (((x > 0) && COLOR_EQUAL(cubicmapPixels[z*cubicmap.width + (x - 1)], BLACK)) || (x == 0))
|
||||
if (((x > 0) && COLOR_EQUAL(pixels[z*cubicmap.width + (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
|
||||
@ -2120,7 +2120,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(cubicmapPixels[z*cubicmap.width + x], BLACK))
|
||||
else if (COLOR_EQUAL(pixels[z*cubicmap.width + x], BLACK))
|
||||
{
|
||||
// Define top triangles (2 tris, 6 vertex --> v1-v2-v3, v1-v3-v4)
|
||||
mapVertices[vCounter] = v1;
|
||||
@ -2220,7 +2220,7 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize)
|
||||
RL_FREE(mapNormals);
|
||||
RL_FREE(mapTexcoords);
|
||||
|
||||
RL_FREE(cubicmapPixels); // Free image pixel data
|
||||
UnloadImageColors(pixels); // Unload pixels color data
|
||||
|
||||
// Upload vertex data to GPU (static mesh)
|
||||
rlLoadMesh(&mesh, false);
|
||||
|
Loading…
Reference in New Issue
Block a user