JNGL
Easy to use cross-platform 2D game library
Loading...
Searching...
No Matches
shapes.hpp
Go to the documentation of this file.
1// Copyright 2012-2026 Jan Niklas Hasse <jhasse@bixense.com>
2// For conditions of distribution and use, see copyright notice in LICENSE.txt
5#pragma once
6
7#include "Rgba.hpp"
8#include "Vec2.hpp"
9
10#include <cstdint>
11
12namespace jngl {
13
14class Mat3;
15class Rgba;
16
21
24
27void setColor(Rgb, unsigned char alpha);
28
29void setColor(unsigned char red, unsigned char green, unsigned char blue);
30
31void setColor(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha);
32
35void setAlpha(uint8_t alpha);
36
37[[deprecated("Use setAlpha instead")]]
39void pushAlpha(unsigned char alpha);
40
41[[deprecated("Use setAlpha instead")]]
43void popAlpha();
44
45[[deprecated("Pass line width to drawLine instead")]]
47void setLineWidth(float width);
48
51[[deprecated("Use drawLine(Vec2, Vec2, float lineWidth) instead")]]
52void drawLine(Vec2 start, Vec2 end);
53
55void drawLine(Vec2 start, Vec2 end, float lineWidth);
56
58void drawLine(Vec2 start, Vec2 end, float lineWidth, Rgba color);
59
60[[deprecated("Use drawLine(Vec2, Vec2, float lineWidth) instead")]]
62void drawLine(double xstart, double ystart, double xend, double yend);
63
68void drawLine(Mat3 modelview, Vec2 start, Vec2 end);
69
71void drawLine(Mat3 modelview, Vec2 start, Vec2 end, float lineWidth);
72
74void drawLine(Mat3 modelview, Vec2 start, Vec2 end, float lineWidth, Rgba color);
75
78[[deprecated("Use drawLine(const Mat3&, Vec2, Rgba) instead")]]
79void drawLine(const Mat3& modelview, Vec2 end);
80
82void drawLine(const Mat3& modelview, Vec2 end, Rgba color);
83
85void drawLine(Mat3 modelview, Vec2 end, float lineWidth, Rgba color);
86
88void drawLine(const Mat3& modelview, Vec2 end, float lineWidth);
89
90[[deprecated("Use drawEllipse(Mat3, float, float, float) instead")]]
92void drawEllipse(float xmid, float ymid, float width, float height, float startAngle = 0);
93
94void drawEllipse(Vec2, float width, float height, float startAngle = 0);
95
96void drawEllipse(const Mat3& modelview, float width, float height, float startAngle = 0);
97
98void drawEllipse(const Mat3& modelview, float width, float height, float startAngle, Rgba color);
99
101void drawCircle(Vec2, float radius, float startAngle = 0);
102
103void drawCircle(const Mat3& modelview, float radius, float startAngle);
104
123void drawCircle(const Mat3& modelview, float radius, float startAngle, Rgba color);
124
125void drawCircle(const Mat3& modelview, float radius);
126
128void drawCircle(Mat3 modelview, float radius, Rgba color);
129
131void drawCircle(const Mat3& modelview, Rgba color);
132
137void drawCircleOutline(const Mat3& modelview, float radius, float lineWidth, Rgba color);
138
139[[deprecated("Use drawCircle instead")]]
141void drawPoint(double x, double y);
142
145
146[[deprecated("Use drawTriangle(Vec2, Vec2, Vec2) instead")]]
148void drawTriangle(double A_x, double A_y, double B_x, double B_y, double C_x, double C_y);
149
154
157[[deprecated("Use drawRect(const Mat3&, Vec2, Color) instead")]]
158void drawRect(double xposition, double yposition, double width, double height);
159
164[[deprecated("Use drawRect(Mat3, Vec2, Rgba) instead")]]
165void drawRect(Vec2 position, Vec2 size);
166
170void drawRect(const Mat3& modelview, Vec2 size, Rgb);
171
175void drawRect(Mat3 modelview, Vec2 size, Rgba color);
176
178void drawRoundedRect(Mat3 modelview, Vec2 size, Rgba color, float topLeft, float topRight,
179 float bottomLeft, float bottomRight);
180
183void drawRing(Mat3 modelview, float innerRadius, float outerRadius, float startAngle,
184 float endAngle, Rgba color);
185
187void drawRectOutline(Mat3 modelview, Vec2 size, float lineWidth, Rgba color);
188
197void drawSquare(const Mat3& modelview, Rgba color);
198
211void drawSquareOutline(Mat3 modelview, float lineWidth, Rgba color);
212
213template <class Vect> void drawRect(Vect pos, Vect size) {
214 drawRect(pos.x, pos.y, size.x, size.y);
215}
216
217} // namespace jngl
Contains jngl::Rgba class.
Contains jngl::Vec2 class.
3x3 matrix
Definition Mat3.hpp:18
Object representing a RGB color, new version of jngl::Color (which will be deprecated in the future)
Definition Rgb.hpp:21
Object representing a RGBA color.
Definition Rgba.hpp:22
Two-dimensional vector.
Definition Vec2.hpp:36
JNGL's main namespace.
void drawRectOutline(Mat3 modelview, Vec2 size, float lineWidth, Rgba color)
Draws the outline of a rectangle (so □ instead of ■) of size centered at (0, 0) in color.
void drawSquare(const Mat3 &modelview, Rgba color)
Draws a (filled) square of size 1x1 centered at (0, 0) with the specified color.
void drawTriangle(Vec2 a, Vec2 b, Vec2 c)
Draws the triangle a -> b -> c.
void setAlpha(uint8_t alpha)
Sets the alpha value which should be used to draw primitives (0 = fully transparent,...
void pushAlpha(unsigned char alpha)
void drawSquareOutline(Mat3 modelview, float lineWidth, Rgba color)
Draws the outline of a square (so □ instead of ■) of size 1x1 centered at (0, 0) with the specified c...
void setColor(Rgb)
Sets the color which should be used to draw primitives.
void drawCircleOutline(const Mat3 &modelview, float radius, float lineWidth, Rgba color)
Draws the outline of a circle (so ○ instead of ●) at (0, 0) with radius in color.
void drawEllipse(float xmid, float ymid, float width, float height, float startAngle=0)
void drawPoint(double x, double y)
void setLineWidth(float width)
jngl::Mat3 modelview()
Returns a copy of the global ModelView matrix.
void drawCircle(Vec2, float radius, float startAngle=0)
Angles in radian.
void drawLine(Vec2 start, Vec2 end)
Draws a line from start to end, the width can be set using setLineWidth.
void popAlpha()
void drawRoundedRect(Mat3 modelview, Vec2 size, Rgba color, float topLeft, float topRight, float bottomLeft, float bottomRight)
Draws a rectangle spawning from (0, 0) to (size.x, size.y) with rounded corners.
void drawRect(double xposition, double yposition, double width, double height)
Draws a rectangle at { xposition, yposition }.
void drawRing(Mat3 modelview, float innerRadius, float outerRadius, float startAngle, float endAngle, Rgba color)
Draws an annulus sector (ring) centered at (0, 0).