mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-28 05:58:30 +00:00
Added LoadText() function
Actually, renamed ReadTextFile() from rlgl and make it public
This commit is contained in:
@@ -925,6 +925,7 @@ RLAPI RayHitInfo GetCollisionRayGround(Ray ray, float groundHeight);
|
|||||||
// Shaders System Functions (Module: rlgl)
|
// Shaders System Functions (Module: rlgl)
|
||||||
// NOTE: This functions are useless when using OpenGL 1.1
|
// 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 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)
|
RLAPI void UnloadShader(Shader shader); // Unload shader from GPU memory (VRAM)
|
||||||
|
|
||||||
|
76
src/rlgl.c
76
src/rlgl.c
@@ -48,7 +48,7 @@
|
|||||||
|
|
||||||
#include "rlgl.h"
|
#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 <stdlib.h> // Required for: malloc(), free(), rand()
|
||||||
#include <string.h> // Required for: strcmp(), strlen(), strtok()
|
#include <string.h> // Required for: strcmp(), strlen(), strtok()
|
||||||
#include <math.h> // Required for: atan2()
|
#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 GetShaderLightsLocations(Shader shader); // Get shader locations for lights (up to MAX_LIGHTS)
|
||||||
static void SetShaderLightsValues(Shader shader); // Set shader uniform values for 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
|
#endif
|
||||||
|
|
||||||
#if defined(RLGL_OCULUS_SUPPORT)
|
#if defined(RLGL_OCULUS_SUPPORT)
|
||||||
@@ -2423,6 +2421,40 @@ Texture2D GetDefaultTexture(void)
|
|||||||
return texture;
|
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
|
// Load shader from files and bind default locations
|
||||||
Shader LoadShader(char *vsFileName, char *fsFileName)
|
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)
|
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
// Shaders loading from external text file
|
// Shaders loading from external text file
|
||||||
char *vShaderStr = ReadTextFile(vsFileName);
|
char *vShaderStr = LoadText(vsFileName);
|
||||||
char *fShaderStr = ReadTextFile(fsFileName);
|
char *fShaderStr = LoadText(fsFileName);
|
||||||
|
|
||||||
if ((vShaderStr != NULL) && (fShaderStr != NULL))
|
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
|
// Configure stereo rendering (including distortion shader) with HMD device parameters
|
||||||
static void SetStereoConfig(VrDeviceInfo hmd)
|
static void SetStereoConfig(VrDeviceInfo hmd)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user