Browse Source

Corrected some issues on OpenGL 1.1

pull/124/head
raysan5 9 years ago
parent
commit
897179a06c
2 changed files with 46 additions and 31 deletions
  1. +16
    -5
      src/rlgl.c
  2. +30
    -26
      src/textures.c

+ 16
- 5
src/rlgl.c View File

@ -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 Shader LoadStandardShader(void); // Load standard shader (support materials and lighting)
static void LoadDefaultShaderLocations(Shader *shader); // Bind default shader locations (attributes and uniforms) static void LoadDefaultShaderLocations(Shader *shader); // Bind default shader locations (attributes and uniforms)
static void UnloadDefaultShader(void); // Unload default shader 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 LoadDefaultBuffers(void); // Load default internal buffers (lines, triangles, quads)
static void UpdateDefaultBuffers(void); // Update default internal buffers (VAOs/VBOs) with vertex data 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) #if defined(RLGL_STANDALONE)
static void TraceLog(int msgType, const char *text, ...); 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 #endif
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -1545,10 +1545,10 @@ void rlglLoadMesh(Mesh *mesh, bool dynamic)
mesh->vboId[5] = 0; // Vertex texcoords2 VBO mesh->vboId[5] = 0; // Vertex texcoords2 VBO
mesh->vboId[6] = 0; // Vertex indices VBO mesh->vboId[6] = 0; // Vertex indices VBO
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
int drawHint = GL_STATIC_DRAW; int drawHint = GL_STATIC_DRAW;
if (dynamic) drawHint = GL_DYNAMIC_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 vaoId = 0; // Vertex Array Objects (VAO)
GLuint vboId[7]; // Vertex Buffer Objects (VBOs) 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) // Update vertex data on GPU (upload new data to one buffer)
void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex) void rlglUpdateMesh(Mesh mesh, int buffer, int numVertex)
{ {
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Activate mesh VAO // Activate mesh VAO
if (vaoSupported) glBindVertexArray(mesh.vaoId); 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); //mesh.vertices = glMapBuffer(GL_ARRAY_BUFFER, GL_READ_WRITE);
// Now we can modify vertices // Now we can modify vertices
//glUnmapBuffer(GL_ARRAY_BUFFER); //glUnmapBuffer(GL_ARRAY_BUFFER);
#endif
} }
// Draw a 3d mesh with material and transform // 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 // Create a new light, initialize it and add to pool
Light CreateLight(int type, Vector3 position, Color diffuse) 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 // Allocate dynamic memory
Light light = (Light)malloc(sizeof(LightData));
light = (Light)malloc(sizeof(LightData));
// Initialize light values with generic values // Initialize light values with generic values
light->id = lightsCount; light->id = lightsCount;
@ -2298,13 +2303,18 @@ Light CreateLight(int type, Vector3 position, Color diffuse)
// Increase enabled lights count // Increase enabled lights count
lightsCount++; lightsCount++;
#else
// TODO: Support OpenGL 1.1 lighting system
TraceLog(WARNING, "Lighting currently not supported on OpenGL 1.1");
#endif
return light; return light;
} }
// Destroy a light and take it out of the list // Destroy a light and take it out of the list
void DestroyLight(Light light) void DestroyLight(Light light)
{ {
#if defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
// Free dynamic memory allocation // Free dynamic memory allocation
free(lights[light->id]); free(lights[light->id]);
@ -2322,6 +2332,7 @@ void DestroyLight(Light light)
// Decrease enabled physic objects count // Decrease enabled physic objects count
lightsCount--; lightsCount--;
#endif
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

+ 30
- 26
src/textures.c View File

@ -1394,39 +1394,43 @@ void DrawTextureRec(Texture2D texture, Rectangle sourceRec, Vector2 position, Co
// NOTE: origin is relative to destination rectangle size // NOTE: origin is relative to destination rectangle size
void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint) 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();
}
} }
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------

Loading…
Cancel
Save