diff --git a/src/rlgl.c b/src/rlgl.c index 89361f462..aa536e2a2 100644 --- a/src/rlgl.c +++ b/src/rlgl.c @@ -237,7 +237,7 @@ static Shader LoadDefaultShader(void); // Load default shader (just vertex static Shader LoadStandardShader(void); // Load standard shader (support materials and lighting) static void LoadDefaultShaderLocations(Shader *shader); // Bind default shader locations (attributes and uniforms) static void UnloadDefaultShader(void); // Unload default shader -static void UnloadStandardShader(void); // Unload standard shader +static void UnloadStandardShader(void); // Unload standard shader static void LoadDefaultBuffers(void); // Load default internal buffers (lines, triangles, quads) static void UpdateDefaultBuffers(void); // Update default internal buffers (VAOs/VBOs) with vertex data @@ -256,7 +256,7 @@ static Color *GenNextMipmap(Color *srcData, int srcWidth, int srcHeight); #if defined(RLGL_STANDALONE) static void TraceLog(int msgType, const char *text, ...); -float *MatrixToFloat(Matrix mat); // Converts Matrix to float array +float *MatrixToFloat(Matrix mat); // Converts Matrix to float array #endif //---------------------------------------------------------------------------------- @@ -1545,10 +1545,10 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic) mesh->vboId[5] = 0; // Vertex texcoords2 VBO mesh->vboId[6] = 0; // Vertex indices VBO +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) int drawHint = GL_STATIC_DRAW; if (dynamic) drawHint = GL_DYNAMIC_DRAW; -#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) GLuint vaoId = 0; // Vertex Array Objects (VAO) GLuint vboId[7]; // Vertex Buffer Objects (VBOs) @@ -1674,6 +1674,7 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic) // Update vertex data on GPU (upload new data to one buffer) void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex) { +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Activate mesh VAO if (vaoSupported) glBindVertexArray(mesh.vaoId); @@ -1729,6 +1730,7 @@ void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex) //mesh.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE); // Now we can modify vertices //glUnmapBuffer(GL_ARRAY_BUFFER); +#endif } // Draw a 3d mesh with material and transform @@ -2280,8 +2282,11 @@ void EndBlendMode(void) // Create a new light, initialize it and add to pool Light CreateLight(int type, Vector3 position, Color diffuse) { + Light light = NULL; + +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Allocate dynamic memory - Light light = (Light)malloc(sizeof(LightData)); + light = (Light)malloc(sizeof(LightData)); // Initialize light values with generic values light->id = lightsCount; @@ -2298,13 +2303,18 @@ Light CreateLight(int type, Vector3 position, Color diffuse) // Increase enabled lights count lightsCount++; - +#else + // TODO: Support OpenGL 1.1 lighting system + TraceLog(WARNING, "Lighting currently not supported on OpenGL 1.1"); +#endif + return light; } // Destroy a light and take it out of the list void DestroyLight(Light light) { +#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2) // Free dynamic memory allocation free(lights[light->id]); @@ -2322,6 +2332,7 @@ void DestroyLight(Light light) // Decrease enabled physic objects count lightsCount--; +#endif } //---------------------------------------------------------------------------------- diff --git a/src/textures.c b/src/textures.c index 439311f6b..8c59f3f24 100644 --- a/src/textures.c +++ b/src/textures.c @@ -1394,39 +1394,43 @@ void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Co // NOTE: origin is relative to destination rectangle size void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint) { - if (sourceRec.width < 0) sourceRec.x -= sourceRec.width; - if (sourceRec.height < 0) sourceRec.y -= sourceRec.height; - - rlEnableTexture(texture.id); + // Check if texture is valid + if (texture.id != 0) + { + if (sourceRec.width < 0) sourceRec.x -= sourceRec.width; + if (sourceRec.height < 0) sourceRec.y -= sourceRec.height; + + rlEnableTexture(texture.id); - rlPushMatrix(); - rlTranslatef(destRec.x, destRec.y, 0); - rlRotatef(rotation, 0, 0, 1); - rlTranslatef(-origin.x, -origin.y, 0); + rlPushMatrix(); + rlTranslatef(destRec.x, destRec.y, 0); + rlRotatef(rotation, 0, 0, 1); + rlTranslatef(-origin.x, -origin.y, 0); - rlBegin(RL_QUADS); - rlColor4ub(tint.r, tint.g, tint.b, tint.a); - rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer + rlBegin(RL_QUADS); + rlColor4ub(tint.r, tint.g, tint.b, tint.a); + rlNormal3f(0.0f, 0.0f, 1.0f); // Normal vector pointing towards viewer - // Bottom-left corner for texture and quad - rlTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height); - rlVertex2f(0.0f, 0.0f); + // Bottom-left corner for texture and quad + rlTexCoord2f((float)sourceRec.x / texture.width, (float)sourceRec.y / texture.height); + rlVertex2f(0.0f, 0.0f); - // Bottom-right corner for texture and quad - rlTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height); - rlVertex2f(0.0f, destRec.height); + // Bottom-right corner for texture and quad + rlTexCoord2f((float)sourceRec.x / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height); + rlVertex2f(0.0f, destRec.height); - // Top-right corner for texture and quad - rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height); - rlVertex2f(destRec.width, destRec.height); + // Top-right corner for texture and quad + rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)(sourceRec.y + sourceRec.height) / texture.height); + rlVertex2f(destRec.width, destRec.height); - // Top-left corner for texture and quad - rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height); - rlVertex2f(destRec.width, 0.0f); - rlEnd(); - rlPopMatrix(); + // Top-left corner for texture and quad + rlTexCoord2f((float)(sourceRec.x + sourceRec.width) / texture.width, (float)sourceRec.y / texture.height); + rlVertex2f(destRec.width, 0.0f); + rlEnd(); + rlPopMatrix(); - rlDisableTexture(); + rlDisableTexture(); + } } //----------------------------------------------------------------------------------