aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorraysan5 <raysan5@gmail.com>2017-01-15 01:09:15 +0100
committerraysan5 <raysan5@gmail.com>2017-01-15 01:09:15 +0100
commit4a158d972d9d110fcb581bc9f6583d05a2dc2544 (patch)
tree105a2bee1c5483df1be5c55d51f2bbf33b763ff8 /src
parent4ea8494f3e03440d0d67db8a3fa77ac50a4b1a36 (diff)
downloadraylib-4a158d972d9d110fcb581bc9f6583d05a2dc2544.tar.gz
raylib-4a158d972d9d110fcb581bc9f6583d05a2dc2544.zip
Added LoadText() function
Actually, renamed ReadTextFile() from rlgl and make it public
Diffstat (limited to 'src')
-rw-r--r--src/raylib.h1
-rw-r--r--src/rlgl.c76
2 files changed, 38 insertions, 39 deletions
diff --git a/src/raylib.h b/src/raylib.h
index fa4f44e6..a47d3c59 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -925,6 +925,7 @@ RLAPI RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight);
// Shaders System Functions (Module: rlgl)
// NOTE: This functions are useless when using OpenGL 1.1
//------------------------------------------------------------------------------------
+RLAPI char *LoadText(const char *fileName); // Load chars array from text file
RLAPI Shader LoadShader(char *vsFileName, char *fsFileName); // Load shader from files and bind default locations
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)
diff --git a/src/rlgl.c b/src/rlgl.c
index 9770b647..bcbca227 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -48,7 +48,7 @@
#include "rlgl.h"
-#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on ReadTextFile()]
+#include <stdio.h> // Required for: fopen(), fclose(), fread()... [Used only on LoadText()]
#include <stdlib.h> // Required for: malloc(), free(), rand()
#include <string.h> // Required for: strcmp(), strlen(), strtok()
#include <math.h> // Required for: atan2()
@@ -400,8 +400,6 @@ static void SetStereoView(int eye, Matrix matProjection, Matrix matModelView);
static void GetShaderLightsLocations(Shader shader); // Get shader locations for lights (up to MAX_LIGHTS)
static void SetShaderLightsValues(Shader shader); // Set shader uniform values for lights
-
-static char *ReadTextFile(const char *fileName); // Read chars array from text file
#endif
#if defined(RLGL_OCULUS_SUPPORT)
@@ -2423,6 +2421,40 @@ Texture2D GetDefaultTexture(void)
return texture;
}
+// Load text data from file
+// NOTE: text chars array should be freed manually
+char *LoadText(const char *fileName)
+{
+ FILE *textFile;
+ char *text = NULL;
+
+ int count = 0;
+
+ if (fileName != NULL)
+ {
+ textFile = fopen(fileName,"rt");
+
+ if (textFile != NULL)
+ {
+ fseek(textFile, 0, SEEK_END);
+ count = ftell(textFile);
+ rewind(textFile);
+
+ if (count > 0)
+ {
+ text = (char *)malloc(sizeof(char)*(count + 1));
+ count = fread(text, sizeof(char), count, textFile);
+ text[count] = '\0';
+ }
+
+ fclose(textFile);
+ }
+ else TraceLog(WARNING, "[%s] Text file could not be opened", fileName);
+ }
+
+ return text;
+}
+
// Load shader from files and bind default locations
Shader LoadShader(char *vsFileName, char *fsFileName)
{
@@ -2430,8 +2462,8 @@ Shader LoadShader(char *vsFileName, char *fsFileName)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Shaders loading from external text file
- char *vShaderStr = ReadTextFile(vsFileName);
- char *fShaderStr = ReadTextFile(fsFileName);
+ char *vShaderStr = LoadText(vsFileName);
+ char *fShaderStr = LoadText(fsFileName);
if ((vShaderStr != NULL) && (fShaderStr != NULL))
{
@@ -3829,40 +3861,6 @@ static void SetShaderLightsValues(Shader shader)
}
}
-// Read text data from file
-// NOTE: text chars array should be freed manually
-static char *ReadTextFile(const char *fileName)
-{
- FILE *textFile;
- char *text = NULL;
-
- int count = 0;
-
- if (fileName != NULL)
- {
- textFile = fopen(fileName,"rt");
-
- if (textFile != NULL)
- {
- fseek(textFile, 0, SEEK_END);
- count = ftell(textFile);
- rewind(textFile);
-
- if (count > 0)
- {
- text = (char *)malloc(sizeof(char)*(count + 1));
- count = fread(text, sizeof(char), count, textFile);
- text[count] = '\0';
- }
-
- fclose(textFile);
- }
- else TraceLog(WARNING, "[%s] Text file could not be opened", fileName);
- }
-
- return text;
-}
-
// Configure stereo rendering (including distortion shader) with HMD device parameters
static void SetStereoConfig(VrDeviceInfo hmd)
{