Corrected bug with drawing order

We have three vertex buffers: lines, triangles and quads for textures.
Drawing in a desired order could become a nighmare... noww it seems it
works prety well...
This commit is contained in:
raysan5 2014-07-23 01:25:33 +02:00
parent 0b03431c95
commit ecb3c47704
4 changed files with 37 additions and 11 deletions

View File

@ -15,6 +15,7 @@ Release: raylib 1.1.1 (22 July 2014)
[rlgl] Removed double buffer system (no performance improvement) [rlgl] Removed double buffer system (no performance improvement)
[rlgl] rlglDraw() - Reorganized buffers drawing order [rlgl] rlglDraw() - Reorganized buffers drawing order
[rlgl] Corrected bug on screen resizing [rlgl] Corrected bug on screen resizing
[shapes] DrawRectangle() - Use QUADS instead of TRIANGLES
[models] DrawSphereWires() - Corrected some issues [models] DrawSphereWires() - Corrected some issues
[models] LoadOBJ() - Redesigned to support multiple meshes [models] LoadOBJ() - Redesigned to support multiple meshes
[models] LoadCubesMap() - Loading a map as cubes (by pixel color) [models] LoadCubesMap() - Loading a map as cubes (by pixel color)

Binary file not shown.

View File

@ -825,7 +825,17 @@ void rlglDraw()
glUniformMatrix4fv(modelviewMatrixLoc, 1, false, GetMatrixVector(modelview)); glUniformMatrix4fv(modelviewMatrixLoc, 1, false, GetMatrixVector(modelview));
glUniform1i(textureLoc, 0); glUniform1i(textureLoc, 0);
// NOTE: We draw in this order: textured quads, triangles shapes, lines // NOTE: We draw in this order: triangle shapes, textured quads and lines
if (triangles.vCounter > 0)
{
glBindTexture(GL_TEXTURE_2D, whiteTexture);
glBindVertexArray(vaoTriangles);
glDrawArrays(GL_TRIANGLES, 0, triangles.vCounter);
glBindTexture(GL_TEXTURE_2D, 0);
}
if (quads.vCounter > 0) if (quads.vCounter > 0)
{ {
@ -855,16 +865,6 @@ void rlglDraw()
glBindTexture(GL_TEXTURE_2D, 0); // Unbind textures glBindTexture(GL_TEXTURE_2D, 0); // Unbind textures
} }
if (triangles.vCounter > 0)
{
glBindTexture(GL_TEXTURE_2D, whiteTexture);
glBindVertexArray(vaoTriangles);
glDrawArrays(GL_TRIANGLES, 0, triangles.vCounter);
glBindTexture(GL_TEXTURE_2D, 0);
}
if (lines.vCounter > 0) if (lines.vCounter > 0)
{ {
glBindTexture(GL_TEXTURE_2D, whiteTexture); glBindTexture(GL_TEXTURE_2D, whiteTexture);

View File

@ -180,6 +180,7 @@ void DrawRectangleGradient(int posX, int posY, int width, int height, Color colo
// Draw a color-filled rectangle (Vector version) // Draw a color-filled rectangle (Vector version)
void DrawRectangleV(Vector2 position, Vector2 size, Color color) void DrawRectangleV(Vector2 position, Vector2 size, Color color)
{ {
/*
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
@ -191,6 +192,30 @@ void DrawRectangleV(Vector2 position, Vector2 size, Color color)
rlVertex2i(position.x + size.x, position.y + size.y); rlVertex2i(position.x + size.x, position.y + size.y);
rlVertex2i(position.x + size.x, position.y); rlVertex2i(position.x + size.x, position.y);
rlEnd(); rlEnd();
*/
// NOTE: This shape uses QUADS to avoid drawing order issues (view rlglDraw)
rlEnableTexture(1); // Default white texture
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
rlNormal3f(0.0f, 0.0f, 1.0f); // Normal Pointing Towards Viewer
rlTexCoord2f(0.0f, 0.0f);
rlVertex2f(position.x, position.y);
rlTexCoord2f(0.0f, 1.0f);
rlVertex2f(position.x, position.y + size.y);
rlTexCoord2f(1.0f, 1.0f);
rlVertex2f(position.x + size.x, position.y + size.y);
rlTexCoord2f(1.0f, 0.0f);
rlVertex2f(position.x + size.x, position.y);
rlEnd();
rlDisableTexture();
} }
// Draw rectangle outline // Draw rectangle outline