From 18af18479f1b2b08c0c7c0d2ed2662cb60bcb793 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 27 Aug 2021 18:49:03 +0200 Subject: [PATCH 01/59] REVIEWED: ExportWaveAsCode() --- src/raudio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/raudio.c b/src/raudio.c index f48888a98..706efedd0 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -967,12 +967,13 @@ bool ExportWaveAsCode(Wave wave, const char *fileName) bytesCount += sprintf(txtData + bytesCount, "// Wave data information\n"); bytesCount += sprintf(txtData + bytesCount, "#define %s_FRAME_COUNT %u\n", varFileName, wave.frameCount); - bytesCount += sprintf(txtData + bytesCount, "#define %s_SAMPLE_COUNT %u\n", varFileName, wave.frameCount*wave.channels); + bytesCount += sprintf(txtData + bytesCount, "#define %s_FRAME_COUNT %u\n", varFileName, wave.frameCount); bytesCount += sprintf(txtData + bytesCount, "#define %s_SAMPLE_RATE %u\n", varFileName, wave.sampleRate); bytesCount += sprintf(txtData + bytesCount, "#define %s_SAMPLE_SIZE %u\n", varFileName, wave.sampleSize); bytesCount += sprintf(txtData + bytesCount, "#define %s_CHANNELS %u\n\n", varFileName, wave.channels); // Write byte data as hexadecimal text + // NOTE: Frame data exported is interlaced: Frame01[Sample-Channel01, Sample-Channel02, ...], Frame02[], Frame03[] bytesCount += sprintf(txtData + bytesCount, "static unsigned char %s_DATA[%i] = { ", varFileName, waveDataSize); for (int i = 0; i < waveDataSize - 1; i++) bytesCount += sprintf(txtData + bytesCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)wave.data)[i]); bytesCount += sprintf(txtData + bytesCount, "0x%x };\n", ((unsigned char *)wave.data)[waveDataSize - 1]); From 936199d8de3fecf3ff57bab4d5e35ed9c5ffa54b Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 27 Aug 2021 18:50:02 +0200 Subject: [PATCH 02/59] Review dates --- src/raudio.c | 2 +- src/textures.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/raudio.c b/src/raudio.c index 706efedd0..771fa50db 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -952,7 +952,7 @@ bool ExportWaveAsCode(Wave wave, const char *fileName) bytesCount += sprintf(txtData + bytesCount, "// more info and bugs-report: github.com/raysan5/raylib //\n"); bytesCount += sprintf(txtData + bytesCount, "// feedback and support: ray[at]raylib.com //\n"); bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// Copyright (c) 2018 Ramon Santamaria (@raysan5) //\n"); + bytesCount += sprintf(txtData + bytesCount, "// Copyright (c) 2018-2021 Ramon Santamaria (@raysan5) //\n"); bytesCount += sprintf(txtData + bytesCount, "// //\n"); bytesCount += sprintf(txtData + bytesCount, "//////////////////////////////////////////////////////////////////////////////////\n\n"); diff --git a/src/textures.c b/src/textures.c index ff55eedf7..8435d2677 100644 --- a/src/textures.c +++ b/src/textures.c @@ -528,7 +528,7 @@ bool ExportImageAsCode(Image image, const char *fileName) bytesCount += sprintf(txtData + bytesCount, "// more info and bugs-report: github.com/raysan5/raylib //\n"); bytesCount += sprintf(txtData + bytesCount, "// feedback and support: ray[at]raylib.com //\n"); bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// Copyright (c) 2020 Ramon Santamaria (@raysan5) //\n"); + bytesCount += sprintf(txtData + bytesCount, "// Copyright (c) 2018-2021 Ramon Santamaria (@raysan5) //\n"); bytesCount += sprintf(txtData + bytesCount, "// //\n"); bytesCount += sprintf(txtData + bytesCount, "////////////////////////////////////////////////////////////////////////////////////////\n\n"); From 66c6ec44650d56cbe0bfb5c60d84b7225fccc1e5 Mon Sep 17 00:00:00 2001 From: Hussein Sarea <54902350+Ho011@users.noreply.github.com> Date: Sat, 28 Aug 2021 10:57:13 +0300 Subject: [PATCH 03/59] Add pyraylib (#1961) --- BINDINGS.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BINDINGS.md b/BINDINGS.md index 2311406b4..163692620 100644 --- a/BINDINGS.md +++ b/BINDINGS.md @@ -45,9 +45,10 @@ Some people ported raylib to other languages in form of bindings or wrappers to | raylib-ruby-ffi | 2.0 | [Ruby](https://www.ruby-lang.org/en/) | https://github.com/D3nX/raylib-ruby-ffi | | raylib-ruby | 2.6 | [Ruby](https://www.ruby-lang.org/en/) | https://github.com/a0/raylib-ruby | | raylib-mruby | 2.5-dev | [mruby](https://github.com/mruby/mruby) | https://github.com/lihaochen910/raylib-mruby | +| pyraylib | 3.7 | [Python](https://www.python.org/) | https://github.com/Ho011/pyraylib | | raylib-py | 2.0 | [Python](https://www.python.org/) | https://github.com/overdev/raylib-py | | raylib-python-cffi | 3.7 | [Python](https://www.python.org/) | https://github.com/electronstudio/raylib-python-cffi | -| raylib-py-ctbg | 2.6 | [Python](https://www.python.org/) | https://github.com/overdev/raylib-py-ctbg | +| raylib-py-ctbg | 2.6 | [Python](https://www.python.org/) | https://github.com/overdev/raylib-py-ctbg | | jaylib | 3.7 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | https://github.com/electronstudio/jaylib/ | | raylib-java | 2.0 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | https://github.com/XoanaIO/raylib-java | | raylib-j | 3.5 | [Java](https://en.wikipedia.org/wiki/Java_(programming_language)) | https://github.com/CreedVI/Raylib-J | From d98e61c6ebf2bca919e1d1a0e8da6164f888d04a Mon Sep 17 00:00:00 2001 From: raysan5 Date: Sat, 28 Aug 2021 12:01:16 +0200 Subject: [PATCH 04/59] Minor format tweaks --- src/models.c | 36 ++++++++++++++++++------------------ src/raudio.c | 2 +- src/textures.c | 2 +- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/models.c b/src/models.c index 411538d1d..a464c9fdf 100644 --- a/src/models.c +++ b/src/models.c @@ -123,13 +123,13 @@ static ModelAnimation *LoadIQMModelAnimations(const char *fileName, int *animCou static Model LoadGLTF(const char *fileName); // Load GLTF mesh data static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCount); // Load GLTF animation data static void LoadGLTFMaterial(Model *model, const char *fileName, const cgltf_data *data); -static void LoadGLTFMesh(cgltf_data *data, cgltf_mesh* mesh, Model* outModel, Matrix currentTransform, int* primitiveIndex, const char *fileName); -static void LoadGLTFNode(cgltf_data *data, cgltf_node* node, Model* outModel, Matrix currentTransform, int* primitiveIndex, const char *fileName); +static void LoadGLTFMesh(cgltf_data *data, cgltf_mesh *mesh, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName); +static void LoadGLTFNode(cgltf_data *data, cgltf_node *node, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName); static void InitGLTFBones(Model *model, const cgltf_data *data); static void BindGLTFPrimitiveToBones(Model *model, const cgltf_data *data, int primitiveIndex); -static void GetGLTFPrimitiveCount(cgltf_node* node, int* outCount); -static bool ReadGLTFValue(cgltf_accessor* acc, unsigned int index, void *variable); -static void *ReadGLTFValuesAs(cgltf_accessor* acc, cgltf_component_type type, bool adjustOnDownCasting); +static void GetGLTFPrimitiveCount(cgltf_node *node, int *outCount); +static bool ReadGLTFValue(cgltf_accessor *acc, unsigned int index, void *variable); +static void *ReadGLTFValuesAs(cgltf_accessor *acc, cgltf_component_type type, bool adjustOnDownCasting); #endif //---------------------------------------------------------------------------------- @@ -4891,7 +4891,7 @@ static Model LoadGLTF(const char *fileName) return model; } -static void InitGLTFBones(Model* model, const cgltf_data* data) +static void InitGLTFBones(Model *model, const cgltf_data *data) { for (unsigned int j = 0; j < data->nodes_count; j++) { @@ -4914,7 +4914,7 @@ static void InitGLTFBones(Model* model, const cgltf_data* data) } { - bool* completedBones = RL_CALLOC(model->boneCount, sizeof(bool)); + bool *completedBones = RL_CALLOC(model->boneCount, sizeof(bool)); int numberCompletedBones = 0; while (numberCompletedBones < model->boneCount) @@ -5022,7 +5022,7 @@ static void LoadGLTFMaterial(Model *model, const char *fileName, const cgltf_dat model->materials[model->materialCount - 1] = LoadMaterialDefault(); } -static void BindGLTFPrimitiveToBones(Model* model, const cgltf_data* data, int primitiveIndex) +static void BindGLTFPrimitiveToBones(Model *model, const cgltf_data *data, int primitiveIndex) { for (unsigned int nodeId = 0; nodeId < data->nodes_count; nodeId++) { @@ -5030,12 +5030,12 @@ static void BindGLTFPrimitiveToBones(Model* model, const cgltf_data* data, int p { if (model->meshes[primitiveIndex].boneIds == NULL) { - model->meshes[primitiveIndex].boneIds = RL_CALLOC(4*model->meshes[primitiveIndex].vertexCount, sizeof(int)); - model->meshes[primitiveIndex].boneWeights = RL_CALLOC(4*model->meshes[primitiveIndex].vertexCount, sizeof(float)); + model->meshes[primitiveIndex].boneIds = RL_CALLOC(model->meshes[primitiveIndex].vertexCount*4, sizeof(int)); + model->meshes[primitiveIndex].boneWeights = RL_CALLOC(model->meshes[primitiveIndex].vertexCount*4, sizeof(float)); - for (int b = 0; b < 4*model->meshes[primitiveIndex].vertexCount; b++) + for (int b = 0; b < model->meshes[primitiveIndex].vertexCount*4; b++) { - if (b % 4 == 0) + if (b%4 == 0) { model->meshes[primitiveIndex].boneIds[b] = nodeId; model->meshes[primitiveIndex].boneWeights[b] = 1.0f; @@ -5112,7 +5112,7 @@ static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCo // Getting the max animation time to consider for animation duration for (unsigned int i = 0; i < animation->channels_count; i++) { - cgltf_animation_channel* channel = animation->channels + i; + cgltf_animation_channel *channel = animation->channels + i; int frameCounts = (int)channel->sampler->input->count; float lastFrameTime = 0.0f; @@ -5159,8 +5159,8 @@ static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCo // for each single transformation type on single bone for (unsigned int channelId = 0; channelId < animation->channels_count; channelId++) { - cgltf_animation_channel* channel = animation->channels + channelId; - cgltf_animation_sampler* sampler = channel->sampler; + cgltf_animation_channel *channel = animation->channels + channelId; + cgltf_animation_sampler *sampler = channel->sampler; int boneId = (int)(channel->target_node - data->nodes); @@ -5318,7 +5318,7 @@ static ModelAnimation *LoadGLTFModelAnimations(const char *fileName, int *animCo return animations; } -void LoadGLTFMesh(cgltf_data* data, cgltf_mesh* mesh, Model* outModel, Matrix currentTransform, int* primitiveIndex, const char *fileName) +void LoadGLTFMesh(cgltf_data *data, cgltf_mesh *mesh, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName) { for (unsigned int p = 0; p < mesh->primitives_count; p++) { @@ -5443,7 +5443,7 @@ void LoadGLTFMesh(cgltf_data* data, cgltf_mesh* mesh, Model* outModel, Matrix cu } } -void LoadGLTFNode(cgltf_data* data, cgltf_node* node, Model* outModel, Matrix currentTransform, int* primitiveIndex, const char *fileName) +void LoadGLTFNode(cgltf_data *data, cgltf_node *node, Model *outModel, Matrix currentTransform, int *primitiveIndex, const char *fileName) { Matrix nodeTransform = { node->matrix[0], node->matrix[4], node->matrix[8], node->matrix[12], @@ -5458,7 +5458,7 @@ void LoadGLTFNode(cgltf_data* data, cgltf_node* node, Model* outModel, Matrix cu for (unsigned int i = 0; i < node->children_count; i++) LoadGLTFNode(data, node->children[i], outModel, currentTransform, primitiveIndex, fileName); } -static void GetGLTFPrimitiveCount(cgltf_node* node, int* outCount) +static void GetGLTFPrimitiveCount(cgltf_node *node, int *outCount) { if (node->mesh != NULL) *outCount += node->mesh->primitives_count; diff --git a/src/raudio.c b/src/raudio.c index 771fa50db..78bbcd810 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -942,7 +942,7 @@ bool ExportWaveAsCode(Wave wave, const char *fileName) // NOTE: Text data buffer size is estimated considering wave data size in bytes // and requiring 6 char bytes for every byte: "0x00, " - char *txtData = (char *)RL_CALLOC(6*waveDataSize + 2000, sizeof(char)); + char *txtData = (char *)RL_CALLOC(waveDataSize*6 + 2000, sizeof(char)); int bytesCount = 0; bytesCount += sprintf(txtData + bytesCount, "\n//////////////////////////////////////////////////////////////////////////////////\n"); diff --git a/src/textures.c b/src/textures.c index 8435d2677..92ed19fad 100644 --- a/src/textures.c +++ b/src/textures.c @@ -518,7 +518,7 @@ bool ExportImageAsCode(Image image, const char *fileName) // NOTE: Text data buffer size is estimated considering image data size in bytes // and requiring 6 char bytes for every byte: "0x00, " - char *txtData = (char *)RL_CALLOC(6*dataSize + 2000, sizeof(char)); + char *txtData = (char *)RL_CALLOC(dataSize*6 + 2000, sizeof(char)); int bytesCount = 0; bytesCount += sprintf(txtData + bytesCount, "////////////////////////////////////////////////////////////////////////////////////////\n"); From 68bcfa119243e716eaf00ffe521d0358c084b74f Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 28 Aug 2021 22:54:47 +0200 Subject: [PATCH 05/59] Minor tweak --- examples/textures/textures_image_loading.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/textures/textures_image_loading.c b/examples/textures/textures_image_loading.c index 527ed35ae..8babce693 100644 --- a/examples/textures/textures_image_loading.c +++ b/examples/textures/textures_image_loading.c @@ -26,8 +26,8 @@ int main(void) Image image = LoadImage("resources/raylib_logo.png"); // Loaded in CPU memory (RAM) Texture2D texture = LoadTextureFromImage(image); // Image converted to texture, GPU memory (VRAM) - UnloadImage(image); // Once image has been converted to texture and uploaded to VRAM, it can be unloaded from RAM + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //--------------------------------------------------------------------------------------- From e8fa7ceb79613188c495b80a332875a1afdab8cf Mon Sep 17 00:00:00 2001 From: Tristan Schulz Date: Wed, 1 Sep 2021 21:29:20 +0200 Subject: [PATCH 06/59] [models] Fixed counting loop for face amount per material (#1967) --- src/models.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/models.c b/src/models.c index a464c9fdf..b175dd94d 100644 --- a/src/models.c +++ b/src/models.c @@ -3491,6 +3491,11 @@ RayCollision GetRayCollisionQuad(Ray ray, Vector3 p1, Vector3 p2, Vector3 p3, Ve //---------------------------------------------------------------------------------- #if defined(SUPPORT_FILEFORMAT_OBJ) // Load OBJ mesh data +// +// Keep the following information in mind when reading this +// - A mesh is created for every material present in the obj file +// - the model.meshCount is therefore the materialCount returned from tinyobj +// - the mesh is automatically triangulated by tinyobj static Model LoadOBJ(const char *fileName) { Model model = { 0 }; @@ -3542,15 +3547,12 @@ static Model LoadOBJ(const char *fileName) // Count the faces for each material int *matFaces = RL_CALLOC(materialCount, sizeof(int)); - for (unsigned int mi = 0; mi < meshCount; mi++) - { - for (unsigned int fi = 0; fi < meshes[mi].length; fi++) - { - int idx = attrib.material_ids[meshes[mi].face_offset + fi]; - if (idx == -1) idx = 0; // for no material face (which could be the whole model) - matFaces[idx]++; - } + for(int fi = 0; fi< attrib.num_faces; fi++){ + tinyobj_vertex_index_t face = attrib.faces[fi]; + int idx = attrib.material_ids[fi]; + matFaces[idx]++; } + //-------------------------------------- // Create the material meshes From a0f8682905fee1b65c903f1f46adff6e06ab6ae7 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 1 Sep 2021 23:09:30 +0200 Subject: [PATCH 07/59] REVIEWED: Count for consistency Following english rules, it should be singular name before Count. --- src/core.c | 46 +++++++++++------------ src/models.c | 71 ++++++++++++++++++----------------- src/raudio.c | 50 ++++++++++++------------- src/rlgl.h | 100 ++++++++++++++++++++++++------------------------- src/shapes.c | 24 ++++++------ src/textures.c | 66 ++++++++++++++++---------------- 6 files changed, 178 insertions(+), 179 deletions(-) diff --git a/src/core.c b/src/core.c index aff8cdd35..89b9874ac 100644 --- a/src/core.c +++ b/src/core.c @@ -385,7 +385,7 @@ typedef struct CoreData { Matrix screenScale; // Matrix to scale screen (framebuffer rendering) char **dropFilesPath; // Store dropped files paths as strings - int dropFilesCount; // Count dropped files strings + int dropFileCount; // Count dropped files strings } Window; #if defined(PLATFORM_ANDROID) @@ -411,7 +411,7 @@ typedef struct CoreData { int keyPressedQueue[MAX_KEY_PRESSED_QUEUE]; // Input keys queue int keyPressedQueueCount; // Input keys queue count - int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue + int charPressedQueue[MAX_CHAR_PRESSED_QUEUE]; // Input characters queue (unicode) int charPressedQueueCount; // Input characters queue count #if defined(PLATFORM_RPI) || defined(PLATFORM_DRM) @@ -481,14 +481,14 @@ typedef struct CoreData { static CoreData CORE = { 0 }; // Global CORE state context static char **dirFilesPath = NULL; // Store directory files paths as strings -static int dirFilesCount = 0; // Count directory files strings +static int dirFileCount = 0; // Count directory files strings #if defined(SUPPORT_SCREEN_CAPTURE) static int screenshotCounter = 0; // Screenshots counter #endif #if defined(SUPPORT_GIF_RECORDING) -static int gifFramesCounter = 0; // GIF frames counter +static int gifFrameCounter = 0; // GIF frames counter static bool gifRecording = false; // GIF recording state static MsfGifState gifState = { 0 }; // MSGIF context state #endif @@ -1926,10 +1926,10 @@ void EndDrawing(void) if (gifRecording) { #define GIF_RECORD_FRAMERATE 10 - gifFramesCounter++; + gifFrameCounter++; // NOTE: We record one gif frame every 10 game frames - if ((gifFramesCounter%GIF_RECORD_FRAMERATE) == 0) + if ((gifFrameCounter%GIF_RECORD_FRAMERATE) == 0) { // Get image data for the current frame (from backbuffer) // NOTE: This process is quite slow... :( @@ -1939,7 +1939,7 @@ void EndDrawing(void) RL_FREE(screenData); // Free image data } - if (((gifFramesCounter/15)%2) == 1) + if (((gifFrameCounter/15)%2) == 1) { DrawCircle(30, CORE.Window.screen.height - 20, 10, MAROON); DrawText("GIF RECORDING", 50, CORE.Window.screen.height - 25, 10, RED); @@ -1953,9 +1953,9 @@ void EndDrawing(void) // Draw record/play indicator if (eventsRecording) { - gifFramesCounter++; + gifFrameCounter++; - if (((gifFramesCounter/15)%2) == 1) + if (((gifFrameCounter/15)%2) == 1) { DrawCircle(30, CORE.Window.screen.height - 20, 10, MAROON); DrawText("EVENTS RECORDING", 50, CORE.Window.screen.height - 25, 10, RED); @@ -1965,9 +1965,9 @@ void EndDrawing(void) } else if (eventsPlaying) { - gifFramesCounter++; + gifFrameCounter++; - if (((gifFramesCounter/15)%2) == 1) + if (((gifFrameCounter/15)%2) == 1) { DrawCircle(30, CORE.Window.screen.height - 20, 10, LIME); DrawText("EVENTS PLAYING", 50, CORE.Window.screen.height - 25, 10, GREEN); @@ -2895,8 +2895,8 @@ char **GetDirectoryFiles(const char *dirPath, int *fileCount) } else TRACELOG(LOG_WARNING, "FILEIO: Failed to open requested directory"); // Maybe it's a file... - dirFilesCount = counter; - *fileCount = dirFilesCount; + dirFileCount = counter; + *fileCount = dirFileCount; return dirFilesPath; } @@ -2904,14 +2904,14 @@ char **GetDirectoryFiles(const char *dirPath, int *fileCount) // Clear directory files paths buffers void ClearDirectoryFiles(void) { - if (dirFilesCount > 0) + if (dirFileCount > 0) { for (int i = 0; i < MAX_DIRECTORY_FILES; i++) RL_FREE(dirFilesPath[i]); RL_FREE(dirFilesPath); } - dirFilesCount = 0; + dirFileCount = 0; } // Change working directory, returns true on success @@ -2927,27 +2927,27 @@ bool ChangeDirectory(const char *dir) // Check if a file has been dropped into window bool IsFileDropped(void) { - if (CORE.Window.dropFilesCount > 0) return true; + if (CORE.Window.dropFileCount > 0) return true; else return false; } // Get dropped files names char **GetDroppedFiles(int *count) { - *count = CORE.Window.dropFilesCount; + *count = CORE.Window.dropFileCount; return CORE.Window.dropFilesPath; } // Clear dropped files paths buffer void ClearDroppedFiles(void) { - if (CORE.Window.dropFilesCount > 0) + if (CORE.Window.dropFileCount > 0) { - for (int i = 0; i < CORE.Window.dropFilesCount; i++) RL_FREE(CORE.Window.dropFilesPath[i]); + for (int i = 0; i < CORE.Window.dropFileCount; i++) RL_FREE(CORE.Window.dropFilesPath[i]); RL_FREE(CORE.Window.dropFilesPath); - CORE.Window.dropFilesCount = 0; + CORE.Window.dropFileCount = 0; } } @@ -4922,7 +4922,7 @@ static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, i else { gifRecording = true; - gifFramesCounter = 0; + gifFrameCounter = 0; msf_gif_begin(&gifState, CORE.Window.screen.width, CORE.Window.screen.height); screenshotCounter++; @@ -5085,7 +5085,7 @@ static void WindowDropCallback(GLFWwindow *window, int count, const char **paths strcpy(CORE.Window.dropFilesPath[i], paths[i]); } - CORE.Window.dropFilesCount = count; + CORE.Window.dropFileCount = count; } #endif @@ -5145,7 +5145,7 @@ static void AndroidCommandCallback(struct android_app *app, int32_t cmd) /* if (assetsReloadRequired) { - for (int i = 0; i < assetsCount; i++) + for (int i = 0; i < assetCount; i++) { // TODO: Unload old asset if required diff --git a/src/models.c b/src/models.c index b175dd94d..b233cf2af 100644 --- a/src/models.c +++ b/src/models.c @@ -201,16 +201,16 @@ void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color) } // Draw a triangle strip defined by points -void DrawTriangleStrip3D(Vector3 *points, int pointsCount, Color color) +void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color) { - if (pointsCount >= 3) + if (pointCount >= 3) { - rlCheckRenderBatchLimit(3*(pointsCount - 2)); + rlCheckRenderBatchLimit(3*(pointCount - 2)); rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); - for (int i = 2; i < pointsCount; i++) + for (int i = 2; i < pointCount; i++) { if ((i%2) == 0) { @@ -1144,14 +1144,14 @@ void DrawMesh(Mesh mesh, Material material, Matrix transform) if (mesh.indices != NULL) rlEnableVertexBufferElement(mesh.vboId[6]); } - int eyesCount = 1; - if (rlIsStereoRenderEnabled()) eyesCount = 2; + int eyeCount = 1; + if (rlIsStereoRenderEnabled()) eyeCount = 2; - for (int eye = 0; eye < eyesCount; eye++) + for (int eye = 0; eye < eyeCount; eye++) { // Calculate model-view-projection matrix (MVP) Matrix matModelViewProjection = MatrixIdentity(); - if (eyesCount == 1) matModelViewProjection = MatrixMultiply(matModelView, matProjection); + if (eyeCount == 1) matModelViewProjection = MatrixMultiply(matModelView, matProjection); else { // Setup current eye viewport (half screen width) @@ -1359,14 +1359,14 @@ void DrawMeshInstanced(Mesh mesh, Material material, Matrix *transforms, int ins if (mesh.indices != NULL) rlEnableVertexBufferElement(mesh.vboId[6]); } - int eyesCount = 1; - if (rlIsStereoRenderEnabled()) eyesCount = 2; + int eyeCount = 1; + if (rlIsStereoRenderEnabled()) eyeCount = 2; - for (int eye = 0; eye < eyesCount; eye++) + for (int eye = 0; eye < eyeCount; eye++) { // Calculate model-view-projection matrix (MVP) Matrix matModelViewProjection = MatrixIdentity(); - if (eyesCount == 1) matModelViewProjection = MatrixMultiply(matModelView, matProjection); + if (eyeCount == 1) matModelViewProjection = MatrixMultiply(matModelView, matProjection); else { // Setup current eye viewport (half screen width) @@ -1448,43 +1448,43 @@ bool ExportMesh(Mesh mesh, const char *fileName) // NOTE: Text data buffer size is estimated considering mesh data size char *txtData = (char *)RL_CALLOC(dataSize + 2000, sizeof(char)); - int bytesCount = 0; - bytesCount += sprintf(txtData + bytesCount, "# //////////////////////////////////////////////////////////////////////////////////\n"); - bytesCount += sprintf(txtData + bytesCount, "# // //\n"); - bytesCount += sprintf(txtData + bytesCount, "# // rMeshOBJ exporter v1.0 - Mesh exported as triangle faces and not optimized //\n"); - bytesCount += sprintf(txtData + bytesCount, "# // //\n"); - bytesCount += sprintf(txtData + bytesCount, "# // more info and bugs-report: github.com/raysan5/raylib //\n"); - bytesCount += sprintf(txtData + bytesCount, "# // feedback and support: ray[at]raylib.com //\n"); - bytesCount += sprintf(txtData + bytesCount, "# // //\n"); - bytesCount += sprintf(txtData + bytesCount, "# // Copyright (c) 2018 Ramon Santamaria (@raysan5) //\n"); - bytesCount += sprintf(txtData + bytesCount, "# // //\n"); - bytesCount += sprintf(txtData + bytesCount, "# //////////////////////////////////////////////////////////////////////////////////\n\n"); - bytesCount += sprintf(txtData + bytesCount, "# Vertex Count: %i\n", mesh.vertexCount); - bytesCount += sprintf(txtData + bytesCount, "# Triangle Count: %i\n\n", mesh.triangleCount); + int byteCount = 0; + byteCount += sprintf(txtData + byteCount, "# //////////////////////////////////////////////////////////////////////////////////\n"); + byteCount += sprintf(txtData + byteCount, "# // //\n"); + byteCount += sprintf(txtData + byteCount, "# // rMeshOBJ exporter v1.0 - Mesh exported as triangle faces and not optimized //\n"); + byteCount += sprintf(txtData + byteCount, "# // //\n"); + byteCount += sprintf(txtData + byteCount, "# // more info and bugs-report: github.com/raysan5/raylib //\n"); + byteCount += sprintf(txtData + byteCount, "# // feedback and support: ray[at]raylib.com //\n"); + byteCount += sprintf(txtData + byteCount, "# // //\n"); + byteCount += sprintf(txtData + byteCount, "# // Copyright (c) 2018 Ramon Santamaria (@raysan5) //\n"); + byteCount += sprintf(txtData + byteCount, "# // //\n"); + byteCount += sprintf(txtData + byteCount, "# //////////////////////////////////////////////////////////////////////////////////\n\n"); + byteCount += sprintf(txtData + byteCount, "# Vertex Count: %i\n", mesh.vertexCount); + byteCount += sprintf(txtData + byteCount, "# Triangle Count: %i\n\n", mesh.triangleCount); - bytesCount += sprintf(txtData + bytesCount, "g mesh\n"); + byteCount += sprintf(txtData + byteCount, "g mesh\n"); for (int i = 0, v = 0; i < mesh.vertexCount; i++, v += 3) { - bytesCount += sprintf(txtData + bytesCount, "v %.2f %.2f %.2f\n", mesh.vertices[v], mesh.vertices[v + 1], mesh.vertices[v + 2]); + byteCount += sprintf(txtData + byteCount, "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) { - bytesCount += sprintf(txtData + bytesCount, "vt %.3f %.3f\n", mesh.texcoords[v], mesh.texcoords[v + 1]); + byteCount += sprintf(txtData + byteCount, "vt %.3f %.3f\n", mesh.texcoords[v], mesh.texcoords[v + 1]); } for (int i = 0, v = 0; i < mesh.vertexCount; i++, v += 3) { - bytesCount += sprintf(txtData + bytesCount, "vn %.3f %.3f %.3f\n", mesh.normals[v], mesh.normals[v + 1], mesh.normals[v + 2]); + byteCount += sprintf(txtData + byteCount, "vn %.3f %.3f %.3f\n", mesh.normals[v], mesh.normals[v + 1], mesh.normals[v + 2]); } for (int i = 0; i < mesh.triangleCount; i += 3) { - bytesCount += sprintf(txtData + bytesCount, "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); + byteCount += sprintf(txtData + byteCount, "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); } - bytesCount += sprintf(txtData + bytesCount, "\n"); + byteCount += sprintf(txtData + byteCount, "\n"); // NOTE: Text data length exported is determined by '\0' (NULL) character success = SaveFileText(fileName, txtData); @@ -3547,7 +3547,8 @@ static Model LoadOBJ(const char *fileName) // Count the faces for each material int *matFaces = RL_CALLOC(materialCount, sizeof(int)); - for(int fi = 0; fi< attrib.num_faces; fi++){ + for (int fi = 0; fi< attrib.num_faces; fi++) + { tinyobj_vertex_index_t face = attrib.faces[fi]; int idx = attrib.material_ids[fi]; matFaces[idx]++; @@ -4858,14 +4859,14 @@ static Model LoadGLTF(const char *fileName) if (data->scenes_count > 1) TRACELOG(LOG_INFO, "MODEL: [%s] Has multiple scenes but only the first one will be loaded", fileName); - int primitivesCount = 0; + int primitiveCount = 0; for (unsigned int i = 0; i < data->scene->nodes_count; i++) { - GetGLTFPrimitiveCount(data->scene->nodes[i], &primitivesCount); + GetGLTFPrimitiveCount(data->scene->nodes[i], &primitiveCount); } // Process glTF data and map to model - model.meshCount = primitivesCount; + model.meshCount = primitiveCount; model.meshes = RL_CALLOC(model.meshCount, sizeof(Mesh)); model.materialCount = (int)data->materials_count + 1; model.materials = RL_MALLOC(model.materialCount*sizeof(Material)); diff --git a/src/raudio.c b/src/raudio.c index 78bbcd810..5ed3de7c2 100644 --- a/src/raudio.c +++ b/src/raudio.c @@ -877,14 +877,14 @@ void UnloadSound(Sound sound) } // Update sound buffer with new data -void UpdateSound(Sound sound, const void *data, int samplesCount) +void UpdateSound(Sound sound, const void *data, int sampleCount) { if (sound.stream.buffer != NULL) { StopAudioBuffer(sound.stream.buffer); // TODO: May want to lock/unlock this since this data buffer is read at mixing time - memcpy(sound.stream.buffer->data, data, samplesCount*ma_get_bytes_per_frame(sound.stream.buffer->converter.config.formatIn, sound.stream.buffer->converter.config.channelsIn)); + memcpy(sound.stream.buffer->data, data, sampleCount*ma_get_bytes_per_frame(sound.stream.buffer->converter.config.formatIn, sound.stream.buffer->converter.config.channelsIn)); } } @@ -944,17 +944,17 @@ bool ExportWaveAsCode(Wave wave, const char *fileName) // and requiring 6 char bytes for every byte: "0x00, " char *txtData = (char *)RL_CALLOC(waveDataSize*6 + 2000, sizeof(char)); - int bytesCount = 0; - bytesCount += sprintf(txtData + bytesCount, "\n//////////////////////////////////////////////////////////////////////////////////\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// WaveAsCode exporter v1.0 - Wave data exported as an array of bytes //\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// more info and bugs-report: github.com/raysan5/raylib //\n"); - bytesCount += sprintf(txtData + bytesCount, "// feedback and support: ray[at]raylib.com //\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// Copyright (c) 2018-2021 Ramon Santamaria (@raysan5) //\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "//////////////////////////////////////////////////////////////////////////////////\n\n"); + int byteCount = 0; + byteCount += sprintf(txtData + byteCount, "\n//////////////////////////////////////////////////////////////////////////////////\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "// WaveAsCode exporter v1.0 - Wave data exported as an array of bytes //\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "// more info and bugs-report: github.com/raysan5/raylib //\n"); + byteCount += sprintf(txtData + byteCount, "// feedback and support: ray[at]raylib.com //\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "// Copyright (c) 2018-2021 Ramon Santamaria (@raysan5) //\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "//////////////////////////////////////////////////////////////////////////////////\n\n"); char varFileName[256] = { 0 }; #if !defined(RAUDIO_STANDALONE) @@ -965,18 +965,18 @@ bool ExportWaveAsCode(Wave wave, const char *fileName) strcpy(varFileName, fileName); #endif - bytesCount += sprintf(txtData + bytesCount, "// Wave data information\n"); - bytesCount += sprintf(txtData + bytesCount, "#define %s_FRAME_COUNT %u\n", varFileName, wave.frameCount); - bytesCount += sprintf(txtData + bytesCount, "#define %s_FRAME_COUNT %u\n", varFileName, wave.frameCount); - bytesCount += sprintf(txtData + bytesCount, "#define %s_SAMPLE_RATE %u\n", varFileName, wave.sampleRate); - bytesCount += sprintf(txtData + bytesCount, "#define %s_SAMPLE_SIZE %u\n", varFileName, wave.sampleSize); - bytesCount += sprintf(txtData + bytesCount, "#define %s_CHANNELS %u\n\n", varFileName, wave.channels); + byteCount += sprintf(txtData + byteCount, "// Wave data information\n"); + byteCount += sprintf(txtData + byteCount, "#define %s_FRAME_COUNT %u\n", varFileName, wave.frameCount); + byteCount += sprintf(txtData + byteCount, "#define %s_FRAME_COUNT %u\n", varFileName, wave.frameCount); + byteCount += sprintf(txtData + byteCount, "#define %s_SAMPLE_RATE %u\n", varFileName, wave.sampleRate); + byteCount += sprintf(txtData + byteCount, "#define %s_SAMPLE_SIZE %u\n", varFileName, wave.sampleSize); + byteCount += sprintf(txtData + byteCount, "#define %s_CHANNELS %u\n\n", varFileName, wave.channels); // Write byte data as hexadecimal text // NOTE: Frame data exported is interlaced: Frame01[Sample-Channel01, Sample-Channel02, ...], Frame02[], Frame03[] - bytesCount += sprintf(txtData + bytesCount, "static unsigned char %s_DATA[%i] = { ", varFileName, waveDataSize); - for (int i = 0; i < waveDataSize - 1; i++) bytesCount += sprintf(txtData + bytesCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)wave.data)[i]); - bytesCount += sprintf(txtData + bytesCount, "0x%x };\n", ((unsigned char *)wave.data)[waveDataSize - 1]); + byteCount += sprintf(txtData + byteCount, "static unsigned char %s_DATA[%i] = { ", varFileName, waveDataSize); + for (int i = 0; i < waveDataSize - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)wave.data)[i]); + byteCount += sprintf(txtData + byteCount, "0x%x };\n", ((unsigned char *)wave.data)[waveDataSize - 1]); // NOTE: Text data length exported is determined by '\0' (NULL) character success = SaveFileText(fileName, txtData); @@ -1505,9 +1505,7 @@ Music LoadMusicStreamFromMemory(const char *fileType, unsigned char *data, int d // Copy data to allocated memory for default UnloadMusicStream unsigned char *newData = (unsigned char *)RL_MALLOC(dataSize); int it = dataSize/sizeof(unsigned char); - for (int i = 0; i < it; i++){ - newData[i] = data[i]; - } + for (int i = 0; i < it; i++) newData[i] = data[i]; // Memory loaded version for jar_mod_load_file() if (dataSize && dataSize < 32*1024*1024) @@ -1716,7 +1714,7 @@ void UpdateMusicStream(Music music) #if defined(SUPPORT_FILEFORMAT_XM) case MUSIC_MODULE_XM: { - // NOTE: Internally we consider 2 channels generation, so samplesCount/2 + // NOTE: Internally we consider 2 channels generation, so sampleCount/2 if (AUDIO_DEVICE_FORMAT == ma_format_f32) jar_xm_generate_samples((jar_xm_context_t *)music.ctxData, (float *)pcm, frameCountToStream); else if (AUDIO_DEVICE_FORMAT == ma_format_s16) jar_xm_generate_samples_16bit((jar_xm_context_t *)music.ctxData, (short *)pcm, frameCountToStream); else if (AUDIO_DEVICE_FORMAT == ma_format_u8) jar_xm_generate_samples_8bit((jar_xm_context_t *)music.ctxData, (char *)pcm, frameCountToStream); diff --git a/src/rlgl.h b/src/rlgl.h index ce99c40e4..ea46c537e 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -279,7 +279,7 @@ typedef enum { // Dynamic vertex buffers (position + texcoords + colors + indices arrays) typedef struct rlVertexBuffer { - int elementsCount; // Number of elements in the buffer (QUADS) + int elementCount; // Number of elements in the buffer (QUADS) int vCounter; // Vertex position counter to process (and draw) from full buffer int tcCounter; // Vertex texcoord counter to process (and draw) from full buffer @@ -316,12 +316,12 @@ typedef struct rlDrawCall { // rlRenderBatch type typedef struct rlRenderBatch { - int buffersCount; // Number of vertex buffers (multi-buffering support) + int bufferCount; // Number of vertex buffers (multi-buffering support) int currentBuffer; // Current buffer tracking in case of multi-buffering rlVertexBuffer *vertexBuffer; // Dynamic buffer(s) for vertex data rlDrawCall *draws; // Draw calls array, depends on textureId - int drawsCounter; // Draw calls counter + int drawCounterer; // Draw calls counter float currentDepth; // Current depth value for next draw } rlRenderBatch; @@ -1210,34 +1210,34 @@ void rlBegin(int mode) { // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].mode != mode) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode != mode) { - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount > 0) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount > 0) { // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, // that way, following QUADS drawing will keep aligned with index processing // It implies adding some extra alignment vertex at the end of the draw, // those vertex are not processed but they are considered as an additional offset // for the next set of vertex to be drawn - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount%4); - else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount%4))); - else RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment = 0; + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4); + else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4))); + else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = 0; - if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment)) + if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment)) { - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; - RLGL.currentBatch->drawsCounter++; + RLGL.currentBatch->drawCounterer++; } } - if (RLGL.currentBatch->drawsCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); + if (RLGL.currentBatch->drawCounterer >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); - RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].mode = mode; - RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount = 0; - RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].textureId = RLGL.State.defaultTextureId; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode = mode; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount = 0; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].textureId = RLGL.State.defaultTextureId; } } @@ -1285,7 +1285,7 @@ void rlEnd(void) // Verify internal buffers limits // NOTE: This check is combined with usage of rlCheckRenderBatchLimit() if ((RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter) >= - (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementsCount*4 - 4)) + (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4 - 4)) { // WARNING: If we are between rlPushMatrix() and rlPopMatrix() and we need to force a rlDrawRenderBatch(), // we need to call rlPopMatrix() before to recover *RLGL.State.currentMatrix (RLGL.State.modelview) for the next forced draw call! @@ -1312,14 +1312,14 @@ void rlVertex3f(float x, float y, float z) } // Verify that current vertex buffer elements limit has not been reached - if (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter < (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementsCount*4)) + if (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter < (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4)) { RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter] = tx; RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter + 1] = ty; RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter + 2] = tz; RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter++; - RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount++; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount++; } else TRACELOG(RL_LOG_ERROR, "RLGL: Batch elements overflow"); } @@ -1390,7 +1390,7 @@ void rlSetTexture(unsigned int id) #else // NOTE: If quads batch limit is reached, we force a draw call and next batch starts if (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter >= - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementsCount*4) + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4) { rlDrawRenderBatch(RLGL.currentBatch); } @@ -1401,33 +1401,33 @@ void rlSetTexture(unsigned int id) #if defined(GRAPHICS_API_OPENGL_11) rlEnableTexture(id); #else - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].textureId != id) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].textureId != id) { - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount > 0) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount > 0) { // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, // that way, following QUADS drawing will keep aligned with index processing // It implies adding some extra alignment vertex at the end of the draw, // those vertex are not processed but they are considered as an additional offset // for the next set of vertex to be drawn - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount%4); - else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount%4))); - else RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment = 0; + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4); + else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4))); + else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = 0; - if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment)) + if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment)) { - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; - RLGL.currentBatch->drawsCounter++; + RLGL.currentBatch->drawCounterer++; } } - if (RLGL.currentBatch->drawsCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); + if (RLGL.currentBatch->drawCounterer >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); - RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].textureId = id; - RLGL.currentBatch->draws[RLGL.currentBatch->drawsCounter - 1].vertexCount = 0; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].textureId = id; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount = 0; } #endif } @@ -2169,7 +2169,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements) for (int i = 0; i < numBuffers; i++) { - batch.vertexBuffer[i].elementsCount = bufferElements; + batch.vertexBuffer[i].elementCount = bufferElements; batch.vertexBuffer[i].vertices = (float *)RL_MALLOC(bufferElements*3*4*sizeof(float)); // 3 float by vertex, 4 vertex by quad batch.vertexBuffer[i].texcoords = (float *)RL_MALLOC(bufferElements*2*4*sizeof(float)); // 2 float by texcoord, 4 texcoord by quad @@ -2274,8 +2274,8 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements) //batch.draws[i].RLGL.State.modelview = rlMatrixIdentity(); } - batch.buffersCount = numBuffers; // Record buffer count - batch.drawsCounter = 1; // Reset draws counter + batch.bufferCount = numBuffers; // Record buffer count + batch.drawCounterer = 1; // Reset draws counter batch.currentDepth = -1.0f; // Reset depth value //-------------------------------------------------------------------------------------------- #endif @@ -2297,7 +2297,7 @@ void rlUnloadRenderBatch(rlRenderBatch batch) glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); // Unload all vertex buffers data - for (int i = 0; i < batch.buffersCount; i++) + for (int i = 0; i < batch.bufferCount; i++) { // Delete VBOs from GPU (VRAM) glDeleteBuffers(1, &batch.vertexBuffer[i].vboId[0]); @@ -2338,17 +2338,17 @@ void rlDrawRenderBatch(rlRenderBatch *batch) // Vertex positions buffer glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[0]); glBufferSubData(GL_ARRAY_BUFFER, 0, batch->vertexBuffer[batch->currentBuffer].vCounter*3*sizeof(float), batch->vertexBuffer[batch->currentBuffer].vertices); - //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementsCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer + //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*3*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].vertices, GL_DYNAMIC_DRAW); // Update all buffer // Texture coordinates buffer glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[1]); glBufferSubData(GL_ARRAY_BUFFER, 0, batch->vertexBuffer[batch->currentBuffer].vCounter*2*sizeof(float), batch->vertexBuffer[batch->currentBuffer].texcoords); - //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementsCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer + //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*2*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->currentBuffer].texcoords, GL_DYNAMIC_DRAW); // Update all buffer // Colors buffer glBindBuffer(GL_ARRAY_BUFFER, batch->vertexBuffer[batch->currentBuffer].vboId[2]); glBufferSubData(GL_ARRAY_BUFFER, 0, batch->vertexBuffer[batch->currentBuffer].vCounter*4*sizeof(unsigned char), batch->vertexBuffer[batch->currentBuffer].colors); - //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementsCount, batch->vertexBuffer[batch->currentBuffer].colors, GL_DYNAMIC_DRAW); // Update all buffer + //glBufferData(GL_ARRAY_BUFFER, sizeof(float)*4*4*batch->vertexBuffer[batch->currentBuffer].elementCount, batch->vertexBuffer[batch->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. @@ -2375,12 +2375,12 @@ void rlDrawRenderBatch(rlRenderBatch *batch) Matrix matProjection = RLGL.State.projection; Matrix matModelView = RLGL.State.modelview; - int eyesCount = 1; - if (RLGL.State.stereoRender) eyesCount = 2; + int eyeCount = 1; + if (RLGL.State.stereoRender) eyeCount = 2; - for (int eye = 0; eye < eyesCount; eye++) + for (int eye = 0; eye < eyeCount; eye++) { - if (eyesCount == 2) + if (eyeCount == 2) { // Setup current eye viewport (half screen width) rlViewport(eye*RLGL.State.framebufferWidth/2, 0, RLGL.State.framebufferWidth/2, RLGL.State.framebufferHeight); @@ -2447,7 +2447,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch) // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls glActiveTexture(GL_TEXTURE0); - for (int i = 0, vertexOffset = 0; i < batch->drawsCounter; i++) + for (int i = 0, vertexOffset = 0; i < batch->drawCounterer; i++) { // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId); @@ -2456,7 +2456,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch) else { #if defined(GRAPHICS_API_OPENGL_33) - // We need to define the number of indices to be processed: quadsCount*6 + // We need to define the number of indices to be processed: elementCount*6 // 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, batch->draws[i].vertexCount/4*6, GL_UNSIGNED_INT, (GLvoid *)(vertexOffset/4*6*sizeof(GLuint))); @@ -2510,12 +2510,12 @@ void rlDrawRenderBatch(rlRenderBatch *batch) for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++) RLGL.State.activeTextureId[i] = 0; // Reset draws counter to one draw for the batch - batch->drawsCounter = 1; + batch->drawCounterer = 1; //------------------------------------------------------------------------------------------------------------ // Change to next buffer in the list (in case of multi-buffering) batch->currentBuffer++; - if (batch->currentBuffer >= batch->buffersCount) batch->currentBuffer = 0; + if (batch->currentBuffer >= batch->bufferCount) batch->currentBuffer = 0; #endif } @@ -2546,7 +2546,7 @@ bool rlCheckRenderBatchLimit(int vCount) #if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) if ((RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter + vCount) >= - (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementsCount*4)) + (RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].elementCount*4)) { overflow = true; rlDrawRenderBatch(RLGL.currentBatch); // NOTE: Stereo rendering is checked inside diff --git a/src/shapes.c b/src/shapes.c index 104aef0a7..86e7c97a2 100644 --- a/src/shapes.c +++ b/src/shapes.c @@ -190,16 +190,16 @@ void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, fl } // Draw lines sequence -void DrawLineStrip(Vector2 *points, int pointsCount, Color color) +void DrawLineStrip(Vector2 *points, int pointCount, Color color) { - if (pointsCount >= 2) + if (pointCount >= 2) { - rlCheckRenderBatchLimit(pointsCount); + rlCheckRenderBatchLimit(pointCount); rlBegin(RL_LINES); rlColor4ub(color.r, color.g, color.b, color.a); - for (int i = 0; i < pointsCount - 1; i++) + for (int i = 0; i < pointCount - 1; i++) { rlVertex2f(points[i].x, points[i].y); rlVertex2f(points[i + 1].x, points[i + 1].y); @@ -1318,17 +1318,17 @@ void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color) // Draw a triangle fan defined by points // NOTE: First vertex provided is the center, shared by all triangles // By default, following vertex should be provided in counter-clockwise order -void DrawTriangleFan(Vector2 *points, int pointsCount, Color color) +void DrawTriangleFan(Vector2 *points, int pointCount, Color color) { - if (pointsCount >= 3) + if (pointCount >= 3) { - rlCheckRenderBatchLimit((pointsCount - 2)*4); + rlCheckRenderBatchLimit((pointCount - 2)*4); rlSetTexture(texShapes.id); rlBegin(RL_QUADS); rlColor4ub(color.r, color.g, color.b, color.a); - for (int i = 1; i < pointsCount - 1; i++) + for (int i = 1; i < pointCount - 1; i++) { rlTexCoord2f(texShapesRec.x/texShapes.width, texShapesRec.y/texShapes.height); rlVertex2f(points[0].x, points[0].y); @@ -1349,16 +1349,16 @@ void DrawTriangleFan(Vector2 *points, int pointsCount, Color color) // Draw a triangle strip defined by points // NOTE: Every new vertex connects with previous two -void DrawTriangleStrip(Vector2 *points, int pointsCount, Color color) +void DrawTriangleStrip(Vector2 *points, int pointCount, Color color) { - if (pointsCount >= 3) + if (pointCount >= 3) { - rlCheckRenderBatchLimit(3*(pointsCount - 2)); + rlCheckRenderBatchLimit(3*(pointCount - 2)); rlBegin(RL_TRIANGLES); rlColor4ub(color.r, color.g, color.b, color.a); - for (int i = 2; i < pointsCount; i++) + for (int i = 2; i < pointCount; i++) { if ((i%2) == 0) { diff --git a/src/textures.c b/src/textures.c index 92ed19fad..41a0a077b 100644 --- a/src/textures.c +++ b/src/textures.c @@ -258,7 +258,7 @@ Image LoadImageRaw(const char *fileName, int width, int height, int format, int Image LoadImageAnim(const char *fileName, int *frames) { Image image = { 0 }; - int framesCount = 1; + int frameCount = 1; #if defined(SUPPORT_FILEFORMAT_GIF) if (IsFileExtension(fileName, ".gif")) @@ -270,7 +270,7 @@ Image LoadImageAnim(const char *fileName, int *frames) { int comp = 0; int **delays = NULL; - image.data = stbi_load_gif_from_memory(fileData, dataSize, delays, &image.width, &image.height, &framesCount, &comp, 4); + image.data = stbi_load_gif_from_memory(fileData, dataSize, delays, &image.width, &image.height, &frameCount, &comp, 4); image.mipmaps = 1; image.format = PIXELFORMAT_UNCOMPRESSED_R8G8B8A8; @@ -286,7 +286,7 @@ Image LoadImageAnim(const char *fileName, int *frames) // TODO: Support APNG animated images? - *frames = framesCount; + *frames = frameCount; return image; } @@ -520,17 +520,17 @@ bool ExportImageAsCode(Image image, const char *fileName) // and requiring 6 char bytes for every byte: "0x00, " char *txtData = (char *)RL_CALLOC(dataSize*6 + 2000, sizeof(char)); - int bytesCount = 0; - bytesCount += sprintf(txtData + bytesCount, "////////////////////////////////////////////////////////////////////////////////////////\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// ImageAsCode exporter v1.0 - Image pixel data exported as an array of bytes //\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// more info and bugs-report: github.com/raysan5/raylib //\n"); - bytesCount += sprintf(txtData + bytesCount, "// feedback and support: ray[at]raylib.com //\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "// Copyright (c) 2018-2021 Ramon Santamaria (@raysan5) //\n"); - bytesCount += sprintf(txtData + bytesCount, "// //\n"); - bytesCount += sprintf(txtData + bytesCount, "////////////////////////////////////////////////////////////////////////////////////////\n\n"); + int byteCount = 0; + byteCount += sprintf(txtData + byteCount, "////////////////////////////////////////////////////////////////////////////////////////\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "// ImageAsCode exporter v1.0 - Image pixel data exported as an array of bytes //\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "// more info and bugs-report: github.com/raysan5/raylib //\n"); + byteCount += sprintf(txtData + byteCount, "// feedback and support: ray[at]raylib.com //\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "// Copyright (c) 2018-2021 Ramon Santamaria (@raysan5) //\n"); + byteCount += sprintf(txtData + byteCount, "// //\n"); + byteCount += sprintf(txtData + byteCount, "////////////////////////////////////////////////////////////////////////////////////////\n\n"); // Get file name from path and convert variable name to uppercase char varFileName[256] = { 0 }; @@ -538,14 +538,14 @@ bool ExportImageAsCode(Image image, const char *fileName) for (int i = 0; varFileName[i] != '\0'; i++) if ((varFileName[i] >= 'a') && (varFileName[i] <= 'z')) { varFileName[i] = varFileName[i] - 32; } // Add image information - bytesCount += sprintf(txtData + bytesCount, "// Image data information\n"); - bytesCount += sprintf(txtData + bytesCount, "#define %s_WIDTH %i\n", varFileName, image.width); - bytesCount += sprintf(txtData + bytesCount, "#define %s_HEIGHT %i\n", varFileName, image.height); - bytesCount += sprintf(txtData + bytesCount, "#define %s_FORMAT %i // raylib internal pixel format\n\n", varFileName, image.format); + byteCount += sprintf(txtData + byteCount, "// Image data information\n"); + byteCount += sprintf(txtData + byteCount, "#define %s_WIDTH %i\n", varFileName, image.width); + byteCount += sprintf(txtData + byteCount, "#define %s_HEIGHT %i\n", varFileName, image.height); + byteCount += sprintf(txtData + byteCount, "#define %s_FORMAT %i // raylib internal pixel format\n\n", varFileName, image.format); - bytesCount += sprintf(txtData + bytesCount, "static unsigned char %s_DATA[%i] = { ", varFileName, dataSize); - for (int i = 0; i < dataSize - 1; i++) bytesCount += sprintf(txtData + bytesCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)image.data)[i]); - bytesCount += sprintf(txtData + bytesCount, "0x%x };\n", ((unsigned char *)image.data)[dataSize - 1]); + byteCount += sprintf(txtData + byteCount, "static unsigned char %s_DATA[%i] = { ", varFileName, dataSize); + for (int i = 0; i < dataSize - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)image.data)[i]); + byteCount += sprintf(txtData + byteCount, "0x%x };\n", ((unsigned char *)image.data)[dataSize - 1]); // NOTE: Text data length exported is determined by '\0' (NULL) character success = SaveFileText(fileName, txtData); @@ -765,11 +765,11 @@ Image GenImageCellular(int width, int height, int tileSize) int seedsPerRow = width/tileSize; int seedsPerCol = height/tileSize; - int seedsCount = seedsPerRow*seedsPerCol; + int seedCount = seedsPerRow*seedsPerCol; - Vector2 *seeds = (Vector2 *)RL_MALLOC(seedsCount*sizeof(Vector2)); + Vector2 *seeds = (Vector2 *)RL_MALLOC(seedCount*sizeof(Vector2)); - for (int i = 0; i < seedsCount; i++) + for (int i = 0; i < seedCount; i++) { int y = (i/seedsPerRow)*tileSize + GetRandomValue(0, tileSize - 1); int x = (i%seedsPerRow)*tileSize + GetRandomValue(0, tileSize - 1); @@ -1180,12 +1180,12 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co { if ((codepoint != ' ') && (codepoint != '\t')) { - Rectangle rec = { (float)(textOffsetX + font.chars[index].offsetX), (float)(textOffsetY + font.chars[index].offsetY), (float)font.recs[index].width, (float)font.recs[index].height }; - ImageDraw(&imText, font.chars[index].image, (Rectangle){ 0, 0, (float)font.chars[index].image.width, (float)font.chars[index].image.height }, rec, tint); + Rectangle rec = { (float)(textOffsetX + font.glyphs[index].offsetX), (float)(textOffsetY + font.glyphs[index].offsetY), (float)font.recs[index].width, (float)font.recs[index].height }; + ImageDraw(&imText, font.glyphs[index].image, (Rectangle){ 0, 0, (float)font.glyphs[index].image.width, (float)font.glyphs[index].image.height }, rec, tint); } - if (font.chars[index].advanceX == 0) textOffsetX += (int)(font.recs[index].width + spacing); - else textOffsetX += font.chars[index].advanceX + (int)spacing; + if (font.glyphs[index].advanceX == 0) textOffsetX += (int)(font.recs[index].width + spacing); + else textOffsetX += font.glyphs[index].advanceX + (int)spacing; } i += (codepointByteCount - 1); // Move text bytes counter to next codepoint @@ -2185,7 +2185,7 @@ Color *LoadImageColors(Image image) // Load colors palette from image as a Color array (RGBA - 32bit) // NOTE: Memory allocated should be freed using UnloadImagePalette() -Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorsCount) +Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorCount) { #define COLOR_EQUAL(col1, col2) ((col1.r == col2.r)&&(col1.g == col2.g)&&(col1.b == col2.b)&&(col1.a == col2.a)) @@ -2234,7 +2234,7 @@ Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorsCount) UnloadImageColors(pixels); } - *colorsCount = palCount; + *colorCount = palCount; return palette; } @@ -3487,9 +3487,9 @@ void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, // Draw textured polygon, defined by vertex and texturecoordinates // NOTE: Polygon center must have straight line path to all points // without crossing perimeter, points must be in anticlockwise order -void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointsCount, Color tint) +void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint) { - rlCheckRenderBatchLimit((pointsCount - 1)*4); + rlCheckRenderBatchLimit((pointCount - 1)*4); rlSetTexture(texture.id); @@ -3498,7 +3498,7 @@ void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 rlColor4ub(tint.r, tint.g, tint.b, tint.a); - for (int i = 0; i < pointsCount - 1; i++) + for (int i = 0; i < pointCount - 1; i++) { rlTexCoord2f(0.5f, 0.5f); rlVertex2f(center.x, center.y); From 6e76baa6a93d039e132fe11eedc74958971bf4a3 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 1 Sep 2021 23:11:31 +0200 Subject: [PATCH 08/59] WARNING: BREAKING: RENAMED: Font struct variables RENAMED: GetCodepointsCount() -> GetCodepointCount() RENAMED: GetTouchPointsCount() -> GetTouchPointCount() --- examples/text/text_rectangle_bounds.c | 2 +- examples/text/text_unicode.c | 4 +- src/gestures.h | 4 +- src/raylib.h | 42 +++--- src/text.c | 184 +++++++++++++------------- 5 files changed, 118 insertions(+), 118 deletions(-) diff --git a/examples/text/text_rectangle_bounds.c b/examples/text/text_rectangle_bounds.c index 0da1a8ab3..b4884fb36 100644 --- a/examples/text/text_rectangle_bounds.c +++ b/examples/text/text_rectangle_bounds.c @@ -166,7 +166,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec, float glyphWidth = 0; if (codepoint != '\n') { - glyphWidth = (font.chars[index].advanceX == 0) ? font.recs[index].width*scaleFactor : font.chars[index].advanceX*scaleFactor; + glyphWidth = (font.glyphs[index].advanceX == 0) ? font.recs[index].width*scaleFactor : font.glyphs[index].advanceX*scaleFactor; if (i + 1 < length) glyphWidth = glyphWidth + spacing; } diff --git a/examples/text/text_unicode.c b/examples/text/text_unicode.c index 883d2a5cd..4b6b7780f 100644 --- a/examples/text/text_unicode.c +++ b/examples/text/text_unicode.c @@ -277,7 +277,7 @@ int main(int argc, char **argv) // Draw the info text below the main message int size = (int)strlen(messages[message].text); - int len = GetCodepointsCount(messages[message].text); + int len = GetCodepointCount(messages[message].text); const char *info = TextFormat("%s %u characters %i bytes", messages[message].language, len, size); sz = MeasureTextEx(GetFontDefault(), info, 10, 1.0f); Vector2 pos = { textRect.x + textRect.width - sz.x, msgRect.y + msgRect.height - sz.y - 2 }; @@ -367,7 +367,7 @@ static void DrawTextBoxedSelectable(Font font, const char *text, Rectangle rec, float glyphWidth = 0; if (codepoint != '\n') { - glyphWidth = (font.chars[index].advanceX == 0) ? font.recs[index].width*scaleFactor : font.chars[index].advanceX*scaleFactor; + glyphWidth = (font.glyphs[index].advanceX == 0) ? font.recs[index].width*scaleFactor : font.glyphs[index].advanceX*scaleFactor; if (i + 1 < length) glyphWidth = glyphWidth + spacing; } diff --git a/src/gestures.h b/src/gestures.h index 355f60817..09adffd02 100644 --- a/src/gestures.h +++ b/src/gestures.h @@ -118,7 +118,7 @@ void UpdateGestures(void); // Update gestures detec void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags bool IsGestureDetected(int gesture); // Check if a gesture have been detected int GetGestureDetected(void); // Get latest detected gesture -int GetTouchPointsCount(void); // Get touch points count +int GetTouchPointCount(void); // Get touch points count float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds Vector2 GetGestureDragVector(void); // Get gesture drag vector float GetGestureDragAngle(void); // Get gesture drag angle @@ -431,7 +431,7 @@ void UpdateGestures(void) } // Get number of touch points -int GetTouchPointsCount(void) +int GetTouchPointCount(void) { // NOTE: point count is calculated when ProcessGestureEvent(GestureEvent event) is called diff --git a/src/raylib.h b/src/raylib.h index fb0be1783..6b26713d4 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -287,11 +287,11 @@ typedef struct GlyphInfo { // Font, font texture and GlyphInfo array data typedef struct Font { int baseSize; // Base size (default chars height) - int charsCount; // Number of characters - int charsPadding; // Padding around the chars - Texture2D texture; // Characters texture atlas - Rectangle *recs; // Characters rectangles in texture - GlyphInfo *chars; // Characters glyphs info data + int glyphCount; // Number of glyph characters + int glyphPadding; // Padding around the glyph characters + Texture2D texture; // Texture atlas containing the glyphs + Rectangle *recs; // Rectangles in texture for the glyphs + GlyphInfo *glyphs; // Glyphs info data } Font; // Camera, defines position/orientation in 3d space @@ -1111,7 +1111,7 @@ RLAPI Vector2 GetTouchPosition(int index); // Get touch posit RLAPI void SetGesturesEnabled(unsigned int flags); // Enable a set of gestures using flags RLAPI bool IsGestureDetected(int gesture); // Check if a gesture have been detected RLAPI int GetGestureDetected(void); // Get latest detected gesture -RLAPI int GetTouchPointsCount(void); // Get touch points count +RLAPI int GetTouchPointCount(void); // Get touch points count RLAPI float GetGestureHoldDuration(void); // Get gesture hold time in milliseconds RLAPI Vector2 GetGestureDragVector(void); // Get gesture drag vector RLAPI float GetGestureDragAngle(void); // Get gesture drag angle @@ -1145,7 +1145,7 @@ RLAPI void DrawLineV(Vector2 startPos, Vector2 endPos, Color color); RLAPI void DrawLineEx(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line defining thickness RLAPI void DrawLineBezier(Vector2 startPos, Vector2 endPos, float thick, Color color); // Draw a line using cubic-bezier curves in-out RLAPI void DrawLineBezierQuad(Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color); //Draw line using quadratic bezier curves with a control point -RLAPI void DrawLineStrip(Vector2 *points, int pointsCount, Color color); // Draw lines sequence +RLAPI void DrawLineStrip(Vector2 *points, int pointCount, Color color); // Draw lines sequence RLAPI void DrawCircle(int centerX, int centerY, float radius, Color color); // Draw a color-filled circle RLAPI void DrawCircleSector(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw a piece of a circle RLAPI void DrawCircleSectorLines(Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color); // Draw circle sector outline @@ -1169,8 +1169,8 @@ RLAPI void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Co RLAPI void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, float lineThick, Color color); // Draw rectangle with rounded edges outline RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!) RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline (vertex in counter-clockwise order!) -RLAPI void DrawTriangleFan(Vector2 *points, int pointsCount, Color color); // Draw a triangle fan defined by points (first vertex is the center) -RLAPI void DrawTriangleStrip(Vector2 *points, int pointsCount, Color color); // Draw a triangle strip defined by points +RLAPI void DrawTriangleFan(Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points (first vertex is the center) +RLAPI void DrawTriangleStrip(Vector2 *points, int pointCount, Color color); // Draw a triangle strip defined by points RLAPI void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a regular polygon (Vector version) RLAPI void DrawPolyLines(Vector2 center, int sides, float radius, float rotation, Color color); // Draw a polygon outline of n sides RLAPI void DrawPolyLinesEx(Vector2 center, int sides, float radius, float rotation, float lineThick, Color color); // Draw a polygon outline of n sides with extended parameters @@ -1239,7 +1239,7 @@ RLAPI void ImageColorContrast(Image *image, float contrast); RLAPI void ImageColorBrightness(Image *image, int brightness); // Modify image color: brightness (-255 to 255) RLAPI void ImageColorReplace(Image *image, Color color, Color replace); // Modify image color: replace color RLAPI Color *LoadImageColors(Image image); // Load color data from image as a Color array (RGBA - 32bit) -RLAPI Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorsCount); // Load colors palette from image as a Color array (RGBA - 32bit) +RLAPI Color *LoadImagePalette(Image image, int maxPaletteSize, int *colorCount); // Load colors palette from image as a Color array (RGBA - 32bit) RLAPI void UnloadImageColors(Color *colors); // Unload color data loaded with LoadImageColors() RLAPI void UnloadImagePalette(Color *colors); // Unload colors palette loaded with LoadImagePalette() RLAPI Rectangle GetImageAlphaBorder(Image image, float threshold); // Get image alpha border rectangle @@ -1286,7 +1286,7 @@ RLAPI void DrawTextureQuad(Texture2D texture, Vector2 tiling, Vector2 offset, Re RLAPI void DrawTextureTiled(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, float scale, Color tint); // Draw part of a texture (defined by a rectangle) with rotation and scale tiled into dest. RLAPI void DrawTexturePro(Texture2D texture, Rectangle source, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draw a part of a texture defined by a rectangle with 'pro' parameters RLAPI void DrawTextureNPatch(Texture2D texture, NPatchInfo nPatchInfo, Rectangle dest, Vector2 origin, float rotation, Color tint); // Draws a texture (or part of it) that stretches or shrinks nicely -RLAPI void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointsCount, Color tint); // Draw a textured polygon +RLAPI void DrawTexturePoly(Texture2D texture, Vector2 center, Vector2 *points, Vector2 *texcoords, int pointCount, Color tint); // Draw a textured polygon // Color/pixel related functions RLAPI Color Fade(Color color, float alpha); // Get color with alpha applied, alpha goes from 0.0f to 1.0f @@ -1309,12 +1309,12 @@ RLAPI int GetPixelDataSize(int width, int height, int format); // G // Font loading/unloading functions RLAPI Font GetFontDefault(void); // Get the default Font RLAPI Font LoadFont(const char *fileName); // Load font from file into GPU memory (VRAM) -RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCount); // Load font from file with extended parameters +RLAPI Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int glyphCount); // Load font from file with extended parameters RLAPI Font LoadFontFromImage(Image image, Color key, int firstChar); // Load font from Image (XNA style) -RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf' -RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount, int type); // Load font data for further use -RLAPI Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **recs, int charsCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info -RLAPI void UnloadFontData(GlyphInfo *chars, int charsCount); // Unload font chars info data (RAM) +RLAPI Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int glyphCount); // Load font from memory buffer, fileType refers to extension: i.e. '.ttf' +RLAPI GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int glyphCount, int type); // Load font data for further use +RLAPI Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **recs, int glyphCount, int fontSize, int padding, int packMethod); // Generate image font atlas using chars info +RLAPI void UnloadFontData(GlyphInfo *chars, int glyphCount); // Unload font chars info data (RAM) RLAPI void UnloadFont(Font font); // Unload Font from GPU memory (VRAM) // Text drawing functions @@ -1334,7 +1334,7 @@ RLAPI Rectangle GetGlyphAtlasRec(Font font, int codepoint); // Text codepoints management functions (unicode characters) RLAPI int *LoadCodepoints(const char *text, int *count); // Load all codepoints from a UTF-8 text string, codepoints count returned by parameter RLAPI void UnloadCodepoints(int *codepoints); // Unload codepoints data from memory -RLAPI int GetCodepointsCount(const char *text); // Get total number of codepoints in a UTF-8 encoded string +RLAPI int GetCodepointCount(const char *text); // Get total number of codepoints in a UTF-8 encoded string RLAPI int GetCodepoint(const char *text, int *bytesProcessed); // Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure RLAPI const char *CodepointToUTF8(int codepoint, int *byteLength); // Encode one codepoint into UTF-8 byte array (array length returned as parameter) RLAPI char *TextCodepointsToUTF8(int *codepoints, int length); // Encode text as codepoints array into UTF-8 text string (WARNING: memory must be freed!) @@ -1366,7 +1366,7 @@ RLAPI void DrawLine3D(Vector3 startPos, Vector3 endPos, Color color); RLAPI void DrawPoint3D(Vector3 position, Color color); // Draw a point in 3D space, actually a small line RLAPI void DrawCircle3D(Vector3 center, float radius, Vector3 rotationAxis, float rotationAngle, Color color); // Draw a circle in 3D world space RLAPI void DrawTriangle3D(Vector3 v1, Vector3 v2, Vector3 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!) -RLAPI void DrawTriangleStrip3D(Vector3 *points, int pointsCount, Color color); // Draw a triangle strip defined by points +RLAPI void DrawTriangleStrip3D(Vector3 *points, int pointCount, Color color); // Draw a triangle strip defined by points RLAPI void DrawCube(Vector3 position, float width, float height, float length, Color color); // Draw cube RLAPI void DrawCubeV(Vector3 position, Vector3 size, Color color); // Draw cube (Vector version) RLAPI void DrawCubeWires(Vector3 position, float width, float height, float length, Color color); // Draw cube wires @@ -1434,7 +1434,7 @@ RLAPI void SetMaterialTexture(Material *material, int mapType, Texture2D texture RLAPI void SetModelMeshMaterial(Model *model, int meshId, int materialId); // Set material for a mesh // Model animations loading/unloading functions -RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, int *animsCount); // Load model animations from file +RLAPI ModelAnimation *LoadModelAnimations(const char *fileName, int *animCount); // Load model animations from file RLAPI void UpdateModelAnimation(Model model, ModelAnimation anim, int frame); // Update model animation pose RLAPI void UnloadModelAnimation(ModelAnimation anim); // Unload animation data RLAPI void UnloadModelAnimations(ModelAnimation* animations, unsigned int count); // Unload animation array data @@ -1466,7 +1466,7 @@ RLAPI Wave LoadWave(const char *fileName); // Load wa RLAPI Wave LoadWaveFromMemory(const char *fileType, const unsigned char *fileData, int dataSize); // Load wave from memory buffer, fileType refers to extension: i.e. '.wav' RLAPI Sound LoadSound(const char *fileName); // Load sound from file RLAPI Sound LoadSoundFromWave(Wave wave); // Load sound from wave data -RLAPI void UpdateSound(Sound sound, const void *data, int samplesCount);// Update sound buffer with new data +RLAPI void UpdateSound(Sound sound, const void *data, int sampleCount); // Update sound buffer with new data RLAPI void UnloadWave(Wave wave); // Unload wave data RLAPI void UnloadSound(Sound sound); // Unload sound RLAPI bool ExportWave(Wave wave, const char *fileName); // Export wave data to file, returns true on success @@ -1507,7 +1507,7 @@ RLAPI float GetMusicTimePlayed(Music music); // Get cur // AudioStream management functions RLAPI AudioStream LoadAudioStream(unsigned int sampleRate, unsigned int sampleSize, unsigned int channels); // Load audio stream (to stream raw audio pcm data) RLAPI void UnloadAudioStream(AudioStream stream); // Unload audio stream and free memory -RLAPI void UpdateAudioStream(AudioStream stream, const void *data, int framesCount); // Update audio stream buffers with data +RLAPI void UpdateAudioStream(AudioStream stream, const void *data, int frameCount); // Update audio stream buffers with data RLAPI bool IsAudioStreamProcessed(AudioStream stream); // Check if any audio stream buffers requires refill RLAPI void PlayAudioStream(AudioStream stream); // Play audio stream RLAPI void PauseAudioStream(AudioStream stream); // Pause audio stream diff --git a/src/text.c b/src/text.c index 66a08eb19..ae6f38661 100644 --- a/src/text.c +++ b/src/text.c @@ -129,8 +129,8 @@ extern void LoadFontDefault(void) // NOTE: Using UTF-8 encoding table for Unicode U+0000..U+00FF Basic Latin + Latin-1 Supplement // Ref: http://www.utf8-chartable.de/unicode-utf8-table.pl - defaultFont.charsCount = 224; // Number of chars included in our default font - defaultFont.charsPadding = 0; // Characters padding + defaultFont.glyphCount = 224; // Number of chars included in our default font + defaultFont.glyphPadding = 0; // Characters padding // Default font is directly defined here (data generated from a sprite font image) // This way, we reconstruct Font without creating large global variables @@ -220,21 +220,21 @@ extern void LoadFontDefault(void) defaultFont.texture = LoadTextureFromImage(imFont); - // Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, charsCount + // Reconstruct charSet using charsWidth[], charsHeight, charsDivisor, glyphCount //------------------------------------------------------------------------------ // Allocate space for our characters info data // NOTE: This memory should be freed at end! --> CloseWindow() - defaultFont.chars = (GlyphInfo *)RL_MALLOC(defaultFont.charsCount*sizeof(GlyphInfo)); - defaultFont.recs = (Rectangle *)RL_MALLOC(defaultFont.charsCount*sizeof(Rectangle)); + defaultFont.glyphs = (GlyphInfo *)RL_MALLOC(defaultFont.glyphCount*sizeof(GlyphInfo)); + defaultFont.recs = (Rectangle *)RL_MALLOC(defaultFont.glyphCount*sizeof(Rectangle)); int currentLine = 0; int currentPosX = charsDivisor; int testPosX = charsDivisor; - for (int i = 0; i < defaultFont.charsCount; i++) + for (int i = 0; i < defaultFont.glyphCount; i++) { - defaultFont.chars[i].value = 32 + i; // First char is 32 + defaultFont.glyphs[i].value = 32 + i; // First char is 32 defaultFont.recs[i].x = (float)currentPosX; defaultFont.recs[i].y = (float)(charsDivisor + currentLine*(charsHeight + charsDivisor)); @@ -255,12 +255,12 @@ extern void LoadFontDefault(void) else currentPosX = testPosX; // NOTE: On default font character offsets and xAdvance are not required - defaultFont.chars[i].offsetX = 0; - defaultFont.chars[i].offsetY = 0; - defaultFont.chars[i].advanceX = 0; + defaultFont.glyphs[i].offsetX = 0; + defaultFont.glyphs[i].offsetY = 0; + defaultFont.glyphs[i].advanceX = 0; // Fill character image data from fontClear data - defaultFont.chars[i].image = ImageFromImage(imFont, defaultFont.recs[i]); + defaultFont.glyphs[i].image = ImageFromImage(imFont, defaultFont.recs[i]); } UnloadImage(imFont); @@ -273,9 +273,9 @@ extern void LoadFontDefault(void) // Unload raylib default font extern void UnloadFontDefault(void) { - for (int i = 0; i < defaultFont.charsCount; i++) UnloadImage(defaultFont.chars[i].image); + for (int i = 0; i < defaultFont.glyphCount; i++) UnloadImage(defaultFont.glyphs[i].image); UnloadTexture(defaultFont.texture); - RL_FREE(defaultFont.chars); + RL_FREE(defaultFont.glyphs); RL_FREE(defaultFont.recs); } #endif // SUPPORT_DEFAULT_FONT @@ -337,7 +337,7 @@ Font LoadFont(const char *fileName) // Load Font from TTF font file with generation parameters // NOTE: You can pass an array with desired characters, those characters should be available in the font // if array is NULL, default char set is selected 32..126 -Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCount) +Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int glyphCount) { Font font = { 0 }; @@ -348,7 +348,7 @@ Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCou if (fileData != NULL) { // Loading font from memory data - font = LoadFontFromMemory(GetFileExtension(fileName), fileData, fileSize, fontSize, fontChars, charsCount); + font = LoadFontFromMemory(GetFileExtension(fileName), fileData, fileSize, fontSize, fontChars, glyphCount); RL_FREE(fileData); } @@ -449,28 +449,28 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) Font font = { 0 }; font.texture = LoadTextureFromImage(fontClear); // Convert processed image to OpenGL texture - font.charsCount = index; - font.charsPadding = 0; + font.glyphCount = index; + font.glyphPadding = 0; // We got tempCharValues and tempCharsRecs populated with chars data // Now we move temp data to sized charValues and charRecs arrays - font.chars = (GlyphInfo *)RL_MALLOC(font.charsCount*sizeof(GlyphInfo)); - font.recs = (Rectangle *)RL_MALLOC(font.charsCount*sizeof(Rectangle)); + font.glyphs = (GlyphInfo *)RL_MALLOC(font.glyphCount*sizeof(GlyphInfo)); + font.recs = (Rectangle *)RL_MALLOC(font.glyphCount*sizeof(Rectangle)); - for (int i = 0; i < font.charsCount; i++) + for (int i = 0; i < font.glyphCount; i++) { - font.chars[i].value = tempCharValues[i]; + font.glyphs[i].value = tempCharValues[i]; // Get character rectangle in the font atlas texture font.recs[i] = tempCharRecs[i]; // NOTE: On image based fonts (XNA style), character offsets and xAdvance are not required (set to 0) - font.chars[i].offsetX = 0; - font.chars[i].offsetY = 0; - font.chars[i].advanceX = 0; + font.glyphs[i].offsetX = 0; + font.glyphs[i].offsetY = 0; + font.glyphs[i].advanceX = 0; // Fill character image data from fontClear data - font.chars[i].image = ImageFromImage(fontClear, tempCharRecs[i]); + font.glyphs[i].image = ImageFromImage(fontClear, tempCharRecs[i]); } UnloadImage(fontClear); // Unload processed image once converted to texture @@ -481,7 +481,7 @@ Font LoadFontFromImage(Image image, Color key, int firstChar) } // Load font from memory buffer, fileType refers to extension: i.e. ".ttf" -Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount) +Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int glyphCount) { Font font = { 0 }; @@ -493,22 +493,22 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int TextIsEqual(fileExtLower, ".otf")) { font.baseSize = fontSize; - font.charsCount = (charsCount > 0)? charsCount : 95; - font.charsPadding = 0; - font.chars = LoadFontData(fileData, dataSize, font.baseSize, fontChars, font.charsCount, FONT_DEFAULT); + font.glyphCount = (glyphCount > 0)? glyphCount : 95; + font.glyphPadding = 0; + font.glyphs = LoadFontData(fileData, dataSize, font.baseSize, fontChars, font.glyphCount, FONT_DEFAULT); - if (font.chars != NULL) + if (font.glyphs != NULL) { - font.charsPadding = FONT_TTF_DEFAULT_CHARS_PADDING; + font.glyphPadding = FONT_TTF_DEFAULT_CHARS_PADDING; - Image atlas = GenImageFontAtlas(font.chars, &font.recs, font.charsCount, font.baseSize, font.charsPadding, 0); + Image atlas = GenImageFontAtlas(font.glyphs, &font.recs, font.glyphCount, font.baseSize, font.glyphPadding, 0); font.texture = LoadTextureFromImage(atlas); - // Update chars[i].image to use alpha, required to be used on ImageDrawText() - for (int i = 0; i < font.charsCount; i++) + // Update glyphs[i].image to use alpha, required to be used on ImageDrawText() + for (int i = 0; i < font.glyphCount; i++) { - UnloadImage(font.chars[i].image); - font.chars[i].image = ImageFromImage(atlas, font.recs[i]); + UnloadImage(font.glyphs[i].image); + font.glyphs[i].image = ImageFromImage(atlas, font.recs[i]); } UnloadImage(atlas); @@ -524,7 +524,7 @@ Font LoadFontFromMemory(const char *fileType, const unsigned char *fileData, int // Load font data for further use // NOTE: Requires TTF font memory data and can generate SDF data -GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int charsCount, int type) +GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSize, int *fontChars, int glyphCount, int type) { // NOTE: Using some SDF generation default values, // trades off precision with ability to handle *smaller* sizes @@ -562,22 +562,22 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz stbtt_GetFontVMetrics(&fontInfo, &ascent, &descent, &lineGap); // In case no chars count provided, default to 95 - charsCount = (charsCount > 0)? charsCount : 95; + glyphCount = (glyphCount > 0)? glyphCount : 95; // Fill fontChars in case not provided externally - // NOTE: By default we fill charsCount consecutevely, starting at 32 (Space) + // NOTE: By default we fill glyphCount consecutevely, starting at 32 (Space) if (fontChars == NULL) { - fontChars = (int *)RL_MALLOC(charsCount*sizeof(int)); - for (int i = 0; i < charsCount; i++) fontChars[i] = i + 32; + fontChars = (int *)RL_MALLOC(glyphCount*sizeof(int)); + for (int i = 0; i < glyphCount; i++) fontChars[i] = i + 32; genFontChars = true; } - chars = (GlyphInfo *)RL_MALLOC(charsCount*sizeof(GlyphInfo)); + chars = (GlyphInfo *)RL_MALLOC(glyphCount*sizeof(GlyphInfo)); // NOTE: Using simple packaging, one char after another - for (int i = 0; i < charsCount; i++) + for (int i = 0; i < glyphCount; i++) { int chw = 0, chh = 0; // Character width and height (on generation) int ch = fontChars[i]; // Character value to get info for @@ -650,7 +650,7 @@ GlyphInfo *LoadFontData(const unsigned char *fileData, int dataSize, int fontSiz // Generate image font atlas using chars info // NOTE: Packing method: 0-Default, 1-Skyline #if defined(SUPPORT_FILEFORMAT_TTF) -Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int charsCount, int fontSize, int padding, int packMethod) +Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int glyphCount, int fontSize, int padding, int packMethod) { Image atlas = { 0 }; @@ -663,17 +663,17 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int charsC *charRecs = NULL; // In case no chars count provided we suppose default of 95 - charsCount = (charsCount > 0)? charsCount : 95; + glyphCount = (glyphCount > 0)? glyphCount : 95; // NOTE: Rectangles memory is loaded here! - Rectangle *recs = (Rectangle *)RL_MALLOC(charsCount*sizeof(Rectangle)); + Rectangle *recs = (Rectangle *)RL_MALLOC(glyphCount*sizeof(Rectangle)); // Calculate image size based on required pixel area // NOTE 1: Image is forced to be squared and POT... very conservative! // NOTE 2: SDF font characters already contain an internal padding, // so image size would result bigger than default font type float requiredArea = 0; - for (int i = 0; i < charsCount; i++) requiredArea += ((chars[i].image.width + 2*padding)*(chars[i].image.height + 2*padding)); + for (int i = 0; i < glyphCount; i++) requiredArea += ((chars[i].image.width + 2*padding)*(chars[i].image.height + 2*padding)); float guessSize = sqrtf(requiredArea)*1.3f; int imageSize = (int)powf(2, ceilf(logf((float)guessSize)/logf(2))); // Calculate next POT @@ -692,7 +692,7 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int charsC int offsetY = padding; // NOTE: Using simple packaging, one char after another - for (int i = 0; i < charsCount; i++) + for (int i = 0; i < glyphCount; i++) { // Copy pixel data from fc.data to atlas for (int y = 0; y < chars[i].image.height; y++) @@ -728,13 +728,13 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int charsC else if (packMethod == 1) // Use Skyline rect packing algorythm (stb_pack_rect) { stbrp_context *context = (stbrp_context *)RL_MALLOC(sizeof(*context)); - stbrp_node *nodes = (stbrp_node *)RL_MALLOC(charsCount*sizeof(*nodes)); + stbrp_node *nodes = (stbrp_node *)RL_MALLOC(glyphCount*sizeof(*nodes)); - stbrp_init_target(context, atlas.width, atlas.height, nodes, charsCount); - stbrp_rect *rects = (stbrp_rect *)RL_MALLOC(charsCount*sizeof(stbrp_rect)); + stbrp_init_target(context, atlas.width, atlas.height, nodes, glyphCount); + stbrp_rect *rects = (stbrp_rect *)RL_MALLOC(glyphCount*sizeof(stbrp_rect)); // Fill rectangles for packaging - for (int i = 0; i < charsCount; i++) + for (int i = 0; i < glyphCount; i++) { rects[i].id = i; rects[i].w = chars[i].image.width + 2*padding; @@ -742,9 +742,9 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int charsC } // Package rectangles into atlas - stbrp_pack_rects(context, rects, charsCount); + stbrp_pack_rects(context, rects, glyphCount); - for (int i = 0; i < charsCount; i++) + for (int i = 0; i < glyphCount; i++) { // It return char rectangles in atlas recs[i].x = rects[i].x + (float)padding; @@ -792,12 +792,12 @@ Image GenImageFontAtlas(const GlyphInfo *chars, Rectangle **charRecs, int charsC } #endif -// Unload font chars info data (RAM) -void UnloadFontData(GlyphInfo *chars, int charsCount) +// Unload font glyphs info data (RAM) +void UnloadFontData(GlyphInfo *glyphs, int glyphCount) { - for (int i = 0; i < charsCount; i++) UnloadImage(chars[i].image); + for (int i = 0; i < glyphCount; i++) UnloadImage(glyphs[i].image); - RL_FREE(chars); + RL_FREE(glyphs); } // Unload Font from GPU memory (VRAM) @@ -806,7 +806,7 @@ void UnloadFont(Font font) // NOTE: Make sure font is not default font (fallback) if (font.texture.id != GetFontDefault().texture.id) { - UnloadFontData(font.chars, font.charsCount); + UnloadFontData(font.glyphs, font.glyphCount); UnloadTexture(font.texture); RL_FREE(font.recs); @@ -883,8 +883,8 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f DrawTextCodepoint(font, codepoint, (Vector2){ position.x + textOffsetX, position.y + textOffsetY }, fontSize, tint); } - if (font.chars[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing); - else textOffsetX += ((float)font.chars[index].advanceX*scaleFactor + spacing); + if (font.glyphs[index].advanceX == 0) textOffsetX += ((float)font.recs[index].width*scaleFactor + spacing); + else textOffsetX += ((float)font.glyphs[index].advanceX*scaleFactor + spacing); } i += codepointByteCount; // Move text bytes counter to next codepoint @@ -914,16 +914,16 @@ void DrawTextCodepoint(Font font, int codepoint, Vector2 position, float fontSiz float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor // Character destination rectangle on screen - // NOTE: We consider charsPadding on drawing - Rectangle dstRec = { position.x + font.chars[index].offsetX*scaleFactor - (float)font.charsPadding*scaleFactor, - position.y + font.chars[index].offsetY*scaleFactor - (float)font.charsPadding*scaleFactor, - (font.recs[index].width + 2.0f*font.charsPadding)*scaleFactor, - (font.recs[index].height + 2.0f*font.charsPadding)*scaleFactor }; + // NOTE: We consider glyphPadding on drawing + Rectangle dstRec = { position.x + font.glyphs[index].offsetX*scaleFactor - (float)font.glyphPadding*scaleFactor, + position.y + font.glyphs[index].offsetY*scaleFactor - (float)font.glyphPadding*scaleFactor, + (font.recs[index].width + 2.0f*font.glyphPadding)*scaleFactor, + (font.recs[index].height + 2.0f*font.glyphPadding)*scaleFactor }; // Character source rectangle from font texture atlas // NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects - Rectangle srcRec = { font.recs[index].x - (float)font.charsPadding, font.recs[index].y - (float)font.charsPadding, - font.recs[index].width + 2.0f*font.charsPadding, font.recs[index].height + 2.0f*font.charsPadding }; + Rectangle srcRec = { font.recs[index].x - (float)font.glyphPadding, font.recs[index].y - (float)font.glyphPadding, + font.recs[index].width + 2.0f*font.glyphPadding, font.recs[index].height + 2.0f*font.glyphPadding }; // Draw the character texture on the screen DrawTexturePro(font.texture, srcRec, dstRec, (Vector2){ 0, 0 }, 0.0f, tint); @@ -978,8 +978,8 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing if (letter != '\n') { - if (font.chars[index].advanceX != 0) textWidth += font.chars[index].advanceX; - else textWidth += (font.recs[index].width + font.chars[index].offsetX); + if (font.glyphs[index].advanceX != 0) textWidth += font.glyphs[index].advanceX; + else textWidth += (font.recs[index].width + font.glyphs[index].offsetX); } else { @@ -1014,9 +1014,9 @@ int GetGlyphIndex(Font font, int codepoint) #if defined(SUPPORT_UNORDERED_CHARSET) int index = GLYPH_NOTFOUND_CHAR_FALLBACK; - for (int i = 0; i < font.charsCount; i++) + for (int i = 0; i < font.glyphCount; i++) { - if (font.chars[i].value == codepoint) + if (font.glyphs[i].value == codepoint) { index = i; break; @@ -1035,7 +1035,7 @@ GlyphInfo GetGlyphInfo(Font font, int codepoint) { GlyphInfo info = { 0 }; - info = font.chars[GetGlyphIndex(font, codepoint)]; + info = font.glyphs[GetGlyphIndex(font, codepoint)]; return info; } @@ -1472,22 +1472,22 @@ int *LoadCodepoints(const char *text, int *count) int textLength = TextLength(text); int bytesProcessed = 0; - int codepointsCount = 0; + int codepointCount = 0; // Allocate a big enough buffer to store as many codepoints as text bytes int *codepoints = RL_CALLOC(textLength, sizeof(int)); - for (int i = 0; i < textLength; codepointsCount++) + for (int i = 0; i < textLength; codepointCount++) { - codepoints[codepointsCount] = GetCodepoint(text + i, &bytesProcessed); + codepoints[codepointCount] = GetCodepoint(text + i, &bytesProcessed); i += bytesProcessed; } // Re-allocate buffer to the actual number of codepoints loaded - void *temp = RL_REALLOC(codepoints, codepointsCount*sizeof(int)); + void *temp = RL_REALLOC(codepoints, codepointCount*sizeof(int)); if (temp != NULL) codepoints = temp; - *count = codepointsCount; + *count = codepointCount; return codepoints; } @@ -1500,7 +1500,7 @@ void UnloadCodepoints(int *codepoints) // Get total number of characters(codepoints) in a UTF-8 encoded text, until '\0' is found // NOTE: If an invalid UTF-8 sequence is encountered a '?'(0x3f) codepoint is counted instead -int GetCodepointsCount(const char *text) +int GetCodepointCount(const char *text) { unsigned int len = 0; char *ptr = (char *)&text[0]; @@ -1657,7 +1657,7 @@ static Font LoadBMFont(const char *fileName) char *searchPoint = NULL; int fontSize = 0; - int charsCount = 0; + int glyphCount = 0; int imWidth = 0; int imHeight = 0; @@ -1694,10 +1694,10 @@ static Font LoadBMFont(const char *fileName) lineBytes = GetLine(fileTextPtr, buffer, MAX_BUFFER_SIZE); searchPoint = strstr(buffer, "count"); - sscanf(searchPoint, "count=%i", &charsCount); + sscanf(searchPoint, "count=%i", &glyphCount); fileTextPtr += (lineBytes + 1); - TRACELOGD(" > Chars count: %i", charsCount); + TRACELOGD(" > Chars count: %i", glyphCount); // Compose correct path using route of .fnt file (fileName) and imFileName char *imPath = NULL; @@ -1746,14 +1746,14 @@ static Font LoadBMFont(const char *fileName) // Fill font characters info data font.baseSize = fontSize; - font.charsCount = charsCount; - font.charsPadding = 0; - font.chars = (GlyphInfo *)RL_MALLOC(charsCount*sizeof(GlyphInfo)); - font.recs = (Rectangle *)RL_MALLOC(charsCount*sizeof(Rectangle)); + font.glyphCount = glyphCount; + font.glyphPadding = 0; + font.glyphs = (GlyphInfo *)RL_MALLOC(glyphCount*sizeof(GlyphInfo)); + font.recs = (Rectangle *)RL_MALLOC(glyphCount*sizeof(Rectangle)); int charId, charX, charY, charWidth, charHeight, charOffsetX, charOffsetY, charAdvanceX; - for (int i = 0; i < charsCount; i++) + for (int i = 0; i < glyphCount; i++) { lineBytes = GetLine(fileTextPtr, buffer, MAX_BUFFER_SIZE); sscanf(buffer, "char id=%i x=%i y=%i width=%i height=%i xoffset=%i yoffset=%i xadvance=%i", @@ -1764,13 +1764,13 @@ static Font LoadBMFont(const char *fileName) font.recs[i] = (Rectangle){ (float)charX, (float)charY, (float)charWidth, (float)charHeight }; // Save data properly in sprite font - font.chars[i].value = charId; - font.chars[i].offsetX = charOffsetX; - font.chars[i].offsetY = charOffsetY; - font.chars[i].advanceX = charAdvanceX; + font.glyphs[i].value = charId; + font.glyphs[i].offsetX = charOffsetX; + font.glyphs[i].offsetY = charOffsetY; + font.glyphs[i].advanceX = charAdvanceX; // Fill character image data from imFont data - font.chars[i].image = ImageFromImage(imFont, font.recs[i]); + font.glyphs[i].image = ImageFromImage(imFont, font.recs[i]); } UnloadImage(imFont); From dfadb3ee379f60f9fdb3d3a1535c716555e05dcc Mon Sep 17 00:00:00 2001 From: atticus Date: Thu, 2 Sep 2021 00:15:32 +0300 Subject: [PATCH 09/59] fix various memory leaks (#1969) --- src/extras/rmem.h | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/extras/rmem.h b/src/extras/rmem.h index 7f50adf8c..43005cfec 100644 --- a/src/extras/rmem.h +++ b/src/extras/rmem.h @@ -276,7 +276,10 @@ static void __InsertMemNode(MemPool *const mempool, AllocList *const list, MemNo mempool->arena.offs += iter->size; __RemoveMemNode(list, iter); iter = list->head; - if (iter == NULL) return; + if (iter == NULL) { + list->head = node; + return; + } } const uintptr_t inode = ( uintptr_t )node; const uintptr_t iiter = ( uintptr_t )iter; @@ -293,6 +296,14 @@ static void __InsertMemNode(MemPool *const mempool, AllocList *const list, MemNo iter->size += node->size; return; } + else if (iter->next == NULL) + { + // we reached the end of the free list -> append the node + iter->next = node; + node->prev = iter; + list->len++; + return; + } } else if (iter > node) { @@ -326,7 +337,7 @@ static void __InsertMemNode(MemPool *const mempool, AllocList *const list, MemNo } else { - __InsertMemNodeBefore(list, iter, node); + __InsertMemNodeBefore(list, node, iter); list->len++; return; } From 9362eaf9c670c86e3ce4045b7465e55db47bddb7 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 1 Sep 2021 23:40:51 +0200 Subject: [PATCH 10/59] REVIEWED: Naming: length vs size --- examples/text/text_unicode.c | 4 +-- src/core.c | 4 +-- src/raylib.h | 2 +- src/rlgl.h | 70 ++++++++++++++++++------------------ src/text.c | 40 ++++++++++----------- src/textures.c | 6 ++-- 6 files changed, 63 insertions(+), 63 deletions(-) diff --git a/examples/text/text_unicode.c b/examples/text/text_unicode.c index 4b6b7780f..c1521996f 100644 --- a/examples/text/text_unicode.c +++ b/examples/text/text_unicode.c @@ -277,8 +277,8 @@ int main(int argc, char **argv) // Draw the info text below the main message int size = (int)strlen(messages[message].text); - int len = GetCodepointCount(messages[message].text); - const char *info = TextFormat("%s %u characters %i bytes", messages[message].language, len, size); + int length = GetCodepointCount(messages[message].text); + const char *info = TextFormat("%s %u characters %i bytes", messages[message].language, length, size); sz = MeasureTextEx(GetFontDefault(), info, 10, 1.0f); Vector2 pos = { textRect.x + textRect.width - sz.x, msgRect.y + msgRect.height - sz.y - 2 }; DrawText(info, (int)pos.x, (int)pos.y, 10, RAYWHITE); diff --git a/src/core.c b/src/core.c index 89b9874ac..043f99e90 100644 --- a/src/core.c +++ b/src/core.c @@ -2767,9 +2767,9 @@ const char *GetFileNameWithoutExt(const char *filePath) if (filePath != NULL) strcpy(fileName, GetFileName(filePath)); // Get filename with extension - int len = (int)strlen(fileName); + int size = (int)strlen(fileName); // Get size in bytes - for (int i = 0; (i < len) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH); i++) + for (int i = 0; (i < size) && (i < MAX_FILENAMEWITHOUTEXT_LENGTH); i++) { if (fileName[i] == '.') { diff --git a/src/raylib.h b/src/raylib.h index 6b26713d4..9e46e842e 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1336,7 +1336,7 @@ RLAPI int *LoadCodepoints(const char *text, int *count); // Load al RLAPI void UnloadCodepoints(int *codepoints); // Unload codepoints data from memory RLAPI int GetCodepointCount(const char *text); // Get total number of codepoints in a UTF-8 encoded string RLAPI int GetCodepoint(const char *text, int *bytesProcessed); // Get next codepoint in a UTF-8 encoded string, 0x3f('?') is returned on failure -RLAPI const char *CodepointToUTF8(int codepoint, int *byteLength); // Encode one codepoint into UTF-8 byte array (array length returned as parameter) +RLAPI const char *CodepointToUTF8(int codepoint, int *byteSize); // Encode one codepoint into UTF-8 byte array (array length returned as parameter) RLAPI char *TextCodepointsToUTF8(int *codepoints, int length); // Encode text as codepoints array into UTF-8 text string (WARNING: memory must be freed!) // Text strings management functions (no UTF-8 strings, only byte chars) diff --git a/src/rlgl.h b/src/rlgl.h index ea46c537e..0bed58044 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -321,7 +321,7 @@ typedef struct rlRenderBatch { rlVertexBuffer *vertexBuffer; // Dynamic buffer(s) for vertex data rlDrawCall *draws; // Draw calls array, depends on textureId - int drawCounterer; // Draw calls counter + int drawCounter; // Draw calls counter float currentDepth; // Current depth value for next draw } rlRenderBatch; @@ -1210,34 +1210,34 @@ void rlBegin(int mode) { // Draw mode can be RL_LINES, RL_TRIANGLES and RL_QUADS // NOTE: In all three cases, vertex are accumulated over default internal vertex buffer - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode != mode) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode != mode) { - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount > 0) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0) { // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, // that way, following QUADS drawing will keep aligned with index processing // It implies adding some extra alignment vertex at the end of the draw, // those vertex are not processed but they are considered as an additional offset // for the next set of vertex to be drawn - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4); - else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4))); - else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = 0; + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4); + else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4))); + else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = 0; - if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment)) + if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment)) { - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment; - RLGL.currentBatch->drawCounterer++; + RLGL.currentBatch->drawCounter++; } } - if (RLGL.currentBatch->drawCounterer >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); + if (RLGL.currentBatch->drawCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode = mode; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount = 0; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].textureId = RLGL.State.defaultTextureId; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode = mode; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = RLGL.State.defaultTextureId; } } @@ -1319,7 +1319,7 @@ void rlVertex3f(float x, float y, float z) RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vertices[3*RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter + 2] = tz; RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter++; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount++; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount++; } else TRACELOG(RL_LOG_ERROR, "RLGL: Batch elements overflow"); } @@ -1401,33 +1401,33 @@ void rlSetTexture(unsigned int id) #if defined(GRAPHICS_API_OPENGL_11) rlEnableTexture(id); #else - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].textureId != id) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId != id) { - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount > 0) + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount > 0) { // Make sure current RLGL.currentBatch->draws[i].vertexCount is aligned a multiple of 4, // that way, following QUADS drawing will keep aligned with index processing // It implies adding some extra alignment vertex at the end of the draw, // those vertex are not processed but they are considered as an additional offset // for the next set of vertex to be drawn - if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4); - else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount%4))); - else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment = 0; + if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_LINES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount : RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4); + else if (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].mode == RL_TRIANGLES) RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = ((RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount < 4)? 1 : (4 - (RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount%4))); + else RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment = 0; - if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment)) + if (!rlCheckRenderBatchLimit(RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment)) { - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; - RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].vCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].cCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment; + RLGL.currentBatch->vertexBuffer[RLGL.currentBatch->currentBuffer].tcCounter += RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexAlignment; - RLGL.currentBatch->drawCounterer++; + RLGL.currentBatch->drawCounter++; } } - if (RLGL.currentBatch->drawCounterer >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); + if (RLGL.currentBatch->drawCounter >= RL_DEFAULT_BATCH_DRAWCALLS) rlDrawRenderBatch(RLGL.currentBatch); - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].textureId = id; - RLGL.currentBatch->draws[RLGL.currentBatch->drawCounterer - 1].vertexCount = 0; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].textureId = id; + RLGL.currentBatch->draws[RLGL.currentBatch->drawCounter - 1].vertexCount = 0; } #endif } @@ -1910,12 +1910,12 @@ void rlLoadExtensions(void *loader) const char *extensions = (const char *)glGetString(GL_EXTENSIONS); // One big const string // NOTE: We have to duplicate string because glGetString() returns a const string - int len = strlen(extensions) + 1; - char *extensionsDup = (char *)RL_CALLOC(len, sizeof(char)); + int size = strlen(extensions) + 1; // Get extensions string size in bytes + char *extensionsDup = (char *)RL_CALLOC(size, sizeof(char)); strcpy(extensionsDup, extensions); extList[numExt] = extensionsDup; - for (int i = 0; i < len; i++) + for (int i = 0; i < size; i++) { if (extensionsDup[i] == ' ') { @@ -2275,7 +2275,7 @@ rlRenderBatch rlLoadRenderBatch(int numBuffers, int bufferElements) } batch.bufferCount = numBuffers; // Record buffer count - batch.drawCounterer = 1; // Reset draws counter + batch.drawCounter = 1; // Reset draws counter batch.currentDepth = -1.0f; // Reset depth value //-------------------------------------------------------------------------------------------- #endif @@ -2447,7 +2447,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch) // NOTE: Batch system accumulates calls by texture0 changes, additional textures are enabled for all the draw calls glActiveTexture(GL_TEXTURE0); - for (int i = 0, vertexOffset = 0; i < batch->drawCounterer; i++) + for (int i = 0, vertexOffset = 0; i < batch->drawCounter; i++) { // Bind current draw call texture, activated as GL_TEXTURE0 and binded to sampler2D texture0 by default glBindTexture(GL_TEXTURE_2D, batch->draws[i].textureId); @@ -2510,7 +2510,7 @@ void rlDrawRenderBatch(rlRenderBatch *batch) for (int i = 0; i < RL_DEFAULT_BATCH_MAX_TEXTURE_UNITS; i++) RLGL.State.activeTextureId[i] = 0; // Reset draws counter to one draw for the batch - batch->drawCounterer = 1; + batch->drawCounter = 1; //------------------------------------------------------------------------------------------------------------ // Change to next buffer in the list (in case of multi-buffering) diff --git a/src/text.c b/src/text.c index ae6f38661..a7736bffb 100644 --- a/src/text.c +++ b/src/text.c @@ -851,14 +851,14 @@ void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, f { if (font.texture.id == 0) font = GetFontDefault(); // Security check in case of not valid font - int length = TextLength(text); // Total length in bytes of the text, scanned by codepoints in loop + int size = TextLength(text); // Total size in bytes of the text, scanned by codepoints in loop int textOffsetY = 0; // Offset between lines (on line break '\n') float textOffsetX = 0.0f; // Offset X to next character to draw float scaleFactor = fontSize/font.baseSize; // Character quad scaling factor - for (int i = 0; i < length;) + for (int i = 0; i < size;) { // Get next codepoint from byte string and glyph index in font int codepointByteCount = 0; @@ -950,9 +950,9 @@ int MeasureText(const char *text, int fontSize) // Measure string size for Font Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing) { - int len = TextLength(text); - int tempLen = 0; // Used to count longer text line num chars - int lenCounter = 0; + int size = TextLength(text); // Get size in bytes of text + int tempByteCounter = 0; // Used to count longer text line num chars + int byteCounter = 0; float textWidth = 0.0f; float tempTextWidth = 0.0f; // Used to count longer text line width @@ -963,9 +963,9 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing int letter = 0; // Current character int index = 0; // Index position in sprite font - for (int i = 0; i < len; i++) + for (int i = 0; i < size; i++) { - lenCounter++; + byteCounter++; int next = 0; letter = GetCodepoint(&text[i], &next); @@ -984,18 +984,18 @@ Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing else { if (tempTextWidth < textWidth) tempTextWidth = textWidth; - lenCounter = 0; + byteCounter = 0; textWidth = 0; textHeight += ((float)font.baseSize*1.5f); // NOTE: Fixed line spacing of 1.5 lines } - if (tempLen < lenCounter) tempLen = lenCounter; + if (tempByteCounter < byteCounter) tempByteCounter = byteCounter; } if (tempTextWidth < textWidth) tempTextWidth = textWidth; Vector2 vec = { 0 }; - vec.x = tempTextWidth*scaleFactor + (float)((tempLen - 1)*spacing); // Adds chars spacing to measure + vec.x = tempTextWidth*scaleFactor + (float)((tempByteCounter - 1)*spacing); // Adds chars spacing to measure vec.y = textHeight*scaleFactor; return vec; @@ -1429,28 +1429,28 @@ char *TextCodepointsToUTF8(int *codepoints, int length) // Encode codepoint into utf8 text (char array length returned as parameter) // NOTE: It uses a static array to store UTF-8 bytes -RLAPI const char *CodepointToUTF8(int codepoint, int *byteLength) +RLAPI const char *CodepointToUTF8(int codepoint, int *byteSize) { static char utf8[6] = { 0 }; - int length = 0; + int size = 0; // Byte size of codepoint if (codepoint <= 0x7f) { utf8[0] = (char)codepoint; - length = 1; + size = 1; } else if (codepoint <= 0x7ff) { utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0); utf8[1] = (char)((codepoint & 0x3f) | 0x80); - length = 2; + size = 2; } else if (codepoint <= 0xffff) { utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0); utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80); utf8[2] = (char)((codepoint & 0x3f) | 0x80); - length = 3; + size = 3; } else if (codepoint <= 0x10ffff) { @@ -1458,10 +1458,10 @@ RLAPI const char *CodepointToUTF8(int codepoint, int *byteLength) utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80); utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80); utf8[3] = (char)((codepoint & 0x3f) | 0x80); - length = 4; + size = 4; } - *byteLength = length; + *byteSize = size; return utf8; } @@ -1502,7 +1502,7 @@ void UnloadCodepoints(int *codepoints) // NOTE: If an invalid UTF-8 sequence is encountered a '?'(0x3f) codepoint is counted instead int GetCodepointCount(const char *text) { - unsigned int len = 0; + unsigned int length = 0; char *ptr = (char *)&text[0]; while (*ptr != '\0') @@ -1513,10 +1513,10 @@ int GetCodepointCount(const char *text) if (letter == 0x3f) ptr += 1; else ptr += next; - len++; + length++; } - return len; + return length; } #endif // SUPPORT_TEXT_MANIPULATION diff --git a/src/textures.c b/src/textures.c index 41a0a077b..6caaa5bb8 100644 --- a/src/textures.c +++ b/src/textures.c @@ -547,7 +547,7 @@ bool ExportImageAsCode(Image image, const char *fileName) for (int i = 0; i < dataSize - 1; i++) byteCount += sprintf(txtData + byteCount, ((i%TEXT_BYTES_PER_LINE == 0)? "0x%x,\n" : "0x%x, "), ((unsigned char *)image.data)[i]); byteCount += sprintf(txtData + byteCount, "0x%x };\n", ((unsigned char *)image.data)[dataSize - 1]); - // NOTE: Text data length exported is determined by '\0' (NULL) character + // NOTE: Text data size exported is determined by '\0' (NULL) character success = SaveFileText(fileName, txtData); RL_FREE(txtData); @@ -1147,7 +1147,7 @@ Image ImageText(const char *text, int fontSize, Color color) // Create an image from text (custom sprite font) Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Color tint) { - int length = (int)strlen(text); + int size = (int)strlen(text); // Get size in bytes of text int textOffsetX = 0; // Image drawing position X int textOffsetY = 0; // Offset between lines (on line break '\n') @@ -1158,7 +1158,7 @@ Image ImageTextEx(Font font, const char *text, float fontSize, float spacing, Co // Create image to store text Image imText = GenImageColor((int)imSize.x, (int)imSize.y, BLANK); - for (int i = 0; i < length; i++) + for (int i = 0; i < size; i++) { // Get next codepoint from byte string and glyph index in font int codepointByteCount = 0; From 59e7275464f9323a617a0f8ce30a5b69746a1915 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 2 Sep 2021 00:35:55 +0200 Subject: [PATCH 11/59] REVIEWED: Glyphs --- examples/text/text_draw_3d.c | 41 ++++++++++++++--------------------- examples/text/text_font_sdf.c | 20 ++++++++--------- 2 files changed, 26 insertions(+), 35 deletions(-) diff --git a/examples/text/text_draw_3d.c b/examples/text/text_draw_3d.c index 04b6e18ca..a140b1194 100644 --- a/examples/text/text_draw_3d.c +++ b/examples/text/text_draw_3d.c @@ -454,16 +454,16 @@ void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontS // Character destination rectangle on screen // NOTE: We consider charsPadding on drawing - position.x += (float)(font.chars[index].offsetX - font.charsPadding)/(float)font.baseSize*scale; - position.z += (float)(font.chars[index].offsetY - font.charsPadding)/(float)font.baseSize*scale; + position.x += (float)(font.glyphs[index].offsetX - font.glyphPadding)/(float)font.baseSize*scale; + position.z += (float)(font.glyphs[index].offsetY - font.glyphPadding)/(float)font.baseSize*scale; // Character source rectangle from font texture atlas // NOTE: We consider chars padding when drawing, it could be required for outline/glow shader effects - Rectangle srcRec = { font.recs[index].x - (float)font.charsPadding, font.recs[index].y - (float)font.charsPadding, - font.recs[index].width + 2.0f*font.charsPadding, font.recs[index].height + 2.0f*font.charsPadding }; + Rectangle srcRec = { font.recs[index].x - (float)font.glyphPadding, font.recs[index].y - (float)font.glyphPadding, + font.recs[index].width + 2.0f*font.glyphPadding, font.recs[index].height + 2.0f*font.glyphPadding }; - float width = (float)(font.recs[index].width + 2.0f*font.charsPadding)/(float)font.baseSize*scale; - float height = (float)(font.recs[index].height + 2.0f*font.charsPadding)/(float)font.baseSize*scale; + float width = (float)(font.recs[index].width + 2.0f*font.glyphPadding)/(float)font.baseSize*scale; + float height = (float)(font.recs[index].height + 2.0f*font.glyphPadding)/(float)font.baseSize*scale; if (font.texture.id > 0) { @@ -477,16 +477,11 @@ void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontS const float tw = (srcRec.x+srcRec.width)/font.texture.width; const float th = (srcRec.y+srcRec.height)/font.texture.height; - if (SHOW_LETTER_BOUNDRY) - DrawCubeWiresV((Vector3){ position.x + width/2, position.y, position.z + height/2}, (Vector3){ width, LETTER_BOUNDRY_SIZE, height }, LETTER_BOUNDRY_COLOR); + if (SHOW_LETTER_BOUNDRY) DrawCubeWiresV((Vector3){ position.x + width/2, position.y, position.z + height/2}, (Vector3){ width, LETTER_BOUNDRY_SIZE, height }, LETTER_BOUNDRY_COLOR); -#if defined(RAYLIB_NEW_RLGL) rlCheckRenderBatchLimit(4 + 4*backface); rlSetTexture(font.texture.id); -#else - if (rlCheckBufferLimit(4 + 4*backface)) rlglDraw(); - rlEnableTexture(font.texture.id); -#endif + rlPushMatrix(); rlTranslatef(position.x, position.y, position.z); @@ -512,11 +507,7 @@ void DrawTextCodepoint3D(Font font, int codepoint, Vector3 position, float fontS rlEnd(); rlPopMatrix(); -#if defined(RAYLIB_NEW_RLGL) rlSetTexture(0); -#else - rlDisableTexture(); -#endif } } @@ -554,8 +545,8 @@ void DrawText3D(Font font, const char *text, Vector3 position, float fontSize, f DrawTextCodepoint3D(font, codepoint, (Vector3){ position.x + textOffsetX, position.y, position.z + textOffsetY }, fontSize, backface, tint); } - if (font.chars[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale; - else textOffsetX += (float)(font.chars[index].advanceX + fontSpacing)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale; + else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)/(float)font.baseSize*scale; } i += codepointByteCount; // Move text bytes counter to next codepoint @@ -592,8 +583,8 @@ Vector3 MeasureText3D(Font font, const char* text, float fontSize, float fontSpa if (letter != '\n') { - if (font.chars[index].advanceX != 0) textWidth += (font.chars[index].advanceX+fontSpacing)/(float)font.baseSize*scale; - else textWidth += (font.recs[index].width + font.chars[index].offsetX)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)/(float)font.baseSize*scale; + else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)/(float)font.baseSize*scale; } else { @@ -670,8 +661,8 @@ void DrawTextWave3D(Font font, const char *text, Vector3 position, float fontSiz DrawTextCodepoint3D(font, codepoint, (Vector3){ pos.x + textOffsetX, pos.y, pos.z + textOffsetY }, fontSize, backface, tint); } - if (font.chars[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale; - else textOffsetX += (float)(font.chars[index].advanceX + fontSpacing)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX == 0) textOffsetX += (float)(font.recs[index].width + fontSpacing)/(float)font.baseSize*scale; + else textOffsetX += (float)(font.glyphs[index].advanceX + fontSpacing)/(float)font.baseSize*scale; } i += codepointByteCount; // Move text bytes counter to next codepoint @@ -714,8 +705,8 @@ Vector3 MeasureTextWave3D(Font font, const char* text, float fontSize, float fon } else { - if (font.chars[index].advanceX != 0) textWidth += (font.chars[index].advanceX+fontSpacing)/(float)font.baseSize*scale; - else textWidth += (font.recs[index].width + font.chars[index].offsetX)/(float)font.baseSize*scale; + if (font.glyphs[index].advanceX != 0) textWidth += (font.glyphs[index].advanceX+fontSpacing)/(float)font.baseSize*scale; + else textWidth += (font.recs[index].width + font.glyphs[index].offsetX)/(float)font.baseSize*scale; } } else diff --git a/examples/text/text_font_sdf.c b/examples/text/text_font_sdf.c index 7de7986b3..8a2c0d773 100644 --- a/examples/text/text_font_sdf.c +++ b/examples/text/text_font_sdf.c @@ -39,24 +39,24 @@ int main(void) // Default font generation from TTF font Font fontDefault = { 0 }; fontDefault.baseSize = 16; - fontDefault.charsCount = 95; + fontDefault.glyphCount = 95; // Loading font data from memory data - // Parameters > font size: 16, no chars array provided (0), chars count: 95 (autogenerate chars array) - fontDefault.chars = LoadFontData(fileData, fileSize, 16, 0, 95, FONT_DEFAULT); - // Parameters > chars count: 95, font size: 16, chars padding in image: 4 px, pack method: 0 (default) - Image atlas = GenImageFontAtlas(fontDefault.chars, &fontDefault.recs, 95, 16, 4, 0); + // Parameters > font size: 16, no glyphs array provided (0), glyphs count: 95 (autogenerate chars array) + fontDefault.glyphs = LoadFontData(fileData, fileSize, 16, 0, 95, FONT_DEFAULT); + // Parameters > glyphs count: 95, font size: 16, glyphs padding in image: 4 px, pack method: 0 (default) + Image atlas = GenImageFontAtlas(fontDefault.glyphs, &fontDefault.recs, 95, 16, 4, 0); fontDefault.texture = LoadTextureFromImage(atlas); UnloadImage(atlas); // SDF font generation from TTF font Font fontSDF = { 0 }; fontSDF.baseSize = 16; - fontSDF.charsCount = 95; - // Parameters > font size: 16, no chars array provided (0), chars count: 0 (defaults to 95) - fontSDF.chars = LoadFontData(fileData, fileSize, 16, 0, 0, FONT_SDF); - // Parameters > chars count: 95, font size: 16, chars padding in image: 0 px, pack method: 1 (Skyline algorythm) - atlas = GenImageFontAtlas(fontSDF.chars, &fontSDF.recs, 95, 16, 0, 1); + fontSDF.glyphCount = 95; + // Parameters > font size: 16, no glyphs array provided (0), glyphs count: 0 (defaults to 95) + fontSDF.glyphs = LoadFontData(fileData, fileSize, 16, 0, 0, FONT_SDF); + // Parameters > glyphs count: 95, font size: 16, glyphs padding in image: 0 px, pack method: 1 (Skyline algorythm) + atlas = GenImageFontAtlas(fontSDF.glyphs, &fontSDF.recs, 95, 16, 0, 1); fontSDF.texture = LoadTextureFromImage(atlas); UnloadImage(atlas); From 9ff8ad853c77453768c59b5f9ae5206ec63f1bdb Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 2 Sep 2021 00:39:47 +0200 Subject: [PATCH 12/59] Update raygui.h --- src/extras/raygui.h | 379 +++++++++++++++++++++++--------------------- 1 file changed, 196 insertions(+), 183 deletions(-) diff --git a/src/extras/raygui.h b/src/extras/raygui.h index 31b7ca774..5aada37e4 100644 --- a/src/extras/raygui.h +++ b/src/extras/raygui.h @@ -220,14 +220,20 @@ int format; // Data format (PixelFormat type) } Texture2D; - // Font character info - typedef struct GlyphInfo GlyphInfo; + // GlyphInfo, font characters glyphs info + typedef struct GlyphInfo { + int value; // Character value (Unicode) + int offsetX; // Character offset X when drawing + int offsetY; // Character offset Y when drawing + int advanceX; // Character advance position X + Image image; // Character image data + } GlyphInfo; // TODO: Font type is very coupled to raylib, mostly required by GuiLoadStyle() // It should be redesigned to be provided by user typedef struct Font { int baseSize; // Base size (default chars height) - int charsCount; // Number of characters + int glyphCount; // Number of characters Texture2D texture; // Characters texture atlas Rectangle *recs; // Characters rectangles in texture GlyphInfo *chars; // Characters info data @@ -406,7 +412,7 @@ typedef enum { extern "C" { // Prevents name mangling of functions #endif -// State modification functions +// Global gui state control functions RAYGUIDEF void GuiEnable(void); // Enable gui controls (global state) RAYGUIDEF void GuiDisable(void); // Disable gui controls (global state) RAYGUIDEF void GuiLock(void); // Lock gui controls (global state) @@ -1067,7 +1073,7 @@ static unsigned int guiIcons[RICON_MAX_ICONS*RICON_DATA_ELEMENTS] = { #endif // RAYGUI_SUPPORT_RICONS #ifndef RICON_SIZE - #define RICON_SIZE 0 + #define RICON_SIZE 0 #endif #define RAYGUI_MAX_CONTROLS 16 // Maximum number of standard controls @@ -1076,7 +1082,7 @@ static unsigned int guiIcons[RICON_MAX_ICONS*RICON_DATA_ELEMENTS] = { // TODO: Avoid animations and time-based states // Functions using it: GuiTextBox(), GuiValueBox(), GuiTextBoxMulti() -#define TEXTEDIT_CURSOR_BLINK_FRAMES 20 // Text edit controls cursor blink timming +//#define TEXTEDIT_CURSOR_BLINK_FRAMES 20 // Text edit controls cursor blink timming //---------------------------------------------------------------------------------- // Types and Structures Definition @@ -1147,14 +1153,14 @@ static Font GetFontDefault(void); // -- GuiLoadStyleDe static Vector2 MeasureTextEx(Font font, const char *text, float fontSize, float spacing); // -- GetTextWidth(), GuiTextBoxMulti() static void DrawTextEx(Font font, const char *text, Vector2 position, float fontSize, float spacing, Color tint); // -- GuiDrawText() -static Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int charsCount); // -- GuiLoadStyle() +static Font LoadFontEx(const char *fileName, int fontSize, int *fontChars, int glyphCount); // -- GuiLoadStyle() static char *LoadFileText(const char *fileName); // -- GuiLoadStyle() static const char *GetDirectoryPath(const char *filePath); // -- GuiLoadStyle() //------------------------------------------------------------------------------- // raylib functions already implemented in raygui //------------------------------------------------------------------------------- -static Color GetColor(unsigned int hexValue); // Returns a Color struct from hexadecimal value +static Color GetColor(int hexValue); // Returns a Color struct from hexadecimal value static int ColorToInt(Color color); // Returns hexadecimal value for a Color static Color Fade(Color color, float alpha); // Color fade-in or fade-out, alpha goes from 0.0f to 1.0f static bool CheckCollisionPointRec(Vector2 point, Rectangle rec); // Check if point is inside rectangle @@ -1594,7 +1600,7 @@ bool GuiImageButtonEx(Rectangle bounds, const char *text, Texture2D texture, Rec //-------------------------------------------------------------------- GuiDrawRectangle(bounds, GuiGetStyle(BUTTON, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(BUTTON, BORDER + (state*3))), guiAlpha), Fade(GetColor(GuiGetStyle(BUTTON, BASE + (state*3))), guiAlpha)); - if (text != NULL) GuiDrawText(text, GetTextBounds(BUTTON, bounds), GuiGetStyle(BUTTON, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(BUTTON, TEXT + (state*3))), guiAlpha)); + GuiDrawText(text, GetTextBounds(BUTTON, bounds), GuiGetStyle(BUTTON, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(BUTTON, TEXT + (state*3))), guiAlpha)); if (texture.id > 0) DrawTextureRec(texture, texSource, RAYGUI_CLITERAL(Vector2){ bounds.x + bounds.width/2 - texSource.width/2, bounds.y + bounds.height/2 - texSource.height/2 }, Fade(GetColor(GuiGetStyle(BUTTON, TEXT + (state*3))), guiAlpha)); //------------------------------------------------------------------ @@ -1654,12 +1660,12 @@ int GuiToggleGroup(Rectangle bounds, const char *text, int active) // Get substrings items from text (items pointers) int rows[TOGGLEGROUP_MAX_ELEMENTS] = { 0 }; - int itemsCount = 0; - const char **items = GuiTextSplit(text, &itemsCount, rows); + int itemCount = 0; + const char **items = GuiTextSplit(text, &itemCount, rows); int prevRow = rows[0]; - for (int i = 0; i < itemsCount; i++) + for (int i = 0; i < itemCount; i++) { if (prevRow != rows[i]) { @@ -1730,7 +1736,7 @@ bool GuiCheckBox(Rectangle bounds, const char *text, bool checked) GuiDrawRectangle(check, 0, BLANK, Fade(GetColor(GuiGetStyle(CHECKBOX, TEXT + state*3)), guiAlpha)); } - if (text != NULL) GuiDrawText(text, textBounds, (GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == GUI_TEXT_ALIGN_RIGHT)? GUI_TEXT_ALIGN_LEFT : GUI_TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); + GuiDrawText(text, textBounds, (GuiGetStyle(CHECKBOX, TEXT_ALIGNMENT) == GUI_TEXT_ALIGN_RIGHT)? GUI_TEXT_ALIGN_LEFT : GUI_TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); //-------------------------------------------------------------------- return checked; @@ -1747,15 +1753,15 @@ int GuiComboBox(Rectangle bounds, const char *text, int active) (float)bounds.y, (float)GuiGetStyle(COMBOBOX, COMBO_BUTTON_WIDTH), (float)bounds.height }; // Get substrings items from text (items pointers, lengths and count) - int itemsCount = 0; - const char **items = GuiTextSplit(text, &itemsCount, NULL); + int itemCount = 0; + const char **items = GuiTextSplit(text, &itemCount, NULL); if (active < 0) active = 0; - else if (active > itemsCount - 1) active = itemsCount - 1; + else if (active > itemCount - 1) active = itemCount - 1; // Update control //-------------------------------------------------------------------- - if ((state != GUI_STATE_DISABLED) && !guiLocked && (itemsCount > 1)) + if ((state != GUI_STATE_DISABLED) && !guiLocked && (itemCount > 1)) { Vector2 mousePoint = GetMousePosition(); @@ -1765,7 +1771,7 @@ int GuiComboBox(Rectangle bounds, const char *text, int active) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { active += 1; - if (active >= itemsCount) active = 0; + if (active >= itemCount) active = 0; } if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) state = GUI_STATE_PRESSED; @@ -1787,7 +1793,7 @@ int GuiComboBox(Rectangle bounds, const char *text, int active) GuiSetStyle(BUTTON, BORDER_WIDTH, 1); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER); - GuiButton(selector, TextFormat("%i/%i", active + 1, itemsCount)); + GuiButton(selector, TextFormat("%i/%i", active + 1, itemCount)); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, tempTextAlign); GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth); @@ -1805,11 +1811,11 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo int itemFocused = -1; // Get substrings items from text (items pointers, lengths and count) - int itemsCount = 0; - const char **items = GuiTextSplit(text, &itemsCount, NULL); + int itemCount = 0; + const char **items = GuiTextSplit(text, &itemCount, NULL); Rectangle boundsOpen = bounds; - boundsOpen.height = (itemsCount + 1)*(bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_PADDING)); + boundsOpen.height = (itemCount + 1)*(bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_PADDING)); Rectangle itemBounds = bounds; @@ -1817,7 +1823,7 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo // Update control //-------------------------------------------------------------------- - if ((state != GUI_STATE_DISABLED) && !guiLocked && (itemsCount > 1)) + if ((state != GUI_STATE_DISABLED) && !guiLocked && (itemCount > 1)) { Vector2 mousePoint = GetMousePosition(); @@ -1835,7 +1841,7 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo if (CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; // Check focused and selected item - for (int i = 0; i < itemsCount; i++) + for (int i = 0; i < itemCount; i++) { // Update item rectangle y position for next item itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_PADDING)); @@ -1879,7 +1885,7 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo if (editMode) { // Draw visible items - for (int i = 0; i < itemsCount; i++) + for (int i = 0; i < itemCount; i++) { // Update item rectangle y position for next item itemBounds.y += (bounds.height + GuiGetStyle(DROPDOWNBOX, DROPDOWN_ITEMS_PADDING)); @@ -1913,19 +1919,16 @@ bool GuiDropdownBox(Rectangle bounds, const char *text, int *active, bool editMo } // Text Box control, updates input text -// NOTE 1: Requires static variables: framesCounter // NOTE 2: Returns if KEY_ENTER pressed (useful for data validation) bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) { - static int framesCounter = 0; // Blinking cursor counter - GuiControlState state = guiState; bool pressed = false; Rectangle cursor = { bounds.x + GuiGetStyle(TEXTBOX, TEXT_PADDING) + GetTextWidth(text) + 2, bounds.y + bounds.height/2 - GuiGetStyle(DEFAULT, TEXT_SIZE), - 1, + 4, (float)GuiGetStyle(DEFAULT, TEXT_SIZE)*2 }; @@ -1938,8 +1941,7 @@ bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) if (editMode) { state = GUI_STATE_PRESSED; - framesCounter++; - + int key = GetCharPressed(); // Returns codepoint as Unicode int keyCount = (int)strlen(text); @@ -1950,10 +1952,10 @@ bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) if ((GetTextWidth(text) < (maxWidth - GuiGetStyle(DEFAULT, TEXT_SIZE))) && (key >= 32)) { - int byteLength = 0; - const char *textUTF8 = CodepointToUTF8(key, &byteLength); + int byteSize = 0; + const char *textUTF8 = CodepointToUTF8(key, &byteSize); - for (int i = 0; i < byteLength; i++) + for (int i = 0; i < byteSize; i++) { text[keyCount] = textUTF8[i]; keyCount++; @@ -1970,13 +1972,6 @@ bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) { keyCount--; text[keyCount] = '\0'; - framesCounter = 0; - if (keyCount < 0) keyCount = 0; - } - else if (IsKeyDown(KEY_BACKSPACE)) - { - if ((framesCounter > TEXTEDIT_CURSOR_BLINK_FRAMES) && (framesCounter%2) == 0) keyCount--; - text[keyCount] = '\0'; if (keyCount < 0) keyCount = 0; } } @@ -1996,8 +1991,6 @@ bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; } } - - if (pressed) framesCounter = 0; } //-------------------------------------------------------------------- @@ -2006,9 +1999,6 @@ bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) if (state == GUI_STATE_PRESSED) { GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), guiAlpha), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_PRESSED)), guiAlpha)); - - // Draw blinking cursor - if (editMode && ((framesCounter/20)%2 == 0)) GuiDrawRectangle(cursor, 0, BLANK, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha)); } else if (state == GUI_STATE_DISABLED) { @@ -2017,6 +2007,9 @@ bool GuiTextBox(Rectangle bounds, char *text, int textSize, bool editMode) else GuiDrawRectangle(bounds, 1, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), guiAlpha), BLANK); GuiDrawText(text, GetTextBounds(TEXTBOX, bounds), GuiGetStyle(TEXTBOX, TEXT_ALIGNMENT), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))), guiAlpha)); + + // Draw cursor + if (editMode) GuiDrawRectangle(cursor, 0, BLANK, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha)); //-------------------------------------------------------------------- return pressed; @@ -2090,7 +2083,7 @@ bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, in GuiSetStyle(BUTTON, BORDER_WIDTH, tempBorderWidth); // Draw text label if provided - if (text != NULL) GuiDrawText(text, textBounds, (GuiGetStyle(SPINNER, TEXT_ALIGNMENT) == GUI_TEXT_ALIGN_RIGHT)? GUI_TEXT_ALIGN_LEFT : GUI_TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); + GuiDrawText(text, textBounds, (GuiGetStyle(SPINNER, TEXT_ALIGNMENT) == GUI_TEXT_ALIGN_RIGHT)? GUI_TEXT_ALIGN_LEFT : GUI_TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); //-------------------------------------------------------------------- *value = tempValue; @@ -2098,15 +2091,13 @@ bool GuiSpinner(Rectangle bounds, const char *text, int *value, int minValue, in } // Value Box control, updates input text with numbers -// NOTE: Requires static variables: framesCounter +// NOTE: Requires static variables: frameCounter bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, int maxValue, bool editMode) { #if !defined(VALUEBOX_MAX_CHARS) #define VALUEBOX_MAX_CHARS 32 #endif - static int framesCounter = 0; // Blinking cursor counter - GuiControlState state = guiState; bool pressed = false; @@ -2135,8 +2126,6 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i { state = GUI_STATE_PRESSED; - framesCounter++; - int keyCount = (int)strlen(textValue); // Only allow keys in range [48..57] @@ -2161,14 +2150,6 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i { keyCount--; textValue[keyCount] = '\0'; - framesCounter = 0; - if (keyCount < 0) keyCount = 0; - valueHasChanged = true; - } - else if (IsKeyDown(KEY_BACKSPACE)) - { - if ((framesCounter > TEXTEDIT_CURSOR_BLINK_FRAMES) && (framesCounter%2) == 0) keyCount--; - textValue[keyCount] = '\0'; if (keyCount < 0) keyCount = 0; valueHasChanged = true; } @@ -2189,8 +2170,6 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; } } - - if (pressed) framesCounter = 0; } //-------------------------------------------------------------------- @@ -2204,16 +2183,16 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i GuiDrawRectangle(bounds, GuiGetStyle(VALUEBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(VALUEBOX, BORDER + (state*3))), guiAlpha), baseColor); GuiDrawText(textValue, GetTextBounds(VALUEBOX, bounds), GUI_TEXT_ALIGN_CENTER, Fade(GetColor(GuiGetStyle(VALUEBOX, TEXT + (state*3))), guiAlpha)); - // Draw blinking cursor - if ((state == GUI_STATE_PRESSED) && (editMode && ((framesCounter/20)%2 == 0))) + // Draw cursor + if (editMode) { // NOTE: ValueBox internal text is always centered - Rectangle cursor = { bounds.x + GetTextWidth(textValue)/2 + bounds.width/2 + 2, bounds.y + 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), 1, bounds.height - 4*GuiGetStyle(VALUEBOX, BORDER_WIDTH) }; + Rectangle cursor = { bounds.x + GetTextWidth(textValue)/2 + bounds.width/2 + 2, bounds.y + 2*GuiGetStyle(VALUEBOX, BORDER_WIDTH), 4, bounds.height - 4*GuiGetStyle(VALUEBOX, BORDER_WIDTH) }; GuiDrawRectangle(cursor, 0, BLANK, Fade(GetColor(GuiGetStyle(VALUEBOX, BORDER_COLOR_PRESSED)), guiAlpha)); } // Draw text label if provided - if (text != NULL) GuiDrawText(text, textBounds, (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == GUI_TEXT_ALIGN_RIGHT)? GUI_TEXT_ALIGN_LEFT : GUI_TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); + GuiDrawText(text, textBounds, (GuiGetStyle(VALUEBOX, TEXT_ALIGNMENT) == GUI_TEXT_ALIGN_RIGHT)? GUI_TEXT_ALIGN_LEFT : GUI_TEXT_ALIGN_RIGHT, Fade(GetColor(GuiGetStyle(LABEL, TEXT + (state*3))), guiAlpha)); //-------------------------------------------------------------------- return pressed; @@ -2222,8 +2201,6 @@ bool GuiValueBox(Rectangle bounds, const char *text, int *value, int minValue, i // Text Box control with multiple lines bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) { - static int framesCounter = 0; // Blinking cursor counter - GuiControlState state = guiState; bool pressed = false; @@ -2235,10 +2212,9 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) }; // Cursor position, [x, y] values should be updated - Rectangle cursor = { 0, 0, 1, (float)GuiGetStyle(DEFAULT, TEXT_SIZE) + 2 }; - - int textWidth = 0; - int currentLine = 0; + Rectangle cursor = { 0, -1, 4, (float)GuiGetStyle(DEFAULT, TEXT_SIZE) + 2 }; + + float scaleFactor = (float)GuiGetStyle(DEFAULT, TEXT_SIZE)/(float)guiFont.baseSize; // Character rectangle scaling factor // Update control //-------------------------------------------------------------------- @@ -2249,77 +2225,52 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) if (editMode) { state = GUI_STATE_PRESSED; - framesCounter++; - int character = GetCharPressed(); - int keyCount = (int)strlen(text); + // We get an Unicode codepoint + int codepoint = GetCharPressed(); + int textLength = (int)strlen(text); // Length in bytes (UTF-8 string) // Introduce characters - if (keyCount < (textSize - 1)) + if (textLength < (textSize - 1)) { - Vector2 textSize = MeasureTextEx(guiFont, text, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), (float)GuiGetStyle(DEFAULT, TEXT_SPACING)); - - if (textSize.y < (textAreaBounds.height - GuiGetStyle(DEFAULT, TEXT_SIZE))) + if (IsKeyPressed(KEY_ENTER)) { - if (IsKeyPressed(KEY_ENTER)) - { - text[keyCount] = '\n'; - keyCount++; - } - else if (((character >= 32) && (character < 255))) // TODO: Support Unicode inputs - { - text[keyCount] = (char)character; - keyCount++; - } + text[textLength] = '\n'; + textLength++; + } + else if (codepoint >= 32) + { + // Supports Unicode inputs -> Encoded to UTF-8 + int charUTF8Length = 0; + const char *charEncoded = CodepointToUTF8(codepoint, &charUTF8Length); + memcpy(text + textLength, charEncoded, charUTF8Length); + textLength += charUTF8Length; } } // Delete characters - if (keyCount > 0) + if (textLength > 0) { if (IsKeyPressed(KEY_BACKSPACE)) { - keyCount--; - text[keyCount] = '\0'; - framesCounter = 0; - - if (keyCount < 0) keyCount = 0; - } - else if (IsKeyDown(KEY_BACKSPACE)) - { - if ((framesCounter > TEXTEDIT_CURSOR_BLINK_FRAMES) && (framesCounter%2) == 0) keyCount--; - text[keyCount] = '\0'; - - if (keyCount < 0) keyCount = 0; + if ((unsigned char)text[textLength - 1] < 127) + { + // Remove ASCII equivalent character (1 byte) + textLength--; + text[textLength] = '\0'; + } + else + { + // Remove latest UTF-8 unicode character introduced (n bytes) + int charUTF8Length = 0; + while (((unsigned char)text[textLength - 1 - charUTF8Length] & 0b01000000) == 0) charUTF8Length++; + + textLength -= (charUTF8Length + 1); + text[textLength] = '\0'; + } } } - // Calculate cursor position considering text - char oneCharText[2] = { 0 }; - int lastBreakingPos = -1; - - for (int i = 0; i < keyCount && currentLine < keyCount; i++) - { - oneCharText[0] = text[i]; - textWidth += (GetTextWidth(oneCharText) + GuiGetStyle(DEFAULT, TEXT_SPACING)); - - if (text[i] == ' ' || text[i] == '\n') lastBreakingPos = i; - - if ( text[i] == '\n' || textWidth >= textAreaBounds.width) - { - currentLine++; - textWidth = 0; - - if (lastBreakingPos > 0) i = lastBreakingPos; - else textWidth += (GetTextWidth(oneCharText) + GuiGetStyle(DEFAULT, TEXT_SPACING)); - - lastBreakingPos = -1; - } - } - - cursor.x = bounds.x + GuiGetStyle(TEXTBOX, BORDER_WIDTH) + GuiGetStyle(TEXTBOX, TEXT_INNER_PADDING) + textWidth - GuiGetStyle(DEFAULT, TEXT_SPACING); - cursor.y = bounds.y + GuiGetStyle(TEXTBOX, BORDER_WIDTH) + GuiGetStyle(TEXTBOX, TEXT_INNER_PADDING)/2 + ((GuiGetStyle(DEFAULT, TEXT_SIZE) + GuiGetStyle(TEXTBOX, TEXT_INNER_PADDING))*currentLine); - // Exit edit mode if (!CheckCollisionPointRec(mousePoint, bounds) && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; } @@ -2331,8 +2282,6 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) pressed = true; } } - - if (pressed) framesCounter = 0; // Reset blinking cursor } //-------------------------------------------------------------------- @@ -2341,9 +2290,6 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) if (state == GUI_STATE_PRESSED) { GuiDrawRectangle(bounds, GuiGetStyle(TEXTBOX, BORDER_WIDTH), Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), guiAlpha), Fade(GetColor(GuiGetStyle(TEXTBOX, BASE_COLOR_PRESSED)), guiAlpha)); - - // Draw blinking cursor - if (editMode && ((framesCounter/20)%2 == 0)) GuiDrawRectangle(cursor, 0, BLANK, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha)); } else if (state == GUI_STATE_DISABLED) { @@ -2351,9 +2297,76 @@ bool GuiTextBoxMulti(Rectangle bounds, char *text, int textSize, bool editMode) } else GuiDrawRectangle(bounds, 1, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER + (state*3))), guiAlpha), BLANK); - // TODO: Review to support boxed text with word-wrap - //DrawTextBoxed(guiFont, text, textAreaBounds, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), (float)GuiGetStyle(DEFAULT, TEXT_SPACING), true, Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))), guiAlpha)); - DrawTextEx(guiFont, text, (Vector2){ textAreaBounds.x, textAreaBounds.y }, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), (float)GuiGetStyle(DEFAULT, TEXT_SPACING), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))), guiAlpha)); + int wrapMode = 1; // 0-No wrap, 1-Char wrap, 2-Word wrap + Vector2 cursorPos = { textAreaBounds.x, textAreaBounds.y }; + + //int lastSpacePos = 0; + //int lastSpaceWidth = 0; + //int lastSpaceCursorPos = 0; + + for (int i = 0, codepointLength = 0; text[i] != '\0'; i += codepointLength) + { + int codepoint = GetCodepoint(text + i, &codepointLength); + int index = GetGlyphIndex(guiFont, codepoint); // If requested codepoint is not found, we get '?' (0x3f) -> TODO: review that case! + Rectangle atlasRec = guiFont.recs[index]; + GlyphInfo glyphInfo = guiFont.glyphs[index]; // Glyph measures + + if ((codepointLength == 1) && (codepoint == '\n')) + { + cursorPos.y += (guiFont.baseSize*scaleFactor + GuiGetStyle(TEXTBOX, TEXT_LINES_PADDING)); // Line feed + cursorPos.x = textAreaBounds.x; // Carriage return + } + else + { + if (wrapMode == 1) + { + int glyphWidth = 0; + if (glyphInfo.advanceX != 0) glyphWidth += glyphInfo.advanceX; + else glyphWidth += (atlasRec.width + glyphInfo.offsetX); + + // Jump line if the end of the text box area has been reached + if ((cursorPos.x + (glyphWidth*scaleFactor)) > (textAreaBounds.x + textAreaBounds.width)) + { + cursorPos.y += (guiFont.baseSize*scaleFactor + GuiGetStyle(TEXTBOX, TEXT_LINES_PADDING)); // Line feed + cursorPos.x = textAreaBounds.x; // Carriage return + } + } + else if (wrapMode == 2) + { + /* + if ((codepointLength == 1) && (codepoint == ' ')) + { + lastSpacePos = i; + lastSpaceWidth = 0; + lastSpaceCursorPos = cursorPos.x; + } + + // Jump line if last word reaches end of text box area + if ((lastSpaceCursorPos + lastSpaceWidth) > (textAreaBounds.x + textAreaBounds.width)) + { + cursorPos.y += 12; // Line feed + cursorPos.x = textAreaBounds.x; // Carriage return + } + */ + } + + // Draw current character glyph + DrawTextCodepoint(guiFont, codepoint, cursorPos, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), Fade(GetColor(GuiGetStyle(TEXTBOX, TEXT + (state*3))), guiAlpha)); + + int glyphWidth = 0; + if (glyphInfo.advanceX != 0) glyphWidth += glyphInfo.advanceX; + else glyphWidth += (atlasRec.width + glyphInfo.offsetX); + + cursorPos.x += (glyphWidth*scaleFactor + (float)GuiGetStyle(DEFAULT, TEXT_SPACING)); + //if (i > lastSpacePos) lastSpaceWidth += (atlasRec.width + (float)GuiGetStyle(DEFAULT, TEXT_SPACING)); + } + } + + cursor.x = cursorPos.x; + cursor.y = cursorPos.y; + + // Draw cursor position considering text glyphs + if (editMode) GuiDrawRectangle(cursor, 0, BLANK, Fade(GetColor(GuiGetStyle(TEXTBOX, BORDER_COLOR_PRESSED)), guiAlpha)); //-------------------------------------------------------------------- return pressed; @@ -2698,12 +2711,12 @@ int GuiScrollBar(Rectangle bounds, int value, int minValue, int maxValue) // List View control int GuiListView(Rectangle bounds, const char *text, int *scrollIndex, int active) { - int itemsCount = 0; + int itemCount = 0; const char **items = NULL; - if (text != NULL) items = GuiTextSplit(text, &itemsCount, NULL); + if (text != NULL) items = GuiTextSplit(text, &itemCount, NULL); - return GuiListViewEx(bounds, items, itemsCount, NULL, scrollIndex, active); + return GuiListViewEx(bounds, items, itemCount, NULL, scrollIndex, active); } // List View control with extended parameters @@ -3096,12 +3109,12 @@ int GuiMessageBox(Rectangle bounds, const char *title, const char *message, cons int clicked = -1; // Returns clicked button from buttons list, 0 refers to closed window button - int buttonsCount = 0; - const char **buttonsText = GuiTextSplit(buttons, &buttonsCount, NULL); + int buttonCount = 0; + const char **buttonsText = GuiTextSplit(buttons, &buttonCount, NULL); Rectangle buttonBounds = { 0 }; buttonBounds.x = bounds.x + MESSAGEBOX_BUTTON_PADDING; buttonBounds.y = bounds.y + bounds.height - MESSAGEBOX_BUTTON_HEIGHT - MESSAGEBOX_BUTTON_PADDING; - buttonBounds.width = (bounds.width - MESSAGEBOX_BUTTON_PADDING*(buttonsCount + 1))/buttonsCount; + buttonBounds.width = (bounds.width - MESSAGEBOX_BUTTON_PADDING*(buttonCount + 1))/buttonCount; buttonBounds.height = MESSAGEBOX_BUTTON_HEIGHT; Vector2 textSize = MeasureTextEx(guiFont, message, (float)GuiGetStyle(DEFAULT, TEXT_SIZE), 1); @@ -3124,7 +3137,7 @@ int GuiMessageBox(Rectangle bounds, const char *title, const char *message, cons prevTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER); - for (int i = 0; i < buttonsCount; i++) + for (int i = 0; i < buttonCount; i++) { if (GuiButton(buttonBounds, buttonsText[i])) clicked = i + 1; buttonBounds.x += (buttonBounds.width + MESSAGEBOX_BUTTON_PADDING); @@ -3151,12 +3164,12 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co int btnIndex = -1; - int buttonsCount = 0; - const char **buttonsText = GuiTextSplit(buttons, &buttonsCount, NULL); + int buttonCount = 0; + const char **buttonsText = GuiTextSplit(buttons, &buttonCount, NULL); Rectangle buttonBounds = { 0 }; buttonBounds.x = bounds.x + TEXTINPUTBOX_BUTTON_PADDING; buttonBounds.y = bounds.y + bounds.height - TEXTINPUTBOX_BUTTON_HEIGHT - TEXTINPUTBOX_BUTTON_PADDING; - buttonBounds.width = (bounds.width - TEXTINPUTBOX_BUTTON_PADDING*(buttonsCount + 1))/buttonsCount; + buttonBounds.width = (bounds.width - TEXTINPUTBOX_BUTTON_PADDING*(buttonCount + 1))/buttonCount; buttonBounds.height = TEXTINPUTBOX_BUTTON_HEIGHT; int messageInputHeight = (int)bounds.height - WINDOW_STATUSBAR_HEIGHT - GuiGetStyle(STATUSBAR, BORDER_WIDTH) - TEXTINPUTBOX_BUTTON_HEIGHT - 2*TEXTINPUTBOX_BUTTON_PADDING; @@ -3198,7 +3211,7 @@ int GuiTextInputBox(Rectangle bounds, const char *title, const char *message, co int prevBtnTextAlignment = GuiGetStyle(BUTTON, TEXT_ALIGNMENT); GuiSetStyle(BUTTON, TEXT_ALIGNMENT, GUI_TEXT_ALIGN_CENTER); - for (int i = 0; i < buttonsCount; i++) + for (int i = 0; i < buttonCount; i++) { if (GuiButton(buttonBounds, buttonsText[i])) btnIndex = i + 1; buttonBounds.x += (buttonBounds.width + MESSAGEBOX_BUTTON_PADDING); @@ -3322,20 +3335,20 @@ void GuiLoadStyle(const char *fileName) char *charValues = LoadFileText(charmapFileName); if (charValues != NULL) { - int charsCount = 0; - const char **chars = TextSplit(charValues, '\n', &charsCount); + int glyphCount = 0; + const char **chars = TextSplit(charValues, '\n', &glyphCount); - int *values = (int *)RAYGUI_MALLOC(charsCount*sizeof(int)); - for (int i = 0; i < charsCount; i++) values[i] = TextToInteger(chars[i]); + int *values = (int *)RAYGUI_MALLOC(glyphCount*sizeof(int)); + for (int i = 0; i < glyphCount; i++) values[i] = TextToInteger(chars[i]); - font = LoadFontEx(TextFormat("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, values, charsCount); + font = LoadFontEx(TextFormat("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, values, glyphCount); RAYGUI_FREE(values); } } else font = LoadFontEx(TextFormat("%s/%s", GetDirectoryPath(fileName), fontFileName), fontSize, NULL, 0); - if ((font.texture.id > 0) && (font.charsCount > 0)) GuiSetFont(font); + if ((font.texture.id > 0) && (font.glyphCount > 0)) GuiSetFont(font); } break; default: break; @@ -3358,12 +3371,12 @@ void GuiLoadStyle(const char *fileName) char signature[5] = ""; short version = 0; short reserved = 0; - int propertiesCount = 0; + int propertyCount = 0; fread(signature, 1, 4, rgsFile); fread(&version, 1, sizeof(short), rgsFile); fread(&reserved, 1, sizeof(short), rgsFile); - fread(&propertiesCount, 1, sizeof(int), rgsFile); + fread(&propertyCount, 1, sizeof(int), rgsFile); if ((signature[0] == 'r') && (signature[1] == 'G') && @@ -3374,7 +3387,7 @@ void GuiLoadStyle(const char *fileName) short propertyId = 0; int propertyValue = 0; - for (int i = 0; i < propertiesCount; i++) + for (int i = 0; i < propertyCount; i++) { fread(&controlId, 1, sizeof(short), rgsFile); fread(&propertyId, 1, sizeof(short), rgsFile); @@ -3405,7 +3418,7 @@ void GuiLoadStyle(const char *fileName) Rectangle whiteRec = { 0 }; fread(&font.baseSize, 1, sizeof(int), rgsFile); - fread(&font.charsCount, 1, sizeof(int), rgsFile); + fread(&font.glyphCount, 1, sizeof(int), rgsFile); fread(&fontType, 1, sizeof(int), rgsFile); // Load font white rectangle @@ -3432,17 +3445,17 @@ void GuiLoadStyle(const char *fileName) } // Load font recs data - font.recs = (Rectangle *)RAYGUI_CALLOC(font.charsCount, sizeof(Rectangle)); - for (int i = 0; i < font.charsCount; i++) fread(&font.recs[i], 1, sizeof(Rectangle), rgsFile); + font.recs = (Rectangle *)RAYGUI_CALLOC(font.glyphCount, sizeof(Rectangle)); + for (int i = 0; i < font.glyphCount; i++) fread(&font.recs[i], 1, sizeof(Rectangle), rgsFile); // Load font chars info data - font.chars = (GlyphInfo *)RAYGUI_CALLOC(font.charsCount, sizeof(GlyphInfo)); - for (int i = 0; i < font.charsCount; i++) + font.glyphs = (GlyphInfo *)RAYGUI_CALLOC(font.glyphCount, sizeof(GlyphInfo)); + for (int i = 0; i < font.glyphCount; i++) { - fread(&font.chars[i].value, 1, sizeof(int), rgsFile); - fread(&font.chars[i].offsetX, 1, sizeof(int), rgsFile); - fread(&font.chars[i].offsetY, 1, sizeof(int), rgsFile); - fread(&font.chars[i].advanceX, 1, sizeof(int), rgsFile); + fread(&font.glyphs[i].value, 1, sizeof(int), rgsFile); + fread(&font.glyphs[i].offsetX, 1, sizeof(int), rgsFile); + fread(&font.glyphs[i].offsetY, 1, sizeof(int), rgsFile); + fread(&font.glyphs[i].advanceX, 1, sizeof(int), rgsFile); } GuiSetFont(font); @@ -3572,7 +3585,7 @@ unsigned int *GuiGetIcons(void) { return guiIcons; } // Load raygui icons file (.rgi) // NOTE: In case nameIds are required, they can be requested with loadIconsName, -// they are returned as a guiIconsName[iconsCount][RICON_MAX_NAME_LENGTH], +// they are returned as a guiIconsName[iconCount][RICON_MAX_NAME_LENGTH], // guiIconsName[]][] memory should be manually freed! char **GuiLoadIcons(const char *fileName, bool loadIconsName) { @@ -3609,14 +3622,14 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName) char signature[5] = ""; short version = 0; short reserved = 0; - short iconsCount = 0; - short iconsSize = 0; + short iconCount = 0; + short iconSize = 0; fread(signature, 1, 4, rgiFile); fread(&version, 1, sizeof(short), rgiFile); fread(&reserved, 1, sizeof(short), rgiFile); - fread(&iconsCount, 1, sizeof(short), rgiFile); - fread(&iconsSize, 1, sizeof(short), rgiFile); + fread(&iconCount, 1, sizeof(short), rgiFile); + fread(&iconSize, 1, sizeof(short), rgiFile); if ((signature[0] == 'r') && (signature[1] == 'G') && @@ -3625,17 +3638,17 @@ char **GuiLoadIcons(const char *fileName, bool loadIconsName) { if (loadIconsName) { - guiIconsName = (char **)RAYGUI_MALLOC(iconsCount*sizeof(char **)); - for (int i = 0; i < iconsCount; i++) + guiIconsName = (char **)RAYGUI_MALLOC(iconCount*sizeof(char **)); + for (int i = 0; i < iconCount; i++) { guiIconsName[i] = (char *)RAYGUI_MALLOC(RICON_MAX_NAME_LENGTH); fread(guiIconsName[i], RICON_MAX_NAME_LENGTH, 1, rgiFile); } } - else fseek(rgiFile, iconsCount*RICON_MAX_NAME_LENGTH, SEEK_CUR); + else fseek(rgiFile, iconCount*RICON_MAX_NAME_LENGTH, SEEK_CUR); // Read icons data directly over guiIcons data array - fread(guiIcons, iconsCount*(iconsSize*iconsSize/32), sizeof(unsigned int), rgiFile); + fread(guiIcons, iconCount*(iconSize*iconSize/32), sizeof(unsigned int), rgiFile); } fclose(rgiFile); @@ -4061,7 +4074,7 @@ static Vector3 ConvertHSVtoRGB(Vector3 hsv) #if defined(RAYGUI_STANDALONE) // Returns a Color struct from hexadecimal value -static Color GetColor(unsigned int hexValue) +static Color GetColor(int hexValue) { Color color; @@ -4186,29 +4199,29 @@ static int TextToInteger(const char *text) return value*sign; } -// Encode codepoint into UTF-8 text (char array length returned as parameter) -static const char *CodepointToUTF8(int codepoint, int *byteLength) +// Encode codepoint into UTF-8 text (char array size returned as parameter) +static const char *CodepointToUTF8(int codepoint, int *byteSize) { static char utf8[6] = { 0 }; - int length = 0; + int size = 0; if (codepoint <= 0x7f) { utf8[0] = (char)codepoint; - length = 1; + size = 1; } else if (codepoint <= 0x7ff) { utf8[0] = (char)(((codepoint >> 6) & 0x1f) | 0xc0); utf8[1] = (char)((codepoint & 0x3f) | 0x80); - length = 2; + size = 2; } else if (codepoint <= 0xffff) { utf8[0] = (char)(((codepoint >> 12) & 0x0f) | 0xe0); utf8[1] = (char)(((codepoint >> 6) & 0x3f) | 0x80); utf8[2] = (char)((codepoint & 0x3f) | 0x80); - length = 3; + size = 3; } else if (codepoint <= 0x10ffff) { @@ -4216,10 +4229,10 @@ static const char *CodepointToUTF8(int codepoint, int *byteLength) utf8[1] = (char)(((codepoint >> 12) & 0x3f) | 0x80); utf8[2] = (char)(((codepoint >> 6) & 0x3f) | 0x80); utf8[3] = (char)((codepoint & 0x3f) | 0x80); - length = 4; + size = 4; } - *byteLength = length; + *byteSize = size; return utf8; } From 93168304cd377fabec9dfa88469f2cc635cd6326 Mon Sep 17 00:00:00 2001 From: raysan5 Date: Fri, 3 Sep 2021 15:24:05 +0200 Subject: [PATCH 13/59] Update shell.html --- src/shell.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/shell.html b/src/shell.html index aa0210c32..31714f473 100644 --- a/src/shell.html +++ b/src/shell.html @@ -192,7 +192,8 @@ jwE50AGjLCVuS8Yt4H7OgZLKK5EKOsLviEWJSL/+0uMi7gLUSBseYwqEbXvSHCec1CJvZPyHCmYQffaB