aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/camera.c2
-rw-r--r--src/core.c20
-rw-r--r--src/makefile4
-rw-r--r--src/models.c42
-rw-r--r--src/raylib.h3
-rw-r--r--src/raymath.c2
-rw-r--r--src/raymath.h2
-rw-r--r--src/rlgl.c200
-rw-r--r--src/text.c4
-rw-r--r--src/textures.c13
-rw-r--r--src/utils.h2
11 files changed, 155 insertions, 139 deletions
diff --git a/src/camera.c b/src/camera.c
index b637b1e4..f2ac3275 100644
--- a/src/camera.c
+++ b/src/camera.c
@@ -514,4 +514,4 @@ static void ProcessCamera(Camera *camera, Vector3 *playerPosition)
} break;
default: break;
}
-} \ No newline at end of file
+}
diff --git a/src/core.c b/src/core.c
index 1ebc8a8f..6b56ea88 100644
--- a/src/core.c
+++ b/src/core.c
@@ -1024,7 +1024,7 @@ static void InitDisplay(int width, int height)
if (configFlags & FLAG_MSAA_4X_HINT)
{
glfwWindowHint(GLFW_SAMPLES, 4); // Enables multisampling x4 (MSAA), default is 0
- TraceLog(INFO, "Enabled MSAA x4");
+ TraceLog(INFO, "Trying to enable MSAA x4");
}
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); // Choose OpenGL major version (just hint)
@@ -1115,6 +1115,7 @@ static void InitDisplay(int width, int height)
{
samples = 4;
sampleBuffer = 1;
+ TraceLog(INFO, "Trying to enable MSAA x4");
}
const EGLint framebufferAttribs[] =
@@ -1627,7 +1628,7 @@ static void PollInputEvents(void)
else if (key == 0x7f) currentKeyState[259] = 1;
else
{
- TraceLog(INFO, "Pressed key (ASCII): 0x%02x", key);
+ TraceLog(DEBUG, "Pressed key (ASCII): 0x%02x", key);
currentKeyState[key] = 1;
}
@@ -1637,7 +1638,7 @@ static void PollInputEvents(void)
}
else if (keyboardMode == 1)
{
- TraceLog(INFO, "Pressed key (keycode): 0x%02x", key);
+ TraceLog(DEBUG, "Pressed key (keycode): 0x%02x", key);
int asciiKey = -1;
@@ -1724,7 +1725,7 @@ static void InitMouse(void)
// Mouse reading thread
// NOTE: We need a separate thread to avoid loosing mouse events,
-// if too much time passes between reads, queue gets full and new events override older wants...
+// if too much time passes between reads, queue gets full and new events override older ones...
static void *MouseThread(void *arg)
{
struct input_event mouseEvent;
@@ -1807,8 +1808,12 @@ static void InitKeyboard(void)
}
else
{
- // We reconfigure keyboard mode to get scancodes (K_RAW) or keycodes (K_MEDIUMRAW)
- ioctl(STDIN_FILENO, KDSKBMODE, K_MEDIUMRAW); // ASCII chars (K_XLATE), UNICODE chars (K_UNICODE)
+ // We reconfigure keyboard mode to get:
+ // - scancodes (K_RAW)
+ // - keycodes (K_MEDIUMRAW)
+ // - ASCII chars (K_XLATE)
+ // - UNICODE chars (K_UNICODE)
+ ioctl(STDIN_FILENO, KDSKBMODE, K_MEDIUMRAW);
keyboardMode = 1; // keycodes
}
@@ -1820,7 +1825,10 @@ static void InitKeyboard(void)
// Restore default keyboard input
static void RestoreKeyboard(void)
{
+ // Reset to default keyboard settings
tcsetattr(STDIN_FILENO, TCSANOW, &defaultKeyboardSettings);
+
+ // Reconfigure keyboard to default mode
ioctl(STDIN_FILENO, KDSKBMODE, defaultKeyboardMode);
}
diff --git a/src/makefile b/src/makefile
index 67123a9a..da57c2d2 100644
--- a/src/makefile
+++ b/src/makefile
@@ -2,7 +2,7 @@
#
# raylib makefile for desktop platforms, Raspberry Pi and HTML5 (emscripten)
#
-# Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+# Copyright (c) 2014 Ramon Santamaria (@raysan5)
#
# This software is provided "as-is", without any express or implied warranty. In no event
# will the authors be held liable for any damages arising from the use of this software.
@@ -80,7 +80,7 @@ endif
# define any directories containing required header files
ifeq ($(PLATFORM),PLATFORM_RPI)
- INCLUDES = -I. -I/opt/vc/include -I/opt/vc/include/interface/vcos/pthreads
+ INCLUDES = -I. -I/opt/vc/include -I/opt/vc/include/interface/vmcs_host/linux -I/opt/vc/include/interface/vcos/pthreads
else
INCLUDES = -I. -I../src
# external libraries headers
diff --git a/src/models.c b/src/models.c
index 054febcf..4943aa5e 100644
--- a/src/models.c
+++ b/src/models.c
@@ -584,6 +584,7 @@ Model LoadModel(const char *fileName)
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
+ free(vData.colors);
}
}
@@ -619,10 +620,10 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
vData.vertexCount = numTriangles*3;
- vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
- vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
- vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
- vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char)); // Not used...
+ vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
+ vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
+ vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
+ vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char)); // Not used...
int vCounter = 0; // Used to count vertices float by float
int tcCounter = 0; // Used to count texcoords float by float
@@ -722,6 +723,7 @@ Model LoadHeightmap(Image heightmap, float maxHeight)
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
+ free(vData.colors);
}
return model;
@@ -1038,10 +1040,10 @@ Model LoadCubicmap(Image cubicmap)
// Move data from mapVertices temp arays to vertices float array
vData.vertexCount = vCounter;
- vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
- vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
- vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
- vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char)); // Not used...
+ vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
+ vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
+ vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
+ vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char)); // Not used...
// Fill color data
// NOTE: Not used any more... just one plain color defined at DrawModel()
@@ -1096,6 +1098,7 @@ Model LoadCubicmap(Image cubicmap)
free(vData.vertices);
free(vData.texcoords);
free(vData.normals);
+ free(vData.colors);
}
return model;
@@ -1117,7 +1120,8 @@ void UnloadModel(Model model)
rlDeleteVertexArrays(model.mesh.vaoId);
- TraceLog(INFO, "Unloaded model data");
+ if (model.mesh.vaoId > 0) TraceLog(INFO, "[VAO ID %i] Unloaded model data from VRAM (GPU)", model.mesh.vaoId);
+ else TraceLog(INFO, "[VBO ID %i][VBO ID %i][VBO ID %i] Unloaded model data from VRAM (GPU)", model.mesh.vboId[0], model.mesh.vboId[1], model.mesh.vboId[2]);
}
// Link a texture to a model
@@ -1718,16 +1722,16 @@ static VertexData LoadOBJ(const char *fileName)
vData.vertexCount = numTriangles*3;
// Additional arrays to store vertex data as floats
- vData.vertices = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
- vData.texcoords = (float *)malloc(vData.vertexCount * 2 * sizeof(float));
- vData.normals = (float *)malloc(vData.vertexCount * 3 * sizeof(float));
- vData.colors = (unsigned char *)malloc(vData.vertexCount * 4 * sizeof(unsigned char));
+ vData.vertices = (float *)malloc(vData.vertexCount*3*sizeof(float));
+ vData.texcoords = (float *)malloc(vData.vertexCount*2*sizeof(float));
+ vData.normals = (float *)malloc(vData.vertexCount*3*sizeof(float));
+ vData.colors = (unsigned char *)malloc(vData.vertexCount*4*sizeof(unsigned char));
int vCounter = 0; // Used to count vertices float by float
int tcCounter = 0; // Used to count texcoords float by float
int nCounter = 0; // Used to count normals float by float
- int vNum[3], vtNum[3], vnNum[3];
+ int vNum[3], vtNum[3], vnNum[3]; // Used to store triangle indices for v, vt, vn
rewind(objFile); // Return to the beginning of the file, to read again
@@ -1799,14 +1803,16 @@ static VertexData LoadOBJ(const char *fileName)
if (numTexCoords > 0)
{
+ // NOTE: If using negative texture coordinates with a texture filter of GL_CLAMP_TO_EDGE doesn't work!
+ // NOTE: Texture coordinates are Y flipped upside-down
vData.texcoords[tcCounter] = midTexCoords[vtNum[0]-1].x;
- vData.texcoords[tcCounter + 1] = -midTexCoords[vtNum[0]-1].y;
+ vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[0]-1].y;
tcCounter += 2;
vData.texcoords[tcCounter] = midTexCoords[vtNum[1]-1].x;
- vData.texcoords[tcCounter + 1] = -midTexCoords[vtNum[1]-1].y;
+ vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[1]-1].y;
tcCounter += 2;
vData.texcoords[tcCounter] = midTexCoords[vtNum[2]-1].x;
- vData.texcoords[tcCounter + 1] = -midTexCoords[vtNum[2]-1].y;
+ vData.texcoords[tcCounter + 1] = 1.0f - midTexCoords[vtNum[2]-1].y;
tcCounter += 2;
}
} break;
@@ -1818,7 +1824,7 @@ static VertexData LoadOBJ(const char *fileName)
// Security check, just in case no normals or no texcoords defined in OBJ
if (numTexCoords == 0) for (int i = 0; i < (2*vData.vertexCount); i++) vData.texcoords[i] = 0.0f;
-
+
// NOTE: We set all vertex colors to white
// NOTE: Not used any more... just one plain color defined at DrawModel()
for (int i = 0; i < (4*vData.vertexCount); i++) vData.colors[i] = 255;
diff --git a/src/raylib.h b/src/raylib.h
index bf5fe99f..b14ae082 100644
--- a/src/raylib.h
+++ b/src/raylib.h
@@ -614,7 +614,8 @@ void DrawBillboardRec(Camera camera, Texture2D texture, Rectangle sourceRec, Vec
bool CheckCollisionSpheres(Vector3 centerA, float radiusA, Vector3 centerB, float radiusB); // Detect collision between two spheres
bool CheckCollisionBoxes(Vector3 minBBox1, Vector3 maxBBox1, Vector3 minBBox2, Vector3 maxBBox2); // Detect collision between two boxes
bool CheckCollisionBoxSphere(Vector3 minBBox, Vector3 maxBBox, Vector3 centerSphere, float radiusSphere); // Detect collision between box and sphere
-Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Return the normal vector of the impacted surface
+Vector3 ResolveCollisionCubicmap(Image cubicmap, Vector3 mapPosition, Vector3 *playerPosition, float radius); // Detect collision of player radius with cubicmap
+ // NOTE: Return the normal vector of the impacted surface
//------------------------------------------------------------------------------------
// Shaders System Functions (Module: rlgl)
diff --git a/src/raymath.c b/src/raymath.c
index f5e30833..b1f90bb8 100644
--- a/src/raymath.c
+++ b/src/raymath.c
@@ -4,7 +4,7 @@
*
* Some useful functions to work with Vector3, Matrix and Quaternions
*
-* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/raymath.h b/src/raymath.h
index d93c324c..e140b74c 100644
--- a/src/raymath.h
+++ b/src/raymath.h
@@ -4,7 +4,7 @@
*
* Some useful functions to work with Vector3, Matrix and Quaternions
*
-* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2015 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.
diff --git a/src/rlgl.c b/src/rlgl.c
index 8806b429..ec23e988 100644
--- a/src/rlgl.c
+++ b/src/rlgl.c
@@ -283,14 +283,24 @@ static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight);
static pixel *GenNextMipmap(pixel *srcData, int srcWidth, int srcHeight);
#endif
-#if defined(GRAPHICS_API_OPENGL_ES2)
-static char** StringSplit(char *baseString, const char delimiter, int *numExt);
-#endif
-
#if defined(RLGL_STANDALONE)
static void TraceLog(int msgType, const char *text, ...);
#endif
+#if defined(GRAPHICS_API_OPENGL_ES2)
+// NOTE: strdup() functions replacement (not C99, POSIX function, not available on emscripten)
+// Duplicates a string, returning an identical malloc'd string
+char *mystrdup(const char *str)
+{
+ size_t len = strlen(str) + 1;
+ void *newstr = malloc(len);
+
+ if (newstr == NULL) return NULL;
+
+ return (char *)memcpy(newstr, str, len);
+}
+#endif
+
//----------------------------------------------------------------------------------
// Module Functions Definition - Matrix operations
//----------------------------------------------------------------------------------
@@ -863,7 +873,7 @@ void rlglInit(void)
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Get supported extensions list
- GLint numExt;
+ GLint numExt = 0;
#if defined(GRAPHICS_API_OPENGL_33)
@@ -923,21 +933,39 @@ void rlglInit(void)
// NOTE: We don't need to check again supported extensions but we do (in case GLEW is replaced sometime)
// We get a list of available extensions and we check for some of them (compressed textures)
glGetIntegerv(GL_NUM_EXTENSIONS, &numExt);
- const char *ext[numExt];
+ const char *extList[numExt];
- for (int i = 0; i < numExt; i++) ext[i] = (char *)glGetStringi(GL_EXTENSIONS, i);
+ for (int i = 0; i < numExt; i++) extList[i] = (char *)glGetStringi(GL_EXTENSIONS, i);
#elif defined(GRAPHICS_API_OPENGL_ES2)
- char *extensions = (char *)glGetString(GL_EXTENSIONS); // One big string
+ char *extensions = (char *)glGetString(GL_EXTENSIONS); // One big const string
+
+ // NOTE: We have to duplicate string because glGetString() returns a const value
+ // If not duplicated, it fails in some systems (Raspberry Pi)
+ char *extensionsDup = mystrdup(extensions);
// NOTE: String could be splitted using strtok() function (string.h)
- char **ext = StringSplit(extensions, ' ', &numExt);
+ // NOTE: strtok() modifies the received string, it can not be const
+
+ char *extList[512]; // Allocate 512 strings pointers (2 KB)
+
+ extList[numExt] = strtok(extensionsDup, " ");
+
+ while (extList[numExt] != NULL)
+ {
+ numExt++;
+ extList[numExt] = strtok(NULL, " ");
+ }
+
+ free(extensionsDup); // Duplicated string must be deallocated
+
+ numExt -= 1;
#endif
TraceLog(INFO, "Number of supported extensions: %i", numExt);
// Show supported extensions
- //for (int i = 0; i < numExt; i++) TraceLog(INFO, "Supported extension: %s", ext[i]);
+ //for (int i = 0; i < numExt; i++) TraceLog(INFO, "Supported extension: %s", extList[i]);
// Check required extensions
for (int i = 0; i < numExt; i++)
@@ -945,7 +973,7 @@ void rlglInit(void)
#if defined(GRAPHICS_API_OPENGL_ES2)
// Check VAO support
// NOTE: Only check on OpenGL ES, OpenGL 3.3 has VAO support as core feature
- if (strcmp(ext[i], (const char *)"GL_OES_vertex_array_object") == 0)
+ if (strcmp(extList[i], (const char *)"GL_OES_vertex_array_object") == 0)
{
vaoSupported = true;
@@ -959,23 +987,23 @@ void rlglInit(void)
// Check NPOT textures support
// NOTE: Only check on OpenGL ES, OpenGL 3.3 has NPOT textures full support as core feature
- if (strcmp(ext[i], (const char *)"GL_OES_texture_npot") == 0) npotSupported = true;
+ if (strcmp(extList[i], (const char *)"GL_OES_texture_npot") == 0) npotSupported = true;
#endif
// DDS texture compression support
- if (strcmp(ext[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) texCompDXTSupported = true;
+ if (strcmp(extList[i], (const char *)"GL_EXT_texture_compression_s3tc") == 0) texCompDXTSupported = true;
// ETC1 texture compression support
- if (strcmp(ext[i], (const char *)"GL_OES_compressed_ETC1_RGB8_texture") == 0) texCompETC1Supported = true;
+ if (strcmp(extList[i], (const char *)"GL_OES_compressed_ETC1_RGB8_texture") == 0) texCompETC1Supported = true;
// ETC2/EAC texture compression support
- if (strcmp(ext[i], (const char *)"GL_ARB_ES3_compatibility") == 0) texCompETC2Supported = true;
+ if (strcmp(extList[i], (const char *)"GL_ARB_ES3_compatibility") == 0) texCompETC2Supported = true;
// PVR texture compression support
- if (strcmp(ext[i], (const char *)"GL_IMG_texture_compression_pvrtc") == 0) texCompPVRTSupported = true;
+ if (strcmp(extList[i], (const char *)"GL_IMG_texture_compression_pvrtc") == 0) texCompPVRTSupported = true;
// ASTC texture compression support
- if (strcmp(ext[i], (const char *)"GL_KHR_texture_compression_astc_hdr") == 0) texCompASTCSupported = true;
+ if (strcmp(extList[i], (const char *)"GL_KHR_texture_compression_astc_hdr") == 0) texCompASTCSupported = true;
}
#if defined(GRAPHICS_API_OPENGL_ES2)
@@ -984,9 +1012,6 @@ void rlglInit(void)
if (npotSupported) TraceLog(INFO, "[EXTENSION] NPOT textures extension detected, full NPOT textures supported");
else TraceLog(WARNING, "[EXTENSION] NPOT textures extension not found, NPOT textures not supported");
-
- // Once supported extensions have been checked, we should free strings memory
- free(ext);
#endif
if (texCompDXTSupported) TraceLog(INFO, "[EXTENSION] DXT compressed textures supported");
@@ -1008,8 +1033,16 @@ void rlglInit(void)
// Initialize matrix stack
for (int i = 0; i < MATRIX_STACK_SIZE; i++) stack[i] = MatrixIdentity();
+
+ // Create default white texture for plain colors (required by shader)
+ unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
+
+ whiteTexture = rlglLoadTexture(pixels, 1, 1, UNCOMPRESSED_R8G8B8A8, 1);
+
+ if (whiteTexture != 0) TraceLog(INFO, "[TEX ID %i] Base white texture loaded successfully", whiteTexture);
+ else TraceLog(WARNING, "Base white texture could not be loaded");
- // Init default Shader (GLSL 110) -> Common for GL 3.3+ and ES2
+ // Init default Shader (Custom for GL 3.3 and ES2)
defaultShader = LoadDefaultShader();
simpleShader = LoadSimpleShader();
//customShader = LoadShader("custom.vs", "custom.fs"); // Works ok
@@ -1024,14 +1057,6 @@ void rlglInit(void)
for (int i = 0; i < TEMP_VERTEX_BUFFER_SIZE; i++) tempBuffer[i] = VectorZero();
- // Create default white texture for plain colors (required by shader)
- unsigned char pixels[4] = { 255, 255, 255, 255 }; // 1 pixel RGBA (4 bytes)
-
- whiteTexture = rlglLoadTexture(pixels, 1, 1, UNCOMPRESSED_R8G8B8A8, 1);
-
- if (whiteTexture != 0) TraceLog(INFO, "[TEX ID %i] Base white texture loaded successfully", whiteTexture);
- else TraceLog(WARNING, "Base white texture could not be loaded");
-
// Init draw calls tracking system
draws = (DrawCall *)malloc(sizeof(DrawCall)*MAX_DRAWS_BY_TEXTURE);
@@ -1189,6 +1214,7 @@ void rlglClose(void)
// Free GPU texture
glDeleteTextures(1, &whiteTexture);
+ TraceLog(INFO, "[TEX ID %i] Unloaded texture data (base white texture) from VRAM", whiteTexture);
if (fbo != 0)
{
@@ -1207,7 +1233,7 @@ void rlglClose(void)
rlDeleteVertexArrays(postproQuad.mesh.vaoId);
- TraceLog(INFO, "Unloaded postpro quad data");
+ TraceLog(INFO, "[FBO %i] Unloaded postprocessing data", fbo);
}
free(draws);
@@ -1768,8 +1794,17 @@ unsigned int rlglLoadTexture(void *data, int width, int height, int textureForma
// NOTE: glTexParameteri does NOT affect texture uploading, just the way it's used
#if defined(GRAPHICS_API_OPENGL_ES2)
// NOTE: OpenGL ES 2.0 with no GL_OES_texture_npot support (i.e. WebGL) has limited NPOT support, so CLAMP_TO_EDGE must be used
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Set texture to clamp on x-axis
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Set texture to clamp on y-axis
+ if (npotSupported)
+ {
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis
+ }
+ else
+ {
+ // NOTE: If using negative texture coordinates (LoadOBJ()), it does not work!
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); // Set texture to clamp on x-axis
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); // Set texture to clamp on y-axis
+ }
#else
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); // Set texture to repeat on x-axis
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); // Set texture to repeat on y-axis
@@ -1869,12 +1904,12 @@ Model rlglLoadModel(VertexData mesh)
model.mesh = mesh;
model.transform = MatrixIdentity();
-
-#if defined(GRAPHICS_API_OPENGL_11)
model.mesh.vaoId = 0; // Vertex Array Object
model.mesh.vboId[0] = 0; // Vertex position VBO
model.mesh.vboId[1] = 0; // Texcoords VBO
model.mesh.vboId[2] = 0; // Normals VBO
+
+#if defined(GRAPHICS_API_OPENGL_11)
model.texture.id = 0; // No texture required
model.shader.id = 0; // No shader used
@@ -1882,8 +1917,9 @@ Model rlglLoadModel(VertexData mesh)
model.texture.id = whiteTexture; // Default whiteTexture
model.texture.width = 1; // Default whiteTexture width
model.texture.height = 1; // Default whiteTexture height
+ model.texture.format = UNCOMPRESSED_R8G8B8A8; // Default whiteTexture format
model.shader = simpleShader; // Default model shader
-
+
GLuint vaoModel = 0; // Vertex Array Objects (VAO)
GLuint vertexBuffer[3]; // Vertex Buffer Objects (VBO)
@@ -2019,6 +2055,8 @@ void *rlglReadTexturePixels(unsigned int textureId, unsigned int format)
Shader LoadShader(char *vsFileName, char *fsFileName)
{
Shader shader;
+
+ shader.id = 0; // Default value in case of loading failure
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Shaders loading from external text file
@@ -2180,9 +2218,11 @@ unsigned int LoadShaderProgram(char *vShaderStr, char *fShaderStr)
// Unload a custom shader from memory
void UnloadShader(Shader shader)
{
- rlDeleteShader(shader.id);
-
- TraceLog(INFO, "[SHDR ID %i] Unloaded shader program data", shader.id);
+ if (shader.id != 0)
+ {
+ rlDeleteShader(shader.id);
+ TraceLog(INFO, "[SHDR ID %i] Unloaded shader program data", shader.id);
+ }
}
// Set custom shader to be used on batch draw
@@ -2242,7 +2282,7 @@ void SetPostproShader(Shader shader)
//TraceLog(DEBUG, "Postproquad shader diffuse map id: %i", postproQuad.shader.texDiffuseId);
//TraceLog(DEBUG, "Shader diffuse map id: %i", shader.texDiffuseId);
#elif defined(GRAPHICS_API_OPENGL_11)
- TraceLog(WARNING, "Postprocessing shaders not supported on OpenGL 1.1");
+ TraceLog(WARNING, "Shaders not supported on OpenGL 1.1");
#endif
}
@@ -2287,6 +2327,8 @@ void SetModelShader(Model *model, Shader shader)
// NOTE: If SetModelTexture() is called previously, texture is not assigned to new shader
if (model->texture.id > 0) model->shader.texDiffuseId = model->texture.id;
+#elif (GRAPHICS_API_OPENGL_11)
+ TraceLog(WARNING, "Shaders not supported on OpenGL 1.1");
#endif
}
@@ -2527,14 +2569,14 @@ static Shader LoadDefaultShader(void)
// Vertex shader directly defined, no external file required
#if defined(GRAPHICS_API_OPENGL_33)
- char vShaderStr[] = " #version 330 \n"
+ char vShaderStr[] = "#version 330 \n"
"in vec3 vertexPosition; \n"
"in vec2 vertexTexCoord; \n"
"in vec4 vertexColor; \n"
"out vec2 fragTexCoord; \n"
"out vec4 tintColor; \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
- char vShaderStr[] = " #version 100 \n"
+ char vShaderStr[] = "#version 100 \n"
"attribute vec3 vertexPosition; \n"
"attribute vec2 vertexTexCoord; \n"
"attribute vec4 vertexColor; \n"
@@ -2552,11 +2594,11 @@ static Shader LoadDefaultShader(void)
// Fragment shader directly defined, no external file required
#if defined(GRAPHICS_API_OPENGL_33)
- char fShaderStr[] = " #version 330 \n"
+ char fShaderStr[] = "#version 330 \n"
"in vec2 fragTexCoord; \n"
"in vec4 tintColor; \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
- char fShaderStr[] = " #version 100 \n"
+ char fShaderStr[] = "#version 100 \n"
"precision mediump float; \n" // precision required for OpenGL ES2 (WebGL)
"varying vec2 fragTexCoord; \n"
"varying vec4 tintColor; \n"
@@ -2590,6 +2632,10 @@ static Shader LoadDefaultShader(void)
shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
shader.mapNormalLoc = -1; // It can be set later
shader.mapSpecularLoc = -1; // It can be set later
+
+ shader.texDiffuseId = whiteTexture; // Default white texture
+ shader.texNormalId = 0;
+ shader.texSpecularId = 0;
//--------------------------------------------------------------------
return shader;
@@ -2607,13 +2653,13 @@ static Shader LoadSimpleShader(void)
// Vertex shader directly defined, no external file required
#if defined(GRAPHICS_API_OPENGL_33)
- char vShaderStr[] = " #version 330 \n"
+ char vShaderStr[] = "#version 330 \n"
"in vec3 vertexPosition; \n"
"in vec2 vertexTexCoord; \n"
"in vec3 vertexNormal; \n"
"out vec2 fragTexCoord; \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
- char vShaderStr[] = " #version 100 \n"
+ char vShaderStr[] = "#version 100 \n"
"attribute vec3 vertexPosition; \n"
"attribute vec2 vertexTexCoord; \n"
"attribute vec3 vertexNormal; \n"
@@ -2629,10 +2675,10 @@ static Shader LoadSimpleShader(void)
// Fragment shader directly defined, no external file required
#if defined(GRAPHICS_API_OPENGL_33)
- char fShaderStr[] = " #version 330 \n"
- "in vec2 fragTexCoord; \n"
+ char fShaderStr[] = "#version 330 \n"
+ "in vec2 fragTexCoord; \n"
#elif defined(GRAPHICS_API_OPENGL_ES2)
- char fShaderStr[] = " #version 100 \n"
+ char fShaderStr[] = "#version 100 \n"
"precision mediump float; \n" // precision required for OpenGL ES2 (WebGL)
"varying vec2 fragTexCoord; \n"
#endif
@@ -2666,6 +2712,10 @@ static Shader LoadSimpleShader(void)
shader.mapDiffuseLoc = glGetUniformLocation(shader.id, "texture0");
shader.mapNormalLoc = -1; // It can be set later
shader.mapSpecularLoc = -1; // It can be set later
+
+ shader.texDiffuseId = whiteTexture; // Default white texture
+ shader.texNormalId = 0;
+ shader.texSpecularId = 0;
//--------------------------------------------------------------------
return shader;
@@ -2692,7 +2742,7 @@ static char *TextFileRead(char *fileName)
if (count > 0)
{
- text = (char *)malloc(sizeof(char) * (count + 1));
+ text = (char *)malloc(sizeof(char)*(count + 1));
count = fread(text, sizeof(char), count, textFile);
text[count] = '\0';
}
@@ -3085,55 +3135,3 @@ static void TraceLog(int msgType, const char *text, ...)
if (msgType == ERROR) exit(1);
}
#endif
-
-#if defined(GRAPHICS_API_OPENGL_ES2)
-static char **StringSplit(char *baseString, const char delimiter, int *numExt)
-{
- char **result = 0;
- int count = 0;
- char *tmp = baseString;
- char *lastComma = 0;
- char delim[2];
-
- delim[0] = delimiter;
- delim[1] = 0;
-
- // Count how many elements will be extracted
- while (*tmp)
- {
- if (delimiter == *tmp)
- {
- count++;
- lastComma = tmp;
- }
-
- tmp++;
- }
-
- // Add space for trailing token
- count += lastComma < (baseString + strlen(baseString) - 1);
-
- // Add space for terminating null string
- count++;
-
- result = malloc(sizeof(char *)*count);
-
- if (result)
- {
- int idx = 0;
- char *token = strtok(baseString, delim);
-
- while (token)
- {
- *(result + idx++) = token;
- token = strtok(0, delim);
- }
-
- *(result + idx) = 0;
- }
-
- *numExt = (count - 1);
-
- return result;
-}
-#endif \ No newline at end of file
diff --git a/src/text.c b/src/text.c
index 3364a9bf..35a5f049 100644
--- a/src/text.c
+++ b/src/text.c
@@ -221,8 +221,6 @@ extern void UnloadDefaultFont(void)
UnloadTexture(defaultFont.texture);
free(defaultFont.charValues);
free(defaultFont.charRecs);
-
- TraceLog(INFO, "Unloaded default font data");
}
// Get the default font, useful to be used with extended parameters
@@ -243,7 +241,7 @@ SpriteFont LoadSpriteFont(const char *fileName)
{
Image image = LoadImage(fileName);
-#if defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
+#if defined(PLATFORM_WEB)
ImageConvertToPOT(&image, MAGENTA);
#endif
// Process bitmap font pixel data to get characters measures
diff --git a/src/textures.c b/src/textures.c
index e2eb8b2f..165d9358 100644
--- a/src/textures.c
+++ b/src/textures.c
@@ -321,7 +321,7 @@ Texture2D LoadTexture(const char *fileName)
Image image = LoadImage(fileName);
-#if defined(PLATFORM_RPI) || defined(PLATFORM_WEB)
+#if defined(PLATFORM_WEB)
ImageConvertToPOT(&image, BLANK);
#endif
@@ -404,7 +404,7 @@ void UnloadTexture(Texture2D texture)
{
rlDeleteTextures(texture.id);
- TraceLog(INFO, "[TEX ID %i] Unloaded texture data", texture.id);
+ TraceLog(INFO, "[TEX ID %i] Unloaded texture data from VRAM (GPU)", texture.id);
}
}
@@ -501,7 +501,10 @@ Image GetTextureData(Texture2D texture)
{
Image image;
image.data = NULL;
-
+
+#if defined(GRAPHICS_API_OPENGL_ES2)
+ TraceLog(WARNING, "Texture data retrieval not supported on OpenGL ES 2.0");
+#else
if (texture.format < 8)
{
image.data = rlglReadTexturePixels(texture.id, texture.format);
@@ -518,7 +521,7 @@ Image GetTextureData(Texture2D texture)
else TraceLog(WARNING, "Texture pixel data could not be obtained");
}
else TraceLog(WARNING, "Compressed texture data could not be obtained");
-
+#endif
return image;
}
@@ -695,6 +698,8 @@ void ImageConvertToPOT(Image *image, Color fillColor)
int format = image->format; // Store image data format to reconvert later
+ // TODO: Image width and height changes... do we want to store new values or keep the old ones?
+ // NOTE: Issues when using image.width and image.height for sprite animations...
*image = LoadImageEx(pixelsPOT, potWidth, potHeight);
free(pixelsPOT); // Free POT pixels data
diff --git a/src/utils.h b/src/utils.h
index 882aebf6..6ef8c933 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -4,7 +4,7 @@
*
* Some utility functions: rRES files data decompression
*
-* Copyright (c) 2014 Ramon Santamaria (Ray San - raysan@raysanweb.com)
+* Copyright (c) 2014 Ramon Santamaria (@raysan5)
*
* This software is provided "as-is", without any express or implied warranty. In no event
* will the authors be held liable for any damages arising from the use of this software.