From 641895b5ba778fdc9024ebb58446dcc8ea36a00a Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 21 Feb 2019 18:45:19 +0100 Subject: [PATCH] Remove end-line spaces --- src/core.c | 6 +- src/models.c | 208 ++++++++++++++++++++++++------------------------- src/raudio.c | 14 ++-- src/rlgl.h | 114 +++++++++++++-------------- src/shapes.c | 8 +- src/text.c | 86 ++++++++++---------- src/textures.c | 4 +- 7 files changed, 220 insertions(+), 220 deletions(-) diff --git a/src/core.c b/src/core.c index 36315113..714e6e2c 100644 --- a/src/core.c +++ b/src/core.c @@ -707,7 +707,7 @@ bool WindowShouldClose(void) { #if defined(PLATFORM_WEB) // Emterpreter-Async required to run sync code - // https://github.com/kripken/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code + // https://github.com/emscripten-core/emscripten/wiki/Emterpreter#emterpreter-async-run-synchronous-code // By default, this function is never called on a web-ready raylib example because we encapsulate // frame code in a UpdateDrawFrame() function, to allow browser manage execution asynchronously // but now emscripten allows sync code to be executed in an interpreted way, using emterpreter! @@ -1228,7 +1228,7 @@ void BeginTextureMode(RenderTexture2D target) rlLoadIdentity(); // Reset current matrix (MODELVIEW) //rlScalef(0.0f, -1.0f, 0.0f); // Flip Y-drawing (?) - + // Setup current width/height for proper aspect ratio // calculation when using BeginMode3D() currentWidth = target.texture.width; @@ -1254,7 +1254,7 @@ void EndTextureMode(void) rlMatrixMode(RL_MODELVIEW); // Switch back to MODELVIEW matrix rlLoadIdentity(); // Reset current matrix (MODELVIEW) - + // Reset current screen size currentWidth = GetScreenWidth(); currentHeight = GetScreenHeight(); diff --git a/src/models.c b/src/models.c index eace0f66..384c8db4 100644 --- a/src/models.c +++ b/src/models.c @@ -116,7 +116,7 @@ void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color) void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color) { if (rlCheckBufferLimit(2*36)) rlglDraw(); - + rlPushMatrix(); rlTranslatef(center.x, center.y, center.z); rlRotatef(rotationAngle, rotationAxis.x, rotationAxis.y, rotationAxis.z); @@ -140,7 +140,7 @@ void DrawCube(Vector3 position, float width, float height, float length, Color c float x = 0.0f; float y = 0.0f; float z = 0.0f; - + if (rlCheckBufferLimit(36)) rlglDraw(); rlPushMatrix(); @@ -221,7 +221,7 @@ void DrawCubeWires(Vector3 position, float width, float height, float length, Co float x = 0.0f; float y = 0.0f; float z = 0.0f; - + if (rlCheckBufferLimit(36)) rlglDraw(); rlPushMatrix(); @@ -626,7 +626,7 @@ Model LoadModel(const char *fileName) Model LoadModelFromMesh(Mesh mesh) { Model model = { 0 }; - + model.mesh = mesh; model.transform = MatrixIdentity(); model.material = LoadMaterialDefault(); @@ -679,11 +679,11 @@ void UnloadMesh(Mesh *mesh) void ExportMesh(Mesh mesh, const char *fileName) { bool success = false; - + if (IsFileExtension(fileName, ".obj")) { FILE *objFile = fopen(fileName, "wt"); - + fprintf(objFile, "# //////////////////////////////////////////////////////////////////////////////////\n"); fprintf(objFile, "# // //\n"); fprintf(objFile, "# // rMeshOBJ exporter v1.0 - Mesh exported as triangle faces and not optimized //\n"); @@ -696,33 +696,33 @@ void ExportMesh(Mesh mesh, const char *fileName) fprintf(objFile, "# //////////////////////////////////////////////////////////////////////////////////\n\n"); fprintf(objFile, "# Vertex Count: %i\n", mesh.vertexCount); fprintf(objFile, "# Triangle Count: %i\n\n", mesh.triangleCount); - + fprintf(objFile, "g mesh\n"); - + for (int i = 0, v = 0; i < mesh.vertexCount; i++, v += 3) { fprintf(objFile, "v %.2f %.2f %.2f\n", mesh.vertices[v], mesh.vertices[v + 1], mesh.vertices[v + 2]); } - + for (int i = 0, v = 0; i < mesh.vertexCount; i++, v += 2) { fprintf(objFile, "vt %.2f %.2f\n", mesh.texcoords[v], mesh.texcoords[v + 1]); } - + for (int i = 0, v = 0; i < mesh.vertexCount; i++, v += 3) { fprintf(objFile, "vn %.2f %.2f %.2f\n", mesh.normals[v], mesh.normals[v + 1], mesh.normals[v + 2]); } - + for (int i = 0; i < mesh.triangleCount; i += 3) { fprintf(objFile, "f %i/%i/%i %i/%i/%i %i/%i/%i\n", i, i, i, i + 1, i + 1, i + 1, i + 2, i + 2, i + 2); } - + fprintf(objFile, "\n"); - + fclose(objFile); - + success = true; } else if (IsFileExtension(fileName, ".raw")) { } // TODO: Support additional file formats to export mesh vertex data @@ -737,7 +737,7 @@ Mesh GenMeshPoly(int sides, float radius) { Mesh mesh = { 0 }; int vertexCount = sides*3; - + // Vertices definition Vector3 *vertices = (Vector3 *)malloc(vertexCount*sizeof(Vector3)); for (int i = 0, v = 0; i < 360; i += 360/sides, v += 3) @@ -745,13 +745,13 @@ Mesh GenMeshPoly(int sides, float radius) vertices[v] = (Vector3){ 0.0f, 0.0f, 0.0f }; vertices[v + 1] = (Vector3){ sinf(DEG2RAD*i)*radius, 0.0f, cosf(DEG2RAD*i)*radius }; vertices[v + 2] = (Vector3){ sinf(DEG2RAD*(i + 360/sides))*radius, 0.0f, cosf(DEG2RAD*(i + 360/sides))*radius }; - } - + } + // Normals definition Vector3 *normals = (Vector3 *)malloc(vertexCount*sizeof(Vector3)); for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up; - // TexCoords definition + // TexCoords definition Vector2 *texcoords = (Vector2 *)malloc(vertexCount*sizeof(Vector2)); for (int n = 0; n < vertexCount; n++) texcoords[n] = (Vector2){ 0.0f, 0.0f }; @@ -760,7 +760,7 @@ Mesh GenMeshPoly(int sides, float radius) mesh.vertices = (float *)malloc(mesh.vertexCount*3*sizeof(float)); mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float)); mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float)); - + // Mesh vertices position array for (int i = 0; i < mesh.vertexCount; i++) { @@ -768,14 +768,14 @@ Mesh GenMeshPoly(int sides, float radius) mesh.vertices[3*i + 1] = vertices[i].y; mesh.vertices[3*i + 2] = vertices[i].z; } - + // Mesh texcoords array for (int i = 0; i < mesh.vertexCount; i++) { mesh.texcoords[2*i] = texcoords[i].x; mesh.texcoords[2*i + 1] = texcoords[i].y; } - + // Mesh normals array for (int i = 0; i < mesh.vertexCount; i++) { @@ -783,14 +783,14 @@ Mesh GenMeshPoly(int sides, float radius) mesh.normals[3*i + 1] = normals[i].y; mesh.normals[3*i + 2] = normals[i].z; } - + free(vertices); free(normals); free(texcoords); // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); - + rlLoadMesh(&mesh, false); + return mesh; } @@ -803,7 +803,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) #if defined(CUSTOM_MESH_GEN_PLANE) resX++; resZ++; - + // Vertices definition int vertexCount = resX*resZ; // vertices get reused for the faces @@ -824,7 +824,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) Vector3 *normals = (Vector3 *)malloc(vertexCount*sizeof(Vector3)); for (int n = 0; n < vertexCount; n++) normals[n] = (Vector3){ 0.0f, 1.0f, 0.0f }; // Vector3.up; - // TexCoords definition + // TexCoords definition Vector2 *texcoords = (Vector2 *)malloc(vertexCount*sizeof(Vector2)); for (int v = 0; v < resZ; v++) { @@ -847,7 +847,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) triangles[t++] = i + 1; triangles[t++] = i; - triangles[t++] = i + resX; + triangles[t++] = i + resX; triangles[t++] = i + resX + 1; triangles[t++] = i + 1; } @@ -858,7 +858,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) mesh.texcoords = (float *)malloc(mesh.vertexCount*2*sizeof(float)); mesh.normals = (float *)malloc(mesh.vertexCount*3*sizeof(float)); mesh.indices = (unsigned short *)malloc(mesh.triangleCount*3*sizeof(unsigned short)); - + // Mesh vertices position array for (int i = 0; i < mesh.vertexCount; i++) { @@ -866,14 +866,14 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) mesh.vertices[3*i + 1] = vertices[i].y; mesh.vertices[3*i + 2] = vertices[i].z; } - + // Mesh texcoords array for (int i = 0; i < mesh.vertexCount; i++) { mesh.texcoords[2*i] = texcoords[i].x; mesh.texcoords[2*i + 1] = texcoords[i].y; } - + // Mesh normals array for (int i = 0; i < mesh.vertexCount; i++) { @@ -881,22 +881,22 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) mesh.normals[3*i + 1] = normals[i].y; mesh.normals[3*i + 2] = normals[i].z; } - + // Mesh indices array initialization for (int i = 0; i < mesh.triangleCount*3; i++) mesh.indices[i] = triangles[i]; - + free(vertices); free(normals); free(texcoords); free(triangles); - + #else // Use par_shapes library to generate plane mesh par_shapes_mesh *plane = par_shapes_create_plane(resX, resZ); // No normals/texcoords generated!!! par_shapes_scale(plane, width, length, 1.0f); par_shapes_rotate(plane, -PI/2.0f, (float[]){ 1, 0, 0 }); par_shapes_translate(plane, -width/2, 0.0f, length/2); - + mesh.vertices = (float *)malloc(plane->ntriangles*3*3*sizeof(float)); mesh.texcoords = (float *)malloc(plane->ntriangles*3*2*sizeof(float)); mesh.normals = (float *)malloc(plane->ntriangles*3*3*sizeof(float)); @@ -909,11 +909,11 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) mesh.vertices[k*3] = plane->points[plane->triangles[k]*3]; mesh.vertices[k*3 + 1] = plane->points[plane->triangles[k]*3 + 1]; mesh.vertices[k*3 + 2] = plane->points[plane->triangles[k]*3 + 2]; - + mesh.normals[k*3] = plane->normals[plane->triangles[k]*3]; mesh.normals[k*3 + 1] = plane->normals[plane->triangles[k]*3 + 1]; mesh.normals[k*3 + 2] = plane->normals[plane->triangles[k]*3 + 2]; - + mesh.texcoords[k*2] = plane->tcoords[plane->triangles[k]*2]; mesh.texcoords[k*2 + 1] = plane->tcoords[plane->triangles[k]*2 + 1]; } @@ -922,7 +922,7 @@ Mesh GenMeshPlane(float width, float length, int resX, int resZ) #endif // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -960,7 +960,7 @@ Mesh GenMeshCube(float width, float height, float length) -width/2, height/2, length/2, -width/2, height/2, -length/2 }; - + float texcoords[] = { 0.0f, 0.0f, 1.0f, 0.0f, @@ -987,7 +987,7 @@ Mesh GenMeshCube(float width, float height, float length) 1.0f, 1.0f, 0.0f, 1.0f }; - + float normals[] = { 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, @@ -1017,15 +1017,15 @@ Mesh GenMeshCube(float width, float height, float length) mesh.vertices = (float *)malloc(24*3*sizeof(float)); memcpy(mesh.vertices, vertices, 24*3*sizeof(float)); - + mesh.texcoords = (float *)malloc(24*2*sizeof(float)); memcpy(mesh.texcoords, texcoords, 24*2*sizeof(float)); - + mesh.normals = (float *)malloc(24*3*sizeof(float)); memcpy(mesh.normals, normals, 24*3*sizeof(float)); - + mesh.indices = (unsigned short *)malloc(36*sizeof(unsigned short)); - + int k = 0; // Indices can be initialized right now @@ -1040,10 +1040,10 @@ Mesh GenMeshCube(float width, float height, float length) k++; } - + mesh.vertexCount = 24; mesh.triangleCount = 12; - + #else // Use par_shapes library to generate cube mesh /* // Platonic solids: @@ -1057,11 +1057,11 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron // NOTE: No normals/texcoords generated by default par_shapes_mesh *cube = par_shapes_create_cube(); cube->tcoords = PAR_MALLOC(float, 2*cube->npoints); - for (int i = 0; i < 2*cube->npoints; i++) cube->tcoords[i] = 0.0f; + for (int i = 0; i < 2*cube->npoints; i++) cube->tcoords[i] = 0.0f; par_shapes_scale(cube, width, height, length); par_shapes_translate(cube, -width/2, 0.0f, -length/2); par_shapes_compute_normals(cube); - + mesh.vertices = (float *)malloc(cube->ntriangles*3*3*sizeof(float)); mesh.texcoords = (float *)malloc(cube->ntriangles*3*2*sizeof(float)); mesh.normals = (float *)malloc(cube->ntriangles*3*3*sizeof(float)); @@ -1074,11 +1074,11 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron mesh.vertices[k*3] = cube->points[cube->triangles[k]*3]; mesh.vertices[k*3 + 1] = cube->points[cube->triangles[k]*3 + 1]; mesh.vertices[k*3 + 2] = cube->points[cube->triangles[k]*3 + 2]; - + mesh.normals[k*3] = cube->normals[cube->triangles[k]*3]; mesh.normals[k*3 + 1] = cube->normals[cube->triangles[k]*3 + 1]; mesh.normals[k*3 + 2] = cube->normals[cube->triangles[k]*3 + 2]; - + mesh.texcoords[k*2] = cube->tcoords[cube->triangles[k]*2]; mesh.texcoords[k*2 + 1] = cube->tcoords[cube->triangles[k]*2 + 1]; } @@ -1087,7 +1087,7 @@ par_shapes_mesh* par_shapes_create_icosahedron(); // 20 sides polyhedron #endif // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -1099,8 +1099,8 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices) par_shapes_mesh *sphere = par_shapes_create_parametric_sphere(slices, rings); par_shapes_scale(sphere, radius, radius, radius); - // NOTE: Soft normals are computed internally - + // NOTE: Soft normals are computed internally + mesh.vertices = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); mesh.texcoords = (float *)malloc(sphere->ntriangles*3*2*sizeof(float)); mesh.normals = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); @@ -1113,19 +1113,19 @@ RLAPI Mesh GenMeshSphere(float radius, int rings, int slices) mesh.vertices[k*3] = sphere->points[sphere->triangles[k]*3]; mesh.vertices[k*3 + 1] = sphere->points[sphere->triangles[k]*3 + 1]; mesh.vertices[k*3 + 2] = sphere->points[sphere->triangles[k]*3 + 2]; - + mesh.normals[k*3] = sphere->normals[sphere->triangles[k]*3]; mesh.normals[k*3 + 1] = sphere->normals[sphere->triangles[k]*3 + 1]; mesh.normals[k*3 + 2] = sphere->normals[sphere->triangles[k]*3 + 2]; - + mesh.texcoords[k*2] = sphere->tcoords[sphere->triangles[k]*2]; mesh.texcoords[k*2 + 1] = sphere->tcoords[sphere->triangles[k]*2 + 1]; } par_shapes_free_mesh(sphere); - + // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -1137,8 +1137,8 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices) par_shapes_mesh *sphere = par_shapes_create_hemisphere(slices, rings); par_shapes_scale(sphere, radius, radius, radius); - // NOTE: Soft normals are computed internally - + // NOTE: Soft normals are computed internally + mesh.vertices = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); mesh.texcoords = (float *)malloc(sphere->ntriangles*3*2*sizeof(float)); mesh.normals = (float *)malloc(sphere->ntriangles*3*3*sizeof(float)); @@ -1151,19 +1151,19 @@ RLAPI Mesh GenMeshHemiSphere(float radius, int rings, int slices) mesh.vertices[k*3] = sphere->points[sphere->triangles[k]*3]; mesh.vertices[k*3 + 1] = sphere->points[sphere->triangles[k]*3 + 1]; mesh.vertices[k*3 + 2] = sphere->points[sphere->triangles[k]*3 + 2]; - + mesh.normals[k*3] = sphere->normals[sphere->triangles[k]*3]; mesh.normals[k*3 + 1] = sphere->normals[sphere->triangles[k]*3 + 1]; mesh.normals[k*3 + 2] = sphere->normals[sphere->triangles[k]*3 + 2]; - + mesh.texcoords[k*2] = sphere->tcoords[sphere->triangles[k]*2]; mesh.texcoords[k*2 + 1] = sphere->tcoords[sphere->triangles[k]*2 + 1]; } par_shapes_free_mesh(sphere); - + // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -1175,7 +1175,7 @@ Mesh GenMeshCylinder(float radius, float height, int slices) // Instance a cylinder that sits on the Z=0 plane using the given tessellation // levels across the UV domain. Think of "slices" like a number of pizza - // slices, and "stacks" like a number of stacked rings. + // slices, and "stacks" like a number of stacked rings. // Height and radius are both 1.0, but they can easily be changed with par_shapes_scale par_shapes_mesh *cylinder = par_shapes_create_cylinder(slices, 8); par_shapes_scale(cylinder, radius, radius, height); @@ -1187,16 +1187,16 @@ Mesh GenMeshCylinder(float radius, float height, int slices) for (int i = 0; i < 2*capTop->npoints; i++) capTop->tcoords[i] = 0.0f; par_shapes_rotate(capTop, -PI/2.0f, (float[]){ 1, 0, 0 }); par_shapes_translate(capTop, 0, height, 0); - + // Generate an orientable disk shape (bottom cap) par_shapes_mesh *capBottom = par_shapes_create_disk(radius, slices, (float[]){ 0, 0, 0 }, (float[]){ 0, 0, -1 }); capBottom->tcoords = PAR_MALLOC(float, 2*capBottom->npoints); for (int i = 0; i < 2*capBottom->npoints; i++) capBottom->tcoords[i] = 0.95f; par_shapes_rotate(capBottom, PI/2.0f, (float[]){ 1, 0, 0 }); - + par_shapes_merge_and_free(cylinder, capTop); par_shapes_merge_and_free(cylinder, capBottom); - + mesh.vertices = (float *)malloc(cylinder->ntriangles*3*3*sizeof(float)); mesh.texcoords = (float *)malloc(cylinder->ntriangles*3*2*sizeof(float)); mesh.normals = (float *)malloc(cylinder->ntriangles*3*3*sizeof(float)); @@ -1209,19 +1209,19 @@ Mesh GenMeshCylinder(float radius, float height, int slices) mesh.vertices[k*3] = cylinder->points[cylinder->triangles[k]*3]; mesh.vertices[k*3 + 1] = cylinder->points[cylinder->triangles[k]*3 + 1]; mesh.vertices[k*3 + 2] = cylinder->points[cylinder->triangles[k]*3 + 2]; - + mesh.normals[k*3] = cylinder->normals[cylinder->triangles[k]*3]; mesh.normals[k*3 + 1] = cylinder->normals[cylinder->triangles[k]*3 + 1]; mesh.normals[k*3 + 2] = cylinder->normals[cylinder->triangles[k]*3 + 2]; - + mesh.texcoords[k*2] = cylinder->tcoords[cylinder->triangles[k]*2]; mesh.texcoords[k*2 + 1] = cylinder->tcoords[cylinder->triangles[k]*2 + 1]; } par_shapes_free_mesh(cylinder); - + // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -1233,7 +1233,7 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides) if (radius > 1.0f) radius = 1.0f; else if (radius < 0.1f) radius = 0.1f; - + // Create a donut that sits on the Z=0 plane with the specified inner radius // The outer radius can be controlled with par_shapes_scale par_shapes_mesh *torus = par_shapes_create_torus(radSeg, sides, radius); @@ -1251,19 +1251,19 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides) mesh.vertices[k*3] = torus->points[torus->triangles[k]*3]; mesh.vertices[k*3 + 1] = torus->points[torus->triangles[k]*3 + 1]; mesh.vertices[k*3 + 2] = torus->points[torus->triangles[k]*3 + 2]; - + mesh.normals[k*3] = torus->normals[torus->triangles[k]*3]; mesh.normals[k*3 + 1] = torus->normals[torus->triangles[k]*3 + 1]; mesh.normals[k*3 + 2] = torus->normals[torus->triangles[k]*3 + 2]; - + mesh.texcoords[k*2] = torus->tcoords[torus->triangles[k]*2]; mesh.texcoords[k*2 + 1] = torus->tcoords[torus->triangles[k]*2 + 1]; } par_shapes_free_mesh(torus); - + // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -1272,7 +1272,7 @@ Mesh GenMeshTorus(float radius, float size, int radSeg, int sides) Mesh GenMeshKnot(float radius, float size, int radSeg, int sides) { Mesh mesh = { 0 }; - + if (radius > 3.0f) radius = 3.0f; else if (radius < 0.5f) radius = 0.5f; @@ -1291,19 +1291,19 @@ Mesh GenMeshKnot(float radius, float size, int radSeg, int sides) mesh.vertices[k*3] = knot->points[knot->triangles[k]*3]; mesh.vertices[k*3 + 1] = knot->points[knot->triangles[k]*3 + 1]; mesh.vertices[k*3 + 2] = knot->points[knot->triangles[k]*3 + 2]; - + mesh.normals[k*3] = knot->normals[knot->triangles[k]*3]; mesh.normals[k*3 + 1] = knot->normals[knot->triangles[k]*3 + 1]; mesh.normals[k*3 + 2] = knot->normals[knot->triangles[k]*3 + 2]; - + mesh.texcoords[k*2] = knot->tcoords[knot->triangles[k]*2]; mesh.texcoords[k*2 + 1] = knot->tcoords[knot->triangles[k]*2 + 1]; } par_shapes_free_mesh(knot); - + // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -1411,7 +1411,7 @@ Mesh GenMeshHeightmap(Image heightmap, Vector3 size) } free(pixels); - + // Upload vertex data to GPU (static mesh) rlLoadMesh(&mesh, false); @@ -1771,9 +1771,9 @@ Mesh GenMeshCubicmap(Image cubicmap, Vector3 cubeSize) free(mapTexcoords); free(cubicmapPixels); // Free image pixel data - + // Upload vertex data to GPU (static mesh) - rlLoadMesh(&mesh, false); + rlLoadMesh(&mesh, false); return mesh; } @@ -1821,7 +1821,7 @@ void UnloadMaterial(Material material) // Unload loaded texture maps (avoid unloading default texture, managed by raylib) for (int i = 0; i < MAX_MATERIAL_MAPS; i++) { - if (material.maps[i].texture.id != GetTextureDefault().id) rlDeleteTextures(material.maps[i].texture.id); + if (material.maps[i].texture.id != GetTextureDefault().id) rlDeleteTextures(material.maps[i].texture.id); } } @@ -1842,7 +1842,7 @@ void DrawModelEx(Model model, Vector3 position, Vector3 rotationAxis, float rota Matrix matScale = MatrixScale(scale.x, scale.y, scale.z); Matrix matRotation = MatrixRotate(rotationAxis, rotationAngle*DEG2RAD); Matrix matTranslation = MatrixTranslate(position.x, position.y, position.z); - + Matrix matTransform = MatrixMultiply(MatrixMultiply(matScale, matRotation), matTranslation); // Combine model transformation matrix (model.transform) with matrix generated by function parameters (matTransform) @@ -2037,7 +2037,7 @@ bool CheckCollisionRaySphereEx(Ray ray, Vector3 spherePosition, float sphereRadi if (distance < sphereRadius) collisionDistance = vector + sqrtf(d); else collisionDistance = vector - sqrtf(d); - + // Calculate collision point Vector3 cPoint = Vector3Add(ray.position, Vector3Scale(ray.direction, collisionDistance)); @@ -2097,7 +2097,7 @@ RayHitInfo GetCollisionRayModel(Ray ray, Model *model) b = vertdata[i*3 + 1]; c = vertdata[i*3 + 2]; } - + a = Vector3Transform(a, model->transform); b = Vector3Transform(b, model->transform); c = Vector3Transform(c, model->transform); @@ -2231,7 +2231,7 @@ void MeshTangents(Mesh *mesh) { if (mesh->tangents == NULL) mesh->tangents = (float *)malloc(mesh->vertexCount*4*sizeof(float)); else TraceLog(LOG_WARNING, "Mesh tangents already exist"); - + Vector3 *tan1 = (Vector3 *)malloc(mesh->vertexCount*sizeof(Vector3)); Vector3 *tan2 = (Vector3 *)malloc(mesh->vertexCount*sizeof(Vector3)); @@ -2264,7 +2264,7 @@ void MeshTangents(Mesh *mesh) Vector3 sdir = { (t2*x1 - t1*x2)*r, (t2*y1 - t1*y2)*r, (t2*z1 - t1*z2)*r }; Vector3 tdir = { (s1*x2 - s2*x1)*r, (s1*y2 - s2*y1)*r, (s1*z2 - s2*z1)*r }; - + tan1[i + 0] = sdir; tan1[i + 1] = sdir; tan1[i + 2] = sdir; @@ -2296,10 +2296,10 @@ void MeshTangents(Mesh *mesh) mesh->tangents[i*4 + 3] = (Vector3DotProduct(Vector3CrossProduct(normal, tangent), tan2[i]) < 0.0f) ? -1.0f : 1.0f; #endif } - + free(tan1); free(tan2); - + TraceLog(LOG_INFO, "Tangents computed for mesh"); } @@ -2311,7 +2311,7 @@ void MeshBinormals(Mesh *mesh) Vector3 normal = { mesh->normals[i*3 + 0], mesh->normals[i*3 + 1], mesh->normals[i*3 + 2] }; Vector3 tangent = { mesh->tangents[i*4 + 0], mesh->tangents[i*4 + 1], mesh->tangents[i*4 + 2] }; float tangentW = mesh->tangents[i*4 + 3]; - + // TODO: Register computed binormal in mesh->binormal ? // Vector3 binormal = Vector3Multiply(Vector3CrossProduct(normal, tangent), tangentW); } @@ -2740,11 +2740,11 @@ static Material LoadMTL(const char *fileName) static Mesh LoadIQM(const char *fileName) { Mesh mesh = { 0 }; - + // TODO: Load IQM file - + return mesh; -} +} #endif #if defined(SUPPORT_FILEFORMAT_GLTF) @@ -2752,10 +2752,10 @@ static Mesh LoadIQM(const char *fileName) static Mesh LoadGLTF(const char *fileName) { Mesh mesh = { 0 }; - + // glTF file loading FILE *gltfFile = fopen(fileName, "rb"); - + if (gltfFile == NULL) { TraceLog(LOG_WARNING, "[%s] glTF file could not be opened", fileName); @@ -2768,31 +2768,31 @@ static Mesh LoadGLTF(const char *fileName) void *buffer = malloc(size); fread(buffer, size, 1, gltfFile); - + fclose(gltfFile); // glTF data loading cgltf_options options = {0}; cgltf_data data; cgltf_result result = cgltf_parse(&options, buffer, size, &data); - + free(buffer); - + if (result == cgltf_result_success) { printf("Type: %u\n", data.file_type); printf("Version: %d\n", data.version); printf("Meshes: %lu\n", data.meshes_count); - + // TODO: Process glTF data and map to mesh - + // NOTE: data.buffers[] and data.images[] should be loaded // using buffers[n].uri and images[n].uri... or use cgltf_load_buffers(&options, data, fileName); - + cgltf_free(&data); } else TraceLog(LOG_WARNING, "[%s] glTF data could not be loaded", fileName); - return mesh; + return mesh; } #endif diff --git a/src/raudio.c b/src/raudio.c index b19c7d86..e1c9fd48 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -1245,7 +1245,7 @@ Music LoadMusicStream(const char *fileName) void UnloadMusicStream(Music music) { if (music == NULL) return; - + CloseAudioStream(music->stream); #if defined(SUPPORT_FILEFORMAT_OGG) @@ -1311,7 +1311,7 @@ void ResumeMusicStream(Music music) void StopMusicStream(Music music) { if (music == NULL) return; - + StopAudioStream(music->stream); // Restart music context @@ -1343,7 +1343,7 @@ void StopMusicStream(Music music) void UpdateMusicStream(Music music) { if (music == NULL) return; - + bool streamEnding = false; unsigned int subBufferSizeInFrames = ((AudioBuffer *)music->stream.audioBuffer)->bufferSizeInFrames/2; @@ -1393,16 +1393,16 @@ void UpdateMusicStream(Music music) } break; #endif #if defined(SUPPORT_FILEFORMAT_MOD) - case MUSIC_MODULE_MOD: + case MUSIC_MODULE_MOD: { // NOTE: 3rd parameter (nbsample) specify the number of stereo 16bits samples you want, so sampleCount/2 - jar_mod_fillbuffer(&music->ctxMod, (short *)pcm, samplesCount/2, 0); + jar_mod_fillbuffer(&music->ctxMod, (short *)pcm, samplesCount/2, 0); } break; #endif default: break; } - + UpdateAudioStream(music->stream, pcm, samplesCount); if ((music->ctxType == MUSIC_MODULE_XM) || (music->ctxType == MUSIC_MODULE_MOD)) { @@ -1475,7 +1475,7 @@ void SetMusicLoopCount(Music music, int count) float GetMusicTimeLength(Music music) { float totalSeconds = 0.0f; - + if (music != NULL) totalSeconds = (float)music->totalSamples/(music->stream.sampleRate*music->stream.channels); return totalSeconds; diff --git a/src/rlgl.h b/src/rlgl.h index f2762637..c9f15385 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -356,7 +356,7 @@ typedef unsigned char byte; LOC_MAP_PREFILTER, LOC_MAP_BRDF } ShaderLocationIndex; - + // Shader uniform data types typedef enum { UNIFORM_FLOAT = 0, @@ -993,14 +993,14 @@ void rlPushMatrix(void) // Pop lattest inserted matrix from stack void rlPopMatrix(void) -{ +{ if (stackCounter > 0) { Matrix mat = stack[stackCounter - 1]; *currentMatrix = mat; stackCounter--; } - + if ((stackCounter == 0) && (currentMatrixMode == RL_MODELVIEW)) { currentMatrix = &modelview; @@ -1141,7 +1141,7 @@ void rlEnd(void) // Make sure vertexCount is the same for vertices, texcoords, colors and normals // NOTE: In OpenGL 1.1, one glColor call can be made for all the subsequent glVertex calls - + // Make sure colors count match vertex count if (vertexData[currentBuffer].vCounter != vertexData[currentBuffer].cCounter) { @@ -1156,7 +1156,7 @@ void rlEnd(void) vertexData[currentBuffer].cCounter++; } } - + // Make sure texcoords count match vertex count if (vertexData[currentBuffer].vCounter != vertexData[currentBuffer].tcCounter) { @@ -1194,10 +1194,10 @@ void rlEnd(void) void rlVertex3f(float x, float y, float z) { Vector3 vec = { x, y, z }; - + // Transform provided vector if required if (useTransformMatrix) vec = Vector3Transform(vec, transformMatrix); - + // Verify that MAX_BATCH_ELEMENTS limit not reached if (vertexData[currentBuffer].vCounter < (MAX_BATCH_ELEMENTS*4)) { @@ -1499,7 +1499,7 @@ void rlglInit(int width, int height) //for (int i = 0; i < numComp; i++) TraceLog(LOG_INFO, "Supported compressed format: 0x%x", format[i]); // NOTE: We don't need that much data on screen... right now... - + // TODO: Automatize extensions loading using rlLoadExtensions() and GLAD // Actually, when rlglInit() is called in InitWindow() in core.c, // OpenGL required extensions have already been loaded (PLATFORM_DESKTOP) @@ -1512,7 +1512,7 @@ void rlglInit(int width, int height) // NOTE: On OpenGL 3.3 VAO and NPOT are supported by default vaoSupported = true; - + // Multiple texture extensions supported by default texNPOTSupported = true; texFloatSupported = true; @@ -1585,11 +1585,11 @@ void rlglInit(int width, int height) // Check texture float support if (strcmp(extList[i], (const char *)"GL_OES_texture_float") == 0) texFloatSupported = true; - + // Check depth texture support if ((strcmp(extList[i], (const char *)"GL_OES_depth_texture") == 0) || (strcmp(extList[i], (const char *)"GL_WEBGL_depth_texture") == 0)) texDepthSupported = true; - + if (strcmp(extList[i], (const char *)"GL_OES_depth24") == 0) maxDepthBits = 24; if (strcmp(extList[i], (const char *)"GL_OES_depth32") == 0) maxDepthBits = 32; #endif @@ -1648,8 +1648,8 @@ void rlglInit(int width, int height) if (debugMarkerSupported) TraceLog(LOG_INFO, "[EXTENSION] Debug Marker supported"); - - + + // Initialize buffers, default shaders and default textures //---------------------------------------------------------- @@ -1666,7 +1666,7 @@ void rlglInit(int width, int height) // Init default vertex arrays buffers LoadBuffersDefault(); - + // Init transformations matrix accumulator transformMatrix = MatrixIdentity(); @@ -1995,9 +1995,9 @@ unsigned int rlLoadTextureDepth(int width, int height, int bits, bool useRenderB { unsigned int id = 0; unsigned int glInternalFormat = GL_DEPTH_COMPONENT16; - + if ((bits != 16) && (bits != 24) && (bits != 32)) bits = 16; - + if (bits == 24) { #if defined(GRAPHICS_API_OPENGL_33) @@ -2006,7 +2006,7 @@ unsigned int rlLoadTextureDepth(int width, int height, int bits, bool useRenderB if (maxDepthBits >= 24) glInternalFormat = GL_DEPTH_COMPONENT24_OES; #endif } - + if (bits == 32) { #if defined(GRAPHICS_API_OPENGL_33) @@ -2021,7 +2021,7 @@ unsigned int rlLoadTextureDepth(int width, int height, int bits, bool useRenderB glGenTextures(1, &id); glBindTexture(GL_TEXTURE_2D, id); glTexImage2D(GL_TEXTURE_2D, 0, glInternalFormat, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, NULL); - + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -2036,10 +2036,10 @@ unsigned int rlLoadTextureDepth(int width, int height, int bits, bool useRenderB glGenRenderbuffers(1, &id); glBindRenderbuffer(GL_RENDERBUFFER, id); glRenderbufferStorage(GL_RENDERBUFFER, glInternalFormat, width, height); - + glBindRenderbuffer(GL_RENDERBUFFER, 0); } - + return id; } @@ -2053,7 +2053,7 @@ unsigned int rlLoadTextureCubemap(void *data, int size, int format) glGenTextures(1, &cubemapId); glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapId); - + unsigned int glInternalFormat, glFormat, glType; rlGetGlTextureFormats(format, &glInternalFormat, &glFormat, &glType); @@ -2084,7 +2084,7 @@ unsigned int rlLoadTextureCubemap(void *data, int size, int format) #endif } } - + // Set cubemap texture sampling parameters glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR); @@ -2178,14 +2178,14 @@ void rlUnloadTexture(unsigned int id) RenderTexture2D rlLoadRenderTexture(int width, int height, int format, int depthBits, bool useDepthTexture) { RenderTexture2D target = { 0 }; - + if (useDepthTexture && texDepthSupported) target.depthTexture = true; -#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Create the framebuffer object glGenFramebuffers(1, &target.id); glBindFramebuffer(GL_FRAMEBUFFER, target.id); - + // Create fbo color texture attachment //----------------------------------------------------------------------------------------------------- if ((format != -1) && (format < COMPRESSED_DXT1_RGB)) @@ -2198,7 +2198,7 @@ RenderTexture2D rlLoadRenderTexture(int width, int height, int format, int depth target.texture.mipmaps = 1; } //----------------------------------------------------------------------------------------------------- - + // Create fbo depth renderbuffer/texture //----------------------------------------------------------------------------------------------------- if (depthBits > 0) @@ -2210,7 +2210,7 @@ RenderTexture2D rlLoadRenderTexture(int width, int height, int format, int depth target.depth.mipmaps = 1; } //----------------------------------------------------------------------------------------------------- - + // Attach color texture and depth renderbuffer to FBO //----------------------------------------------------------------------------------------------------- rlRenderTextureAttach(target, target.texture.id, 0); // COLOR attachment @@ -2235,12 +2235,12 @@ void rlRenderTextureAttach(RenderTexture2D target, unsigned int id, int attachTy glBindFramebuffer(GL_FRAMEBUFFER, target.id); if (attachType == 0) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, id, 0); - else if (attachType == 1) + else if (attachType == 1) { if (target.depthTexture) glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, id, 0); else glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, id); } - + glBindFramebuffer(GL_FRAMEBUFFER, 0); } @@ -2248,7 +2248,7 @@ void rlRenderTextureAttach(RenderTexture2D target, unsigned int id, int attachTy bool rlRenderTextureComplete(RenderTexture target) { glBindFramebuffer(GL_FRAMEBUFFER, target.id); - + GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); if (status != GL_FRAMEBUFFER_COMPLETE) @@ -2264,9 +2264,9 @@ bool rlRenderTextureComplete(RenderTexture target) default: break; } } - + glBindFramebuffer(GL_FRAMEBUFFER, 0); - + return (status == GL_FRAMEBUFFER_COMPLETE); } @@ -2349,7 +2349,7 @@ void rlLoadMesh(Mesh *mesh, bool dynamic) TraceLog(LOG_WARNING, "Trying to re-load an already loaded mesh"); return; } - + mesh->vaoId = 0; // Vertex Array Object mesh->vboId[0] = 0; // Vertex positions VBO mesh->vboId[1] = 0; // Vertex texcoords VBO @@ -2766,7 +2766,7 @@ unsigned char *rlReadScreenPixels(int width, int height) for (int x = 0; x < (width*4); x++) { imgData[((height - 1) - y)*width*4 + x] = screenData[(y*width*4) + x]; // Flip line - + // Set alpha component value to 255 (no trasparent image retrieval) // NOTE: Alpha value has already been applied to RGB in framebuffer, we don't need it! if (((x + 1)%4) == 0) imgData[((height - 1) - y)*width*4 + x] = 255; @@ -2822,7 +2822,7 @@ void *rlReadTexturePixels(Texture2D texture) // We are using Option 1, just need to care for texture format on retrieval // NOTE: This behaviour could be conditioned by graphic driver... RenderTexture2D fbo = rlLoadRenderTexture(texture.width, texture.height, UNCOMPRESSED_R8G8B8A8, 16, false); - + glBindFramebuffer(GL_FRAMEBUFFER, fbo.id); glBindTexture(GL_TEXTURE_2D, 0); @@ -2836,7 +2836,7 @@ void *rlReadTexturePixels(Texture2D texture) // Get OpenGL internal formats and data type from our texture format unsigned int glInternalFormat, glFormat, glType; rlGetGlTextureFormats(texture.format, &glInternalFormat, &glFormat, &glType); - + // NOTE: We read data as RGBA because FBO texture is configured as RGBA, despite binding a RGB texture... glReadPixels(0, 0, texture.width, texture.height, glFormat, glType, pixels); @@ -3064,7 +3064,7 @@ void SetShaderValueV(Shader shader, int uniformLoc, const void *value, int unifo case UNIFORM_SAMPLER2D: glUniform1iv(uniformLoc, count, (int *)value); break; default: TraceLog(LOG_WARNING, "Shader uniform could not be set data type not recognized"); } - + //glUseProgram(0); // Avoid reseting current shader program, in case other uniforms are set #endif } @@ -3143,7 +3143,7 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) // NOTE: Faces are stored as 32 bit floating point values glGenTextures(1, &cubemap.id); glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap.id); - for (unsigned int i = 0; i < 6; i++) + for (unsigned int i = 0; i < 6; i++) { #if defined(GRAPHICS_API_OPENGL_33) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB32F, size, size, 0, GL_RGB, GL_FLOAT, NULL); @@ -3151,7 +3151,7 @@ Texture2D GenTextureCubemap(Shader shader, Texture2D skyHDR, int size) if (texFloatSupported) glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, size, size, 0, GL_RGB, GL_FLOAT, NULL); #endif } - + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); #if defined(GRAPHICS_API_OPENGL_33) @@ -3231,7 +3231,7 @@ Texture2D GenTextureIrradiance(Shader shader, Texture2D cubemap, int size) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL); } - + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); @@ -3309,7 +3309,7 @@ Texture2D GenTexturePrefilter(Shader shader, Texture2D cubemap, int size) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB16F, size, size, 0, GL_RGB, GL_FLOAT, NULL); } - + glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE); @@ -3417,7 +3417,7 @@ Texture2D GenTextureBRDF(Shader shader, int size) // Unbind framebuffer and textures glBindFramebuffer(GL_FRAMEBUFFER, 0); - + // Unload framebuffer but keep color texture glDeleteRenderbuffers(1, &rbo); glDeleteFramebuffers(1, &fbo); @@ -3464,7 +3464,7 @@ void EndBlendMode(void) void BeginScissorMode(int x, int y, int width, int height) { rlglDraw(); // Force drawing elements - + glEnable(GL_SCISSOR_TEST); glScissor(x, screenHeight - (y + height), width, height); } @@ -3473,7 +3473,7 @@ void BeginScissorMode(int x, int y, int width, int height) void EndScissorMode(void) { rlglDraw(); // Force drawing elements - + glDisable(GL_SCISSOR_TEST); } @@ -4050,7 +4050,7 @@ static void LoadBuffersDefault(void) glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(short)*6*MAX_BATCH_ELEMENTS, vertexData[i].indices, GL_STATIC_DRAW); #endif } - + TraceLog(LOG_INFO, "Internal buffers uploaded successfully (GPU)"); // Unbind the current VAO @@ -4073,7 +4073,7 @@ static void UpdateBuffersDefault(void) glBindBuffer(GL_ARRAY_BUFFER, vertexData[currentBuffer].vboId[0]); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*3*vertexData[currentBuffer].vCounter, vertexData[currentBuffer].vertices); //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*MAX_BATCH_ELEMENTS, vertexData[currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer - + // Texture coordinates buffer glBindBuffer(GL_ARRAY_BUFFER, vertexData[currentBuffer].vboId[1]); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(float)*2*vertexData[currentBuffer].vCounter, vertexData[currentBuffer].texcoords); @@ -4083,13 +4083,13 @@ static void UpdateBuffersDefault(void) glBindBuffer(GL_ARRAY_BUFFER, vertexData[currentBuffer].vboId[2]); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(unsigned char)*4*vertexData[currentBuffer].vCounter, vertexData[currentBuffer].colors); //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*MAX_BATCH_ELEMENTS, vertexData[currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer - + // NOTE: glMapBuffer() causes sync issue. - // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job. + // If GPU is working with this buffer, glMapBuffer() will wait(stall) until GPU to finish its job. // To avoid waiting (idle), you can call first glBufferData() with NULL pointer before glMapBuffer(). // If you do that, the previous data in PBO will be discarded and glMapBuffer() returns a new // allocated pointer immediately even if GPU is still working with the previous data. - + // Another option: map the buffer object into client's memory // Probably this code could be moved somewhere else... // vertexData[currentBuffer].vertices = (float *)glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); @@ -4135,7 +4135,7 @@ static void DrawBuffersDefault(void) glUniform1i(currentShader.locs[LOC_MAP_DIFFUSE], 0); // NOTE: Additional map textures not considered for default buffers drawing - + int vertexOffset = 0; if (vaoSupported) glBindVertexArray(vertexData[currentBuffer].vaoId); @@ -4160,7 +4160,7 @@ static void DrawBuffersDefault(void) } glActiveTexture(GL_TEXTURE0); - + for (int i = 0; i < drawsCounter; i++) { glBindTexture(GL_TEXTURE_2D, draws[i].textureId); @@ -4170,7 +4170,7 @@ static void DrawBuffersDefault(void) { #if defined(GRAPHICS_API_OPENGL_33) // We need to define the number of indices to be processed: quadsCount*6 - // NOTE: The final parameter tells the GPU the offset in bytes from the + // NOTE: The final parameter tells the GPU the offset in bytes from the // start of the index buffer to the location of the first index to process glDrawElements(GL_TRIANGLES, draws[i].vertexCount/4*6, GL_UNSIGNED_INT, (GLvoid *)(sizeof(GLuint)*vertexOffset/4*6)); #elif defined(GRAPHICS_API_OPENGL_ES2) @@ -4216,7 +4216,7 @@ static void DrawBuffersDefault(void) } drawsCounter = 1; - + // Change to next buffer in the list currentBuffer++; if (currentBuffer >= MAX_BATCH_BUFFERING) currentBuffer = 0; @@ -4369,14 +4369,14 @@ static void GenDrawCube(void) static VrStereoConfig SetStereoConfig(VrDeviceInfo hmd, Shader distortion) { VrStereoConfig config = { 0 }; - + // Initialize framebuffer and textures for stereo rendering // NOTE: Screen size should match HMD aspect ratio config.stereoFbo = rlLoadRenderTexture(screenWidth, screenHeight, UNCOMPRESSED_R8G8B8A8, 24, false); - + // Assign distortion shader config.distortionShader = distortion; - + // Compute aspect ratio float aspect = ((float)hmd.hResolution*0.5f)/(float)hmd.vResolution; @@ -4442,7 +4442,7 @@ static VrStereoConfig SetStereoConfig(VrDeviceInfo hmd, Shader distortion) SetShaderValue(config.distortionShader, GetShaderLocation(config.distortionShader, "hmdWarpParam"), hmd.lensDistortionValues, UNIFORM_VEC4); SetShaderValue(config.distortionShader, GetShaderLocation(config.distortionShader, "chromaAbParam"), hmd.chromaAbCorrection, UNIFORM_VEC4); #endif - + return config; } diff --git a/src/shapes.c b/src/shapes.c index 8976c81c..87bb573c 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -143,7 +143,7 @@ void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color) rlTexCoord2f(recTexShapes.x/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height); rlVertex2f(0.0f, thick); - + rlTexCoord2f((recTexShapes.x + recTexShapes.width)/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height); rlVertex2f(d, thick); @@ -187,7 +187,7 @@ void DrawCircle(int centerX, int centerY, float radius, Color color) void DrawCircleSector(Vector2 center, float radius, int startAngle, int endAngle, Color color) { #define CIRCLE_SECTOR_LENGTH 10 - + #if defined(SUPPORT_QUADS_DRAW_MODE) if (rlCheckBufferLimit(4*((360/CIRCLE_SECTOR_LENGTH)/2))) rlglDraw(); @@ -307,10 +307,10 @@ void DrawRectanglePro(Rectangle rec, Vector2 origin, float rotation, Color color rlTexCoord2f(recTexShapes.x/texShapes.width, recTexShapes.y/texShapes.height); rlVertex2f(0.0f, 0.0f); - + rlTexCoord2f(recTexShapes.x/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height); rlVertex2f(0.0f, rec.height); - + rlTexCoord2f((recTexShapes.x + recTexShapes.width)/texShapes.width, (recTexShapes.y + recTexShapes.height)/texShapes.height); rlVertex2f(rec.width, rec.height); diff --git a/src/text.c b/src/text.c index 17f6d9dd..9a7d690d 100644 --- a/src/text.c +++ b/src/text.c @@ -790,14 +790,14 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f } // Draw text using font inside rectangle limits -void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint) +void DrawTextRec(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint) { DrawTextRecEx(font, text, rec, fontSize, spacing, wordWrap, tint, 0, 0, WHITE, WHITE); } // Draw text using font inside rectangle limits with support for text selection -void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, - int selectStart, int selectLength, Color selectText, Color selectBack) +void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, float spacing, bool wordWrap, Color tint, + int selectStart, int selectLength, Color selectText, Color selectBack) { int length = strlen(text); int textOffsetX = 0; // Offset between characters @@ -813,12 +813,12 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f int state = wordWrap? MEASURE_STATE : DRAW_STATE; int startLine = -1; // Index where to begin drawing (where a line begins) int endLine = -1; // Index where to stop drawing (where a line ends) - + for (int i = 0; i < length; i++) { int glyphWidth = 0; letter = (unsigned char)text[i]; - + if (letter != '\n') { if ((unsigned char)text[i] == 0xc2) // UTF-8 encoding identification HACK! @@ -836,41 +836,41 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f i++; } else index = GetGlyphIndex(font, (unsigned char)text[i]); - - glyphWidth = (font.chars[index].advanceX == 0)? + + glyphWidth = (font.chars[index].advanceX == 0)? (int)(font.chars[index].rec.width*scaleFactor + spacing): (int)(font.chars[index].advanceX*scaleFactor + spacing); } - + // NOTE: When wordWrap is ON we first measure how much of the text we can draw - // before going outside of the `rec` container. We store this info inside + // before going outside of the `rec` container. We store this info inside // `startLine` and `endLine` then we change states, draw the text between those two // variables then change states again and again recursively until the end of the text // (or until we get outside of the container). - // When wordWrap is OFF we don't need the measure state so we go to the drawing - // state immediately and begin drawing on the next line before we can get outside + // When wordWrap is OFF we don't need the measure state so we go to the drawing + // state immediately and begin drawing on the next line before we can get outside // the container. - if (state == MEASURE_STATE) + if (state == MEASURE_STATE) { if ((letter == ' ') || (letter == '\t') || (letter == '\n')) endLine = i; - - if ((textOffsetX + glyphWidth + 1) >= rec.width) + + if ((textOffsetX + glyphWidth + 1) >= rec.width) { endLine = (endLine < 1) ? i : endLine; if (i == endLine) endLine -= 1; if ((startLine + 1) == endLine) endLine = i - 1; state = !state; - } - else if ((i + 1) == length) + } + else if ((i + 1) == length) { endLine = i; state = !state; } - else if (letter == '\n') + else if (letter == '\n') { state = !state; } - + if (state == DRAW_STATE) { textOffsetX = 0; @@ -878,8 +878,8 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f glyphWidth = 0; } - } - else + } + else { if (letter == '\n') { @@ -888,17 +888,17 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor); textOffsetX = 0; } - } - else + } + else { if (!wordWrap && ((textOffsetX + glyphWidth + 1) >= rec.width)) { textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor); textOffsetX = 0; } - + if ((textOffsetY + (int)((font.baseSize + font.baseSize/2)*scaleFactor)) > rec.height) break; - + //draw selected bool isGlyphSelected = false; if ((selectStart >= 0) && (i >= selectStart) && (i < (selectStart + selectLength))) @@ -907,7 +907,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f DrawRectangleRec(strec, selectBack); isGlyphSelected = true; } - + //draw glyph if ((letter != ' ') && (letter != '\t')) { @@ -915,12 +915,12 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f (Rectangle){ rec.x + textOffsetX + font.chars[index].offsetX*scaleFactor, rec.y + textOffsetY + font.chars[index].offsetY*scaleFactor, font.chars[index].rec.width*scaleFactor, - font.chars[index].rec.height*scaleFactor }, (Vector2){ 0, 0 }, 0.0f, + font.chars[index].rec.height*scaleFactor }, (Vector2){ 0, 0 }, 0.0f, (!isGlyphSelected) ? tint : selectText); } } - - if (wordWrap && (i == endLine)) + + if (wordWrap && (i == endLine)) { textOffsetY += (int)((font.baseSize + font.baseSize/2)*scaleFactor); textOffsetX = 0; @@ -930,7 +930,7 @@ void DrawTextRecEx(Font font, const char *text, Rectangle rec, float fontSize, f state = !state; } } - + textOffsetX += glyphWidth; } } @@ -968,11 +968,11 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing unsigned char letter = 0; // Current character int index = 0; // Index position in sprite font - + for (int i = 0; i < len; i++) { lenCounter++; - + if (text[i] != '\n') { if ((unsigned char)text[i] == 0xc2) // UTF-8 encoding identification @@ -1105,7 +1105,7 @@ const char *TextSubtext(const char *text, int position, int length) const char *TextReplace(char *text, const char *replace, const char *by) { char *result; - + char *insertPoint; // Next insert point char *temp; // Temp pointer int replaceLen; // Replace string length of (the string to remove) @@ -1163,7 +1163,7 @@ const char *TextInsert(const char *text, const char *insert, int position) for (int i = 0; i < position; i++) result[i] = text[i]; for (int i = position; i < insertLen + position; i++) result[i] = insert[i]; for (int i = (insertLen + position); i < (textLen + insertLen); i++) result[i] = text[i]; - + result[textLen + insertLen] = '\0'; // Make sure text string is valid! return result; @@ -1174,7 +1174,7 @@ const char *TextInsert(const char *text, const char *insert, int position) const char *TextJoin(const char **textList, int count, const char *delimiter) { // TODO: Make sure joined text could fit inside MAX_TEXT_BUFFER_LENGTH - + static char text[MAX_TEXT_BUFFER_LENGTH] = { 0 }; memset(text, 0, MAX_TEXT_BUFFER_LENGTH); @@ -1197,9 +1197,9 @@ const char **TextSplit(const char *text, char delimiter, int *count) // all used memory is static... it has some limitations: // 1. Maximum number of possible split strings is set by MAX_SUBSTRINGS_COUNT // 2. Maximum size of text to split is MAX_TEXT_BUFFER_LENGTH - + #define MAX_SUBSTRINGS_COUNT 64 - + static const char *result[MAX_SUBSTRINGS_COUNT] = { NULL }; static char buffer[MAX_TEXT_BUFFER_LENGTH] = { 0 }; memset(buffer, 0, MAX_TEXT_BUFFER_LENGTH); @@ -1208,7 +1208,7 @@ const char **TextSplit(const char *text, char delimiter, int *count) int counter = 1; // Count how many substrings we have on text and point to every one - for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) + for (int i = 0; i < MAX_TEXT_BUFFER_LENGTH; i++) { buffer[i] = text[i]; if (buffer[i] == '\0') break; @@ -1217,7 +1217,7 @@ const char **TextSplit(const char *text, char delimiter, int *count) buffer[i] = '\0'; // Set an end of string at this point result[counter] = buffer + i + 1; counter++; - + if (counter == MAX_SUBSTRINGS_COUNT) break; } } @@ -1239,11 +1239,11 @@ void TextAppend(char *text, const char *append, int *position) int TextFindIndex(const char *text, const char *find) { int position = -1; - + char *ptr = strstr(text, find); - + if (ptr != NULL) position = ptr - text; - + return position; } @@ -1314,10 +1314,10 @@ int TextToInteger(const char *text) { if ((text[i] > 47) && (text[i] < 58)) result += ((int)text[i] - 48)*units; else { result = -1; break; } - + units *= 10; } - + return result; } diff --git a/src/textures.c b/src/textures.c index 75624fdb..48b89384 100644 --- a/src/textures.c +++ b/src/textures.c @@ -2529,7 +2529,7 @@ void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Rectangl { Rectangle source = { offset.x*texture.width, offset.y*texture.height, tiling.x*texture.width, tiling.y*texture.height }; Vector2 origin = { 0.0f, 0.0f }; - + DrawTexturePro(texture, source, quad, origin, 0.0f, tint); } @@ -3198,7 +3198,7 @@ static int SaveKTX(Image image, const char *fileName) //unsigned char id[12] = { 0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A }; const char ktxIdentifier[12] = { 0xAB, 'K', 'T', 'X', ' ', '1', '1', 0xBB, '\r', '\n', 0x1A, '\n' }; - + // Get the image header strncpy(ktxHeader.id, ktxIdentifier, 12); // KTX 1.1 signature ktxHeader.endianness = 0;