Support shapes drawing using only QUADS

Also added new compilation FLAGS for that pourpose
This commit is contained in:
raysan5 2018-04-29 12:53:32 +02:00
parent ada6668b24
commit 8d81b6e4e4
4 changed files with 225 additions and 187 deletions

View File

@ -25,6 +25,7 @@ set_property(CACHE OPENGL_VERSION PROPERTY STRINGS "3.3" "2.1" "1.1" "ES 2.0")
option(SUPPORT_BUSY_WAIT_LOOP "Use busy wait loop for timing sync instead of a high-resolution timer" ON) option(SUPPORT_BUSY_WAIT_LOOP "Use busy wait loop for timing sync instead of a high-resolution timer" ON)
option(SUPPORT_CAMERA_SYSTEM "Provide camera module (camera.h) with multiple predefined cameras: free, 1st/3rd person, orbital" ON) option(SUPPORT_CAMERA_SYSTEM "Provide camera module (camera.h) with multiple predefined cameras: free, 1st/3rd person, orbital" ON)
option(SUPPORT_DEFAULT_FONT "Default font is loaded on window initialization to be available for the user to render simple text. If enabled, uses external module functions to load default raylib font (module: text)" ON) option(SUPPORT_DEFAULT_FONT "Default font is loaded on window initialization to be available for the user to render simple text. If enabled, uses external module functions to load default raylib font (module: text)" ON)
option(SUPPORT_SCREEN_CAPTURE "Allow automatic screen capture of current screen pressing F12, defined in KeyCallback()" ON)
option(SUPPORT_GIF_RECORDING "Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()" ON) option(SUPPORT_GIF_RECORDING "Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback()" ON)
option(SUPPORT_GESTURES_SYSTEM "Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag" ON) option(SUPPORT_GESTURES_SYSTEM "Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag" ON)
option(SUPPORT_MOUSE_GESTURES "Mouse gestures are directly mapped like touches and processed by gestures system" ON) option(SUPPORT_MOUSE_GESTURES "Mouse gestures are directly mapped like touches and processed by gestures system" ON)
@ -33,10 +34,9 @@ option(SUPPORT_MOUSE_GESTURES "Mouse gestures are directly mapped like touches a
option(SUPPORT_VR_SIMULATOR "Support VR simulation functionality (stereo rendering)" ON) option(SUPPORT_VR_SIMULATOR "Support VR simulation functionality (stereo rendering)" ON)
option(SUPPORT_DISTORTION_SHADER "Include stereo rendering distortion shader (shader_distortion.h)" ON) option(SUPPORT_DISTORTION_SHADER "Include stereo rendering distortion shader (shader_distortion.h)" ON)
# models.c # shapes.c
option(SUPPORT_FILEFORMAT_OBJ "Support loading OBJ file format" ON) option(SUPPORT_FONT_TEXTURE "Draw rectangle shapes using font texture white character instead of default white texture. Allows drawing rectangles and text with a single draw call, very useful for GUI systems!" ON)
option(SUPPORT_FILEFORMAT_MTL "Support loading MTL file format" ON) option(SUPPORT_QUADS_DRAW_MODE "Use QUADS instead of TRIANGLES for drawing when possible. Some lines-based shapes could still use lines" ON)
option(SUPPORT_MESH_GENERATION "Support procedural mesh generation functions, uses external par_shapes.h library. NOTE: Some generated meshes DO NOT include generated texture coordinates" ON)
# textures.c # textures.c
option(SUPPORT_IMAGE_GENERATION "Support proedural image generation functionality (gradient, spot, perlin-noise, cellular)" ON) option(SUPPORT_IMAGE_GENERATION "Support proedural image generation functionality (gradient, spot, perlin-noise, cellular)" ON)
@ -53,6 +53,11 @@ option(SUPPORT_FILEFORMAT_PSD "Support loading PSD as textures" OFF)
option(SUPPORT_FILEFORMAT_PKM "Support loading PKM as textures" OFF) option(SUPPORT_FILEFORMAT_PKM "Support loading PKM as textures" OFF)
option(SUPPORT_FILEFORMAT_PVR "Support loading PVR as textures" OFF) option(SUPPORT_FILEFORMAT_PVR "Support loading PVR as textures" OFF)
# models.c
option(SUPPORT_FILEFORMAT_OBJ "Support loading OBJ file format" ON)
option(SUPPORT_FILEFORMAT_MTL "Support loading MTL file format" ON)
option(SUPPORT_MESH_GENERATION "Support procedural mesh generation functions, uses external par_shapes.h library. NOTE: Some generated meshes DO NOT include generated texture coordinates" ON)
# audio.c # audio.c
option(SUPPORT_FILEFORMAT_WAV "Support loading WAV for sound" ON) option(SUPPORT_FILEFORMAT_WAV "Support loading WAV for sound" ON)
option(SUPPORT_FILEFORMAT_OGG "Support loading OGG for sound" ON) option(SUPPORT_FILEFORMAT_OGG "Support loading OGG for sound" ON)
@ -60,9 +65,6 @@ option(SUPPORT_FILEFORMAT_XM "Support loading XM for sound" ON)
option(SUPPORT_FILEFORMAT_MOD "Support loading MOD for sound" ON) option(SUPPORT_FILEFORMAT_MOD "Support loading MOD for sound" ON)
option(SUPPORT_FILEFORMAT_FLAC "Support loading FLAC for sound" OFF) option(SUPPORT_FILEFORMAT_FLAC "Support loading FLAC for sound" OFF)
# shapes.c
option(USE_DEFAULT_FONT_TEXTURE "Draw rectangle shapes using font texture white character instead of default white texture. Allows drawing rectangles and text with a single draw call, very useful for GUI systems!" ON)
# utils.c # utils.c
option(SUPPORT_SAVE_PNG "Support saving image data in PNG file format" ON) option(SUPPORT_SAVE_PNG "Support saving image data in PNG file format" ON)
option(SUPPORT_SAVE_BMP "Support saving image data in BMP file format" OFF) option(SUPPORT_SAVE_BMP "Support saving image data in BMP file format" OFF)

View File

@ -59,6 +59,16 @@
#define SUPPORT_DISTORTION_SHADER 1 #define SUPPORT_DISTORTION_SHADER 1
//------------------------------------------------------------------------------------
// Module: shapes - Configuration Flags
//------------------------------------------------------------------------------------
// Draw rectangle shapes using font texture white character instead of default white texture
// Allows drawing rectangles and text with a single draw call, very useful for GUI systems!
#define SUPPORT_FONT_TEXTURE
// Use QUADS instead of TRIANGLES for drawing when possible
// Some lines-based shapes could still use lines
#define SUPPORT_QUADS_DRAW_MODE
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------
// Module: textures - Configuration Flags // Module: textures - Configuration Flags
//------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------

View File

@ -1,11 +1,28 @@
/* config.h.in */ /* config.h.in */
// text.c // core.c
/* Default font is loaded on window initialization to be available for the user to render simple text. NOTE: If enabled, uses external module functions to load default raylib font (module: text) */ /* Camera module is included (camera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital */
#cmakedefine SUPPORT_DEFAULT_FONT 1 #cmakedefine SUPPORT_CAMERA_SYSTEM 1
/* Selected desired fileformats to be supported for loading. */ /* Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag */
#cmakedefine SUPPORT_FILEFORMAT_FNT 1 #cmakedefine SUPPORT_GESTURES_SYSTEM 1
#cmakedefine SUPPORT_FILEFORMAT_TTF 1 /* Mouse gestures are directly mapped like touches and processed by gestures system. */
#cmakedefine SUPPORT_MOUSE_GESTURES 1
/* Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used */
#cmakedefine SUPPORT_BUSY_WAIT_LOOP 1
/* Allow automatic screen capture of current screen pressing F12, defined in KeyCallback() */
#cmakedefine SUPPORT_SCREEN_CAPTURE 1
/* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback() */
#cmakedefine SUPPORT_GIF_RECORDING 1
// rlgl.c
/* Support VR simulation functionality (stereo rendering) */
#cmakedefine SUPPORT_VR_SIMULATOR 1
/* Include stereo rendering distortion shader (shader_distortion.h) */
#cmakedefine SUPPORT_DISTORTION_SHADER 1
// shapes.c
#cmakedefine SUPPORT_FONT_TEXTURE 1
#cmakedefine SUPPORT_QUADS_DRAW_MODE 1
// textures.c // textures.c
/* Selecte desired fileformats to be supported for image data loading. */ /* Selecte desired fileformats to be supported for image data loading. */
@ -28,23 +45,20 @@
/* Support proedural image generation functionality (gradient, spot, perlin-noise, cellular) */ /* Support proedural image generation functionality (gradient, spot, perlin-noise, cellular) */
#cmakedefine SUPPORT_IMAGE_GENERATION 1 #cmakedefine SUPPORT_IMAGE_GENERATION 1
// rlgl.c // text.c
/* Support VR simulation functionality (stereo rendering) */ /* Default font is loaded on window initialization to be available for the user to render simple text. NOTE: If enabled, uses external module functions to load default raylib font (module: text) */
#cmakedefine SUPPORT_VR_SIMULATOR 1 #cmakedefine SUPPORT_DEFAULT_FONT 1
/* Include stereo rendering distortion shader (shader_distortion.h) */ /* Selected desired fileformats to be supported for loading. */
#cmakedefine SUPPORT_DISTORTION_SHADER 1 #cmakedefine SUPPORT_FILEFORMAT_FNT 1
#cmakedefine SUPPORT_FILEFORMAT_TTF 1
// core.c // models.c
/* Camera module is included (camera.h) and multiple predefined cameras are available: free, 1st/3rd person, orbital */ /* Selected desired fileformats to be supported for loading. */
#cmakedefine SUPPORT_CAMERA_SYSTEM 1 #cmakedefine SUPPORT_FILEFORMAT_OBJ 1
/* Gestures module is included (gestures.h) to support gestures detection: tap, hold, swipe, drag */ #cmakedefine SUPPORT_FILEFORMAT_MTL 1
#cmakedefine SUPPORT_GESTURES_SYSTEM 1 /* Support procedural mesh generation functions, uses external par_shapes.h library
/* Mouse gestures are directly mapped like touches and processed by gestures system. */ * NOTE: Some generated meshes DO NOT include generated texture coordinates */
#cmakedefine SUPPORT_MOUSE_GESTURES 1 #cmakedefine SUPPORT_MESH_GENERATION 1
/* Use busy wait loop for timing sync, if not defined, a high-resolution timer is setup and used */
#cmakedefine SUPPORT_BUSY_WAIT_LOOP 1
/* Allow automatic gif recording of current screen pressing CTRL+F12, defined in KeyCallback() */
#cmakedefine SUPPORT_GIF_RECORDING 1
// audio.c // audio.c
/* Desired fileformats to be supported for loading. */ /* Desired fileformats to be supported for loading. */
@ -54,20 +68,9 @@
#cmakedefine SUPPORT_FILEFORMAT_MOD 1 #cmakedefine SUPPORT_FILEFORMAT_MOD 1
#cmakedefine SUPPORT_FILEFORMAT_FLAC 1 #cmakedefine SUPPORT_FILEFORMAT_FLAC 1
// models.c
/* Selected desired fileformats to be supported for loading. */
#cmakedefine SUPPORT_FILEFORMAT_OBJ 1
#cmakedefine SUPPORT_FILEFORMAT_MTL 1
/* Support procedural mesh generation functions, uses external par_shapes.h library
* NOTE: Some generated meshes DO NOT include generated texture coordinates
*/
#cmakedefine SUPPORT_MESH_GENERATION 1
// utils.c // utils.c
/* Show TraceLog() output messages. NOTE: By default LOG_DEBUG traces not shown */ /* Show TraceLog() output messages. NOTE: By default LOG_DEBUG traces not shown */
#cmakedefine SUPPORT_TRACELOG 1 #cmakedefine SUPPORT_TRACELOG 1
/* Support saving image data as PNG fileformat. NOTE: Requires stb_image_write library */ /* Support saving image data as PNG fileformat. NOTE: Requires stb_image_write library */
#cmakedefine SUPPORT_SAVE_PNG 1 #cmakedefine SUPPORT_SAVE_PNG 1
/* Support saving image data as PMP fileformat. NOTE: Requires stb_image_write library */ /* Support saving image data as PMP fileformat. NOTE: Requires stb_image_write library */

View File

@ -4,10 +4,13 @@
* *
* CONFIGURATION: * CONFIGURATION:
* *
* #define USE_DEFAULT_FONT_TEXTURE * #define SUPPORT_FONT_TEXTURE
* Draw rectangle shapes using font texture white character instead of default white texture * Draw rectangle shapes using font texture white character instead of default white texture
* Allows drawing rectangles and text with a single draw call, very useful for GUI systems! * Allows drawing rectangles and text with a single draw call, very useful for GUI systems!
* *
* #define SUPPORT_QUADS_DRAW_MODE
* Use QUADS instead of TRIANGLES for drawing when possible.
* Some lines-based shapes could still use lines
* *
* LICENSE: zlib/libpng * LICENSE: zlib/libpng
* *
@ -30,13 +33,12 @@
* *
**********************************************************************************************/ **********************************************************************************************/
#include "config.h" #include "config.h" // Defines module configuration flags
#include "raylib.h" // Declares module functions
#include "raylib.h"
#include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2 #include "rlgl.h" // raylib OpenGL abstraction layer to OpenGL 1.1, 2.1, 3.3+ or ES2
#include <stdlib.h> // Required for: abs() #include <stdlib.h> // Required for: abs(), fabs()
#include <math.h> // Required for: sinf(), cosf(), sqrtf() #include <math.h> // Required for: sinf(), cosf(), sqrtf()
//---------------------------------------------------------------------------------- //----------------------------------------------------------------------------------
@ -188,37 +190,34 @@ void DrawCircleGradient(int centerX, int centerY, float radius, Color color1, Co
// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw) // NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
void DrawCircleV(Vector2 center, float radius, Color color) void DrawCircleV(Vector2 center, float radius, Color color)
{ {
if (rlGetVersion() == OPENGL_11) #if defined(SUPPORT_QUADS_DRAW_MODE)
{ rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_TRIANGLES);
for (int i = 0; i < 360; i += 10)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(center.x, center.y);
rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius);
rlVertex2f(center.x + sinf(DEG2RAD*(i + 10))*radius, center.y + cosf(DEG2RAD*(i + 10))*radius);
}
rlEnd();
}
else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{
rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
for (int i = 0; i < 360; i += 20) for (int i = 0; i < 360; i += 20)
{ {
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(center.x, center.y); rlVertex2f(center.x, center.y);
rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius); rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius);
rlVertex2f(center.x + sinf(DEG2RAD*(i + 10))*radius, center.y + cosf(DEG2RAD*(i + 10))*radius); rlVertex2f(center.x + sinf(DEG2RAD*(i + 10))*radius, center.y + cosf(DEG2RAD*(i + 10))*radius);
rlVertex2f(center.x + sinf(DEG2RAD*(i + 20))*radius, center.y + cosf(DEG2RAD*(i + 20))*radius); rlVertex2f(center.x + sinf(DEG2RAD*(i + 20))*radius, center.y + cosf(DEG2RAD*(i + 20))*radius);
} }
rlEnd(); rlEnd();
rlDisableTexture(); rlDisableTexture();
} #else
rlBegin(RL_TRIANGLES);
for (int i = 0; i < 360; i += 10)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(center.x, center.y);
rlVertex2f(center.x + sinf(DEG2RAD*i)*radius, center.y + cosf(DEG2RAD*i)*radius);
rlVertex2f(center.x + sinf(DEG2RAD*(i + 10))*radius, center.y + cosf(DEG2RAD*(i + 10))*radius);
}
rlEnd();
#endif
} }
// Draw circle outline // Draw circle outline
@ -249,72 +248,69 @@ void DrawRectangle(int posX, int posY, int width, int height, Color color)
// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw) // NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
void DrawRectangleV(Vector2 position, Vector2 size, Color color) void DrawRectangleV(Vector2 position, Vector2 size, Color color)
{ {
if (rlGetVersion() == OPENGL_11) #if defined(SUPPORT_QUADS_DRAW_MODE)
{ #if defined(SUPPORT_FONT_TEXTURE)
rlBegin(RL_TRIANGLES); // Draw rectangle using font texture white character
rlColor4ub(color.r, color.g, color.b, color.a); rlEnableTexture(GetDefaultFont().texture.id);
rlVertex2i(position.x, position.y); rlBegin(RL_QUADS);
rlVertex2i(position.x, position.y + size.y); rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2i(position.x + size.x, position.y + size.y); rlNormal3f(0.0f, 0.0f, 1.0f);
rlVertex2i(position.x, position.y); // NOTE: Default raylib font character 95 is a white square
rlVertex2i(position.x + size.x, position.y + size.y); rlTexCoord2f((float)GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
rlVertex2i(position.x + size.x, position.y); (float)GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlEnd(); rlVertex2f(position.x, position.y);
}
else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{
#if defined(USE_DEFAULT_FONT_TEXTURE)
// Draw rectangle using font texture white character
rlEnableTexture(GetDefaultFont().texture.id);
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
rlNormal3f(0.0f, 0.0f, 1.0f);
// NOTE: Default raylib font character 95 is a white square
rlTexCoord2f((float)GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
(float)GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlVertex2f(position.x, position.y);
rlTexCoord2f((float)GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
(float)(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlVertex2f(position.x, position.y + size.y);
rlTexCoord2f((float)(GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
(float)(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlVertex2f(position.x + size.x, position.y + size.y);
rlTexCoord2f((float)(GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
(float)GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlVertex2f(position.x + size.x, position.y);
rlEnd();
rlDisableTexture(); rlTexCoord2f((float)GetDefaultFont().chars[95].rec.x/GetDefaultFont().texture.width,
(float)(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlVertex2f(position.x, position.y + size.y);
rlTexCoord2f((float)(GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
(float)(GetDefaultFont().chars[95].rec.y + GetDefaultFont().chars[95].rec.height)/GetDefaultFont().texture.height);
rlVertex2f(position.x + size.x, position.y + size.y);
rlTexCoord2f((float)(GetDefaultFont().chars[95].rec.x + GetDefaultFont().chars[95].rec.width)/GetDefaultFont().texture.width,
(float)GetDefaultFont().chars[95].rec.y/GetDefaultFont().texture.height);
rlVertex2f(position.x + size.x, position.y);
rlEnd();
rlDisableTexture();
#else
rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
rlNormal3f(0.0f, 0.0f, 1.0f);
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();
#endif // SUPPORT_FONT_TEXTURE
#else #else
rlEnableTexture(GetTextureDefault().id); // Default white texture rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a);
rlBegin(RL_QUADS); rlVertex2i(position.x, position.y);
rlColor4ub(color.r, color.g, color.b, color.a); rlVertex2i(position.x, position.y + size.y);
rlNormal3f(0.0f, 0.0f, 1.0f); rlVertex2i(position.x + size.x, position.y + size.y);
rlTexCoord2f(0.0f, 0.0f); rlVertex2i(position.x, position.y);
rlVertex2f(position.x, position.y); rlVertex2i(position.x + size.x, position.y + size.y);
rlVertex2i(position.x + size.x, position.y);
rlTexCoord2f(0.0f, 1.0f); rlEnd();
rlVertex2f(position.x, position.y + size.y); #endif // SUPPORT_QUADS_DRAW_MODE
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();
#endif
}
} }
// Draw a color-filled rectangle // Draw a color-filled rectangle
@ -364,7 +360,7 @@ void DrawRectangleGradientH(int posX, int posY, int width, int height, Color col
// NOTE: Colors refer to corners, starting at top-lef corner and counter-clockwise // NOTE: Colors refer to corners, starting at top-lef corner and counter-clockwise
void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4) void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3, Color col4)
{ {
#if defined(USE_DEFAULT_FONT_TEXTURE) #if defined(SUPPORT_FONT_TEXTURE)
// Draw rectangle using font texture white character // Draw rectangle using font texture white character
rlEnableTexture(GetDefaultFont().texture.id); rlEnableTexture(GetDefaultFont().texture.id);
@ -425,30 +421,27 @@ void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3,
// NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw) // NOTE: On OpenGL 3.3 and ES2 we use QUADS to avoid drawing order issues (view rlglDraw)
void DrawRectangleLines(int posX, int posY, int width, int height, Color color) void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
{ {
if (rlGetVersion() == OPENGL_11) #if defined(SUPPORT_QUADS_DRAW_MODE)
{ DrawRectangle(posX, posY, width, 1, color);
rlBegin(RL_LINES); DrawRectangle(posX + width - 1, posY + 1, 1, height - 2, color);
rlColor4ub(color.r, color.g, color.b, color.a); DrawRectangle(posX, posY + height - 1, width, 1, color);
rlVertex2i(posX + 1, posY + 1); DrawRectangle(posX, posY + 1, 1, height - 2, color);
rlVertex2i(posX + width, posY + 1); #else
rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2i(posX + 1, posY + 1);
rlVertex2i(posX + width, posY + 1);
rlVertex2i(posX + width, posY + 1); rlVertex2i(posX + width, posY + 1);
rlVertex2i(posX + width, posY + height); rlVertex2i(posX + width, posY + height);
rlVertex2i(posX + width, posY + height); rlVertex2i(posX + width, posY + height);
rlVertex2i(posX + 1, posY + height); rlVertex2i(posX + 1, posY + height);
rlVertex2i(posX + 1, posY + height); rlVertex2i(posX + 1, posY + height);
rlVertex2i(posX + 1, posY + 1); rlVertex2i(posX + 1, posY + 1);
rlEnd(); rlEnd();
} #endif
else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{
DrawRectangle(posX, posY, width, 1, color);
DrawRectangle(posX + width - 1, posY + 1, 1, height - 2, color);
DrawRectangle(posX, posY + height - 1, width, 1, color);
DrawRectangle(posX, posY + 1, 1, height - 2, color);
}
} }
// Draw rectangle outline with extended parameters // Draw rectangle outline with extended parameters
@ -469,31 +462,29 @@ void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color)
// Draw a triangle // Draw a triangle
void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color) void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
{ {
if (rlGetVersion() == OPENGL_11) #if defined(SUPPORT_QUADS_DRAW_MODE)
{ rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(v1.x, v1.y);
rlVertex2f(v2.x, v2.y);
rlVertex2f(v3.x, v3.y);
rlEnd();
}
else if ((rlGetVersion() == OPENGL_21) || (rlGetVersion() == OPENGL_33) || (rlGetVersion() == OPENGL_ES_20))
{
rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS); rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(v1.x, v1.y); rlVertex2f(v1.x, v1.y);
rlVertex2f(v2.x, v2.y); rlVertex2f(v2.x, v2.y);
rlVertex2f(v2.x, v2.y); rlVertex2f(v2.x, v2.y);
rlVertex2f(v3.x, v3.y); rlVertex2f(v3.x, v3.y);
rlEnd(); rlEnd();
rlDisableTexture(); rlDisableTexture();
} #else
rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(v1.x, v1.y);
rlVertex2f(v2.x, v2.y);
rlVertex2f(v3.x, v3.y);
rlEnd();
#endif
} }
// Draw a triangle using lines
void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color) void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color)
{ {
rlBegin(RL_LINES); rlBegin(RL_LINES);
@ -517,7 +508,23 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col
rlPushMatrix(); rlPushMatrix();
rlTranslatef(center.x, center.y, 0.0); rlTranslatef(center.x, center.y, 0.0);
rlRotatef(rotation, 0, 0, 1); rlRotatef(rotation, 0, 0, 1);
#if defined(SUPPORT_QUADS_DRAW_MODE)
rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS);
for (int i = 0; i < 360; i += 360/sides)
{
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f(0, 0);
rlVertex2f(sinf(DEG2RAD*i)*radius, cosf(DEG2RAD*i)*radius);
rlVertex2f(sinf(DEG2RAD*i)*radius, cosf(DEG2RAD*i)*radius);
rlVertex2f(sinf(DEG2RAD*(i + 360/sides))*radius, cosf(DEG2RAD*(i + 360/sides))*radius);
}
rlEnd();
rlDisableTexture();
#else
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
for (int i = 0; i < 360; i += 360/sides) for (int i = 0; i < 360; i += 360/sides)
{ {
@ -528,38 +535,54 @@ void DrawPoly(Vector2 center, int sides, float radius, float rotation, Color col
rlVertex2f(sinf(DEG2RAD*(i + 360/sides))*radius, cosf(DEG2RAD*(i + 360/sides))*radius); rlVertex2f(sinf(DEG2RAD*(i + 360/sides))*radius, cosf(DEG2RAD*(i + 360/sides))*radius);
} }
rlEnd(); rlEnd();
#endif
rlPopMatrix(); rlPopMatrix();
} }
// Draw a closed polygon defined by points // Draw a closed polygon defined by points
// NOTE: Array num elements MUST be passed as parameter to function void DrawPolyEx(Vector2 *points, int pointsCount, Color color)
void DrawPolyEx(Vector2 *points, int numPoints, Color color)
{ {
if (numPoints >= 3) if (pointsCount >= 3)
{ {
#if defined(SUPPORT_QUADS_DRAW_MODE)
rlEnableTexture(GetTextureDefault().id); // Default white texture
rlBegin(RL_QUADS);
rlColor4ub(color.r, color.g, color.b, color.a);
for (int i = 1; i < pointsCount - 1; i++)
{
rlVertex2f(points[0].x, points[0].y);
rlVertex2f(points[i].x, points[i].y);
rlVertex2f(points[i].x, points[i].y);
rlVertex2f(points[i + 1].x, points[i + 1].y);
}
rlEnd();
rlDisableTexture();
#else
rlBegin(RL_TRIANGLES); rlBegin(RL_TRIANGLES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
for (int i = 1; i < numPoints - 1; i++) for (int i = 1; i < pointsCount - 1; i++)
{ {
rlVertex2f(points[0].x, points[0].y); rlVertex2f(points[0].x, points[0].y);
rlVertex2f(points[i].x, points[i].y); rlVertex2f(points[i].x, points[i].y);
rlVertex2f(points[i + 1].x, points[i + 1].y); rlVertex2f(points[i + 1].x, points[i + 1].y);
} }
rlEnd(); rlEnd();
#endif
} }
} }
// Draw polygon lines // Draw polygon using lines
// NOTE: Array num elements MUST be passed as parameter to function void DrawPolyExLines(Vector2 *points, int pointsCount, Color color)
void DrawPolyExLines(Vector2 *points, int numPoints, Color color)
{ {
if (numPoints >= 2) if (pointsCount >= 2)
{ {
rlBegin(RL_LINES); rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a); rlColor4ub(color.r, color.g, color.b, color.a);
for (int i = 0; i < numPoints - 1; i++) for (int i = 0; i < pointsCount - 1; i++)
{ {
rlVertex2f(points[i].x, points[i].y); rlVertex2f(points[i].x, points[i].y);
rlVertex2f(points[i + 1].x, points[i + 1].y); rlVertex2f(points[i + 1].x, points[i + 1].y);