Wise&mystical  1.0
Project about Europe
Loading...
Searching...
No Matches
rshapes.c File Reference
#include "raylib.h"
#include "config.h"
#include "rlgl.h"
#include <math.h>
#include <float.h>
+ Include dependency graph for rshapes.c:

Go to the source code of this file.

Macros

#define SMOOTH_CIRCLE_ERROR_RATE   0.5f
 rshapes - Basic functions to draw 2d shapes and check collisions More...
 
#define BEZIER_LINE_DIVISIONS   24
 

Functions

void SetShapesTexture (Texture2D texture, Rectangle source)
 
void DrawPixel (int posX, int posY, Color color)
 
void DrawPixelV (Vector2 position, Color color)
 
void DrawLine (int startPosX, int startPosY, int endPosX, int endPosY, Color color)
 
void DrawLineV (Vector2 startPos, Vector2 endPos, Color color)
 
void DrawLineEx (Vector2 startPos, Vector2 endPos, float thick, Color color)
 
void DrawLineBezier (Vector2 startPos, Vector2 endPos, float thick, Color color)
 
void DrawLineBezierQuad (Vector2 startPos, Vector2 endPos, Vector2 controlPos, float thick, Color color)
 
void DrawLineBezierCubic (Vector2 startPos, Vector2 endPos, Vector2 startControlPos, Vector2 endControlPos, float thick, Color color)
 
void DrawLineStrip (Vector2 *points, int pointCount, Color color)
 
void DrawCircle (int centerX, int centerY, float radius, Color color)
 
void DrawCircleSector (Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
 
void DrawCircleSectorLines (Vector2 center, float radius, float startAngle, float endAngle, int segments, Color color)
 
void DrawCircleGradient (int centerX, int centerY, float radius, Color color1, Color color2)
 
void DrawCircleV (Vector2 center, float radius, Color color)
 
void DrawCircleLines (int centerX, int centerY, float radius, Color color)
 
void DrawEllipse (int centerX, int centerY, float radiusH, float radiusV, Color color)
 
void DrawEllipseLines (int centerX, int centerY, float radiusH, float radiusV, Color color)
 
void DrawRing (Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
 
void DrawRingLines (Vector2 center, float innerRadius, float outerRadius, float startAngle, float endAngle, int segments, Color color)
 
void DrawRectangle (int posX, int posY, int width, int height, Color color)
 
void DrawRectangleV (Vector2 position, Vector2 size, Color color)
 
void DrawRectangleRec (Rectangle rec, Color color)
 
void DrawRectanglePro (Rectangle rec, Vector2 origin, float rotation, Color color)
 
void DrawRectangleGradientV (int posX, int posY, int width, int height, Color color1, Color color2)
 
void DrawRectangleGradientH (int posX, int posY, int width, int height, Color color1, Color color2)
 
void DrawRectangleGradientEx (Rectangle rec, Color col1, Color col2, Color col3, Color col4)
 
void DrawRectangleLines (int posX, int posY, int width, int height, Color color)
 
void DrawRectangleLinesEx (Rectangle rec, float lineThick, Color color)
 
void DrawRectangleRounded (Rectangle rec, float roundness, int segments, Color color)
 
void DrawRectangleRoundedLines (Rectangle rec, float roundness, int segments, float lineThick, Color color)
 
void DrawTriangle (Vector2 v1, Vector2 v2, Vector2 v3, Color color)
 
void DrawTriangleLines (Vector2 v1, Vector2 v2, Vector2 v3, Color color)
 
void DrawTriangleFan (Vector2 *points, int pointCount, Color color)
 
void DrawTriangleStrip (Vector2 *points, int pointCount, Color color)
 
void DrawPoly (Vector2 center, int sides, float radius, float rotation, Color color)
 
void DrawPolyLines (Vector2 center, int sides, float radius, float rotation, Color color)
 
void DrawPolyLinesEx (Vector2 center, int sides, float radius, float rotation, float lineThick, Color color)
 
bool CheckCollisionPointRec (Vector2 point, Rectangle rec)
 
bool CheckCollisionPointCircle (Vector2 point, Vector2 center, float radius)
 
bool CheckCollisionPointTriangle (Vector2 point, Vector2 p1, Vector2 p2, Vector2 p3)
 
bool CheckCollisionRecs (Rectangle rec1, Rectangle rec2)
 
bool CheckCollisionCircles (Vector2 center1, float radius1, Vector2 center2, float radius2)
 
bool CheckCollisionCircleRec (Vector2 center, float radius, Rectangle rec)
 
bool CheckCollisionLines (Vector2 startPos1, Vector2 endPos1, Vector2 startPos2, Vector2 endPos2, Vector2 *collisionPoint)
 
bool CheckCollisionPointLine (Vector2 point, Vector2 p1, Vector2 p2, int threshold)
 
Rectangle GetCollisionRec (Rectangle rec1, Rectangle rec2)
 

Variables

Texture2D texShapes = { 1, 1, 1, 1, 7 }
 
Rectangle texShapesRec = { 0.0f, 0.0f, 1.0f, 1.0f }
 

Macro Definition Documentation

◆ BEZIER_LINE_DIVISIONS

#define BEZIER_LINE_DIVISIONS   24

Definition at line 71 of file rshapes.c.

◆ SMOOTH_CIRCLE_ERROR_RATE

#define SMOOTH_CIRCLE_ERROR_RATE   0.5f

rshapes - Basic functions to draw 2d shapes and check collisions

NOTES: Shapes can be draw using 3 types of primitives: LINES, TRIANGLES and QUADS. Some functions implement two drawing options: TRIANGLES and QUADS, by default TRIANGLES are used but QUADS implementation can be selected with SUPPORT_QUADS_DRAW_MODE define

Some functions define texture coordinates (rlTexCoord2f()) for the shapes and use a user-provided texture with SetShapesTexture(), the pourpouse of this implementation is allowing to reduce draw calls when combined with a texture-atlas.

By default, raylib sets the default texture and rectangle at InitWindow()[rcore] to one white character of default font [rtext], this way, raylib text and shapes can be draw with a single draw call and it also allows users to configure it the same way with their own fonts.

CONFIGURATION:

#define SUPPORT_MODULE_RSHAPES rshapes module is included in the build

#define SUPPORT_QUADS_DRAW_MODE Use QUADS instead of TRIANGLES for drawing when possible. Lines-based shapes still use LINES

LICENSE: zlib/libpng

Copyright (c) 2013-2022 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.

Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:

  1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
  2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
  3. This notice may not be removed or altered from any source distribution.

Definition at line 68 of file rshapes.c.

Function Documentation

◆ CheckCollisionCircleRec()

bool CheckCollisionCircleRec ( Vector2  center,
float  radius,
Rectangle  rec 
)

Definition at line 1664 of file rshapes.c.

◆ CheckCollisionCircles()

bool CheckCollisionCircles ( Vector2  center1,
float  radius1,
Vector2  center2,
float  radius2 
)

Definition at line 1648 of file rshapes.c.

+ Here is the caller graph for this function:

◆ CheckCollisionLines()

bool CheckCollisionLines ( Vector2  startPos1,
Vector2  endPos1,
Vector2  startPos2,
Vector2  endPos2,
Vector2 collisionPoint 
)

Definition at line 1689 of file rshapes.c.

◆ CheckCollisionPointCircle()

bool CheckCollisionPointCircle ( Vector2  point,
Vector2  center,
float  radius 
)

Definition at line 1609 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CheckCollisionPointLine()

bool CheckCollisionPointLine ( Vector2  point,
Vector2  p1,
Vector2  p2,
int  threshold 
)

Definition at line 1718 of file rshapes.c.

◆ CheckCollisionPointRec()

bool CheckCollisionPointRec ( Vector2  point,
Rectangle  rec 
)

Definition at line 1599 of file rshapes.c.

+ Here is the caller graph for this function:

◆ CheckCollisionPointTriangle()

bool CheckCollisionPointTriangle ( Vector2  point,
Vector2  p1,
Vector2  p2,
Vector2  p3 
)

Definition at line 1619 of file rshapes.c.

◆ CheckCollisionRecs()

bool CheckCollisionRecs ( Rectangle  rec1,
Rectangle  rec2 
)

Definition at line 1637 of file rshapes.c.

+ Here is the caller graph for this function:

◆ DrawCircle()

void DrawCircle ( int  centerX,
int  centerY,
float  radius,
Color  color 
)

Definition at line 256 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawCircleGradient()

void DrawCircleGradient ( int  centerX,
int  centerY,
float  radius,
Color  color1,
Color  color2 
)

Definition at line 417 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawCircleLines()

void DrawCircleLines ( int  centerX,
int  centerY,
float  radius,
Color  color 
)

Definition at line 442 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawCircleSector()

void DrawCircleSector ( Vector2  center,
float  radius,
float  startAngle,
float  endAngle,
int  segments,
Color  color 
)

Definition at line 262 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawCircleSectorLines()

void DrawCircleSectorLines ( Vector2  center,
float  radius,
float  startAngle,
float  endAngle,
int  segments,
Color  color 
)

Definition at line 354 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawCircleV()

void DrawCircleV ( Vector2  center,
float  radius,
Color  color 
)

Definition at line 436 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawEllipse()

void DrawEllipse ( int  centerX,
int  centerY,
float  radiusH,
float  radiusV,
Color  color 
)

Definition at line 459 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawEllipseLines()

void DrawEllipseLines ( int  centerX,
int  centerY,
float  radiusH,
float  radiusV,
Color  color 
)

Definition at line 475 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawLine()

void DrawLine ( int  startPosX,
int  startPosY,
int  endPosX,
int  endPosY,
Color  color 
)

Definition at line 125 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawLineBezier()

void DrawLineBezier ( Vector2  startPos,
Vector2  endPos,
float  thick,
Color  color 
)

Definition at line 166 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawLineBezierCubic()

void DrawLineBezierCubic ( Vector2  startPos,
Vector2  endPos,
Vector2  startControlPos,
Vector2  endControlPos,
float  thick,
Color  color 
)

Definition at line 211 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawLineBezierQuad()

void DrawLineBezierQuad ( Vector2  startPos,
Vector2  endPos,
Vector2  controlPos,
float  thick,
Color  color 
)

Definition at line 185 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawLineEx()

void DrawLineEx ( Vector2  startPos,
Vector2  endPos,
float  thick,
Color  color 
)

Definition at line 145 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawLineStrip()

void DrawLineStrip ( Vector2 points,
int  pointCount,
Color  color 
)

Definition at line 237 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawLineV()

void DrawLineV ( Vector2  startPos,
Vector2  endPos,
Color  color 
)

Definition at line 135 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawPixel()

void DrawPixel ( int  posX,
int  posY,
Color  color 
)

Definition at line 105 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawPixelV()

void DrawPixelV ( Vector2  position,
Color  color 
)

Definition at line 115 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawPoly()

void DrawPoly ( Vector2  center,
int  sides,
float  radius,
float  rotation,
Color  color 
)

Definition at line 1452 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawPolyLines()

void DrawPolyLines ( Vector2  center,
int  sides,
float  radius,
float  rotation,
Color  color 
)

Definition at line 1508 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawPolyLinesEx()

void DrawPolyLinesEx ( Vector2  center,
int  sides,
float  radius,
float  rotation,
float  lineThick,
Color  color 
)

Definition at line 1532 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawRectangle()

void DrawRectangle ( int  posX,
int  posY,
int  width,
int  height,
Color  color 
)

Definition at line 664 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawRectangleGradientEx()

void DrawRectangleGradientEx ( Rectangle  rec,
Color  col1,
Color  col2,
Color  col3,
Color  col4 
)

Definition at line 782 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawRectangleGradientH()

void DrawRectangleGradientH ( int  posX,
int  posY,
int  width,
int  height,
Color  color1,
Color  color2 
)

Definition at line 775 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawRectangleGradientV()

void DrawRectangleGradientV ( int  posX,
int  posY,
int  width,
int  height,
Color  color1,
Color  color2 
)

Definition at line 768 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawRectangleLines()

void DrawRectangleLines ( int  posX,
int  posY,
int  width,
int  height,
Color  color 
)

Definition at line 816 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawRectangleLinesEx()

void DrawRectangleLinesEx ( Rectangle  rec,
float  lineThick,
Color  color 
)

Definition at line 842 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawRectanglePro()

void DrawRectanglePro ( Rectangle  rec,
Vector2  origin,
float  rotation,
Color  color 
)

Definition at line 683 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawRectangleRec()

void DrawRectangleRec ( Rectangle  rec,
Color  color 
)

Definition at line 677 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawRectangleRounded()

void DrawRectangleRounded ( Rectangle  rec,
float  roundness,
int  segments,
Color  color 
)

Definition at line 873 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawRectangleRoundedLines()

void DrawRectangleRoundedLines ( Rectangle  rec,
float  roundness,
int  segments,
float  lineThick,
Color  color 
)

Definition at line 1095 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawRectangleV()

void DrawRectangleV ( Vector2  position,
Vector2  size,
Color  color 
)

Definition at line 671 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DrawRing()

void DrawRing ( Vector2  center,
float  innerRadius,
float  outerRadius,
float  startAngle,
float  endAngle,
int  segments,
Color  color 
)

Definition at line 490 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawRingLines()

void DrawRingLines ( Vector2  center,
float  innerRadius,
float  outerRadius,
float  startAngle,
float  endAngle,
int  segments,
Color  color 
)

Definition at line 584 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawTriangle()

void DrawTriangle ( Vector2  v1,
Vector2  v2,
Vector2  v3,
Color  color 
)

Definition at line 1334 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawTriangleFan()

void DrawTriangleFan ( Vector2 points,
int  pointCount,
Color  color 
)

Definition at line 1392 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawTriangleLines()

void DrawTriangleLines ( Vector2  v1,
Vector2  v2,
Vector2  v3,
Color  color 
)

Definition at line 1372 of file rshapes.c.

+ Here is the call graph for this function:

◆ DrawTriangleStrip()

void DrawTriangleStrip ( Vector2 points,
int  pointCount,
Color  color 
)

Definition at line 1423 of file rshapes.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetCollisionRec()

Rectangle GetCollisionRec ( Rectangle  rec1,
Rectangle  rec2 
)

Definition at line 1738 of file rshapes.c.

+ Here is the call graph for this function:

◆ SetShapesTexture()

void SetShapesTexture ( Texture2D  texture,
Rectangle  source 
)

Definition at line 98 of file rshapes.c.

+ Here is the caller graph for this function:

Variable Documentation

◆ texShapes

Texture2D texShapes = { 1, 1, 1, 1, 7 }

Definition at line 83 of file rshapes.c.

◆ texShapesRec

Rectangle texShapesRec = { 0.0f, 0.0f, 1.0f, 1.0f }

Definition at line 84 of file rshapes.c.