citro2d
base.h
Go to the documentation of this file.
1 /**
2  * @file base.h
3  * @brief Basic citro2d initialization and drawing API
4  */
5 #pragma once
6 #include <citro3d.h>
7 #include <tex3ds.h>
8 
9 #define C2D_DEFAULT_MAX_OBJECTS 4096
10 
11 #ifdef __cplusplus
12 #define C2D_CONSTEXPR constexpr
13 #define C2D_OPTIONAL(_x) =_x
14 #else
15 #define C2D_CONSTEXPR static inline
16 #define C2D_OPTIONAL(_x)
17 #endif
18 
19 typedef struct
20 {
21  struct
22  {
23  float x, y, w, h;
24  } pos;
25 
26  struct
27  {
28  float x, y;
29  } center;
30 
31  float depth;
32  float angle;
34 
35 typedef struct
36 {
37  u32 color; ///< RGB tint color and Alpha transparency
38  float blend; ///< Blending strength of the tint color (0.0~1.0)
39 } C2D_Tint;
40 
41 typedef enum
42 {
43  C2D_TopLeft, ///< Top left corner
44  C2D_TopRight, ///< Top right corner
45  C2D_BotLeft, ///< Bottom left corner
46  C2D_BotRight, ///< Bottom right corner
47 } C2D_Corner;
48 
49 typedef struct
50 {
51  C3D_Tex* tex;
52  const Tex3DS_SubTexture* subtex;
53 } C2D_Image;
54 
55 typedef struct
56 {
57  C2D_Tint corners[4];
59 
60 /** @defgroup Helper Helper functions
61  * @{
62  */
63 
64 /** @brief Clamps a value between bounds
65  * @param[in] x The value to clamp
66  * @param[in] min The lower bound
67  * @param[in] max The upper bound
68  * @returns The clamped value
69  */
70 C2D_CONSTEXPR float C2D_Clamp(float x, float min, float max)
71 {
72  return x <= min ? min : x >= max ? max : x;
73 }
74 
75 /** @brief Converts a float to u8
76  * @param[in] x Input value (0.0~1.0)
77  * @returns Output value (0~255)
78  */
79 C2D_CONSTEXPR u8 C2D_FloatToU8(float x)
80 {
81  return (u8)(255.0f*C2D_Clamp(x, 0.0f, 1.0f)+0.5f);
82 }
83 
84 /** @brief Builds a 32-bit RGBA color value
85  * @param[in] r Red component (0~255)
86  * @param[in] g Green component (0~255)
87  * @param[in] b Blue component (0~255)
88  * @param[in] a Alpha component (0~255)
89  * @returns The 32-bit RGBA color value
90  */
91 C2D_CONSTEXPR u32 C2D_Color32(u8 r, u8 g, u8 b, u8 a)
92 {
93  return r | (g << (u32)8) | (b << (u32)16) | (a << (u32)24);
94 }
95 
96 /** @brief Builds a 32-bit RGBA color value from float values
97  * @param[in] r Red component (0.0~1.0)
98  * @param[in] g Green component (0.0~1.0)
99  * @param[in] b Blue component (0.0~1.0)
100  * @param[in] a Alpha component (0.0~1.0)
101  * @returns The 32-bit RGBA color value
102  */
103 C2D_CONSTEXPR u32 C2D_Color32f(float r, float g, float b, float a)
104 {
106 }
107 
108 /** @brief Configures one corner of an image tint structure
109  * @param[in] tint Image tint structure
110  * @param[in] corner The corner of the image to tint
111  * @param[in] color RGB tint color and Alpha transparency
112  * @param[in] blend Blending strength of the tint color (0.0~1.0)
113  */
114 static inline void C2D_SetImageTint(C2D_ImageTint* tint, C2D_Corner corner, u32 color, float blend)
115 {
116  tint->corners[corner].color = color;
117  tint->corners[corner].blend = blend;
118 }
119 
120 /** @brief Configures an image tint structure with the specified tint parameters applied to all corners
121  * @param[in] tint Image tint structure
122  * @param[in] color RGB tint color and Alpha transparency
123  * @param[in] blend Blending strength of the tint color (0.0~1.0)
124  */
125 static inline void C2D_PlainImageTint(C2D_ImageTint* tint, u32 color, float blend)
126 {
127  C2D_SetImageTint(tint, C2D_TopLeft, color, blend);
128  C2D_SetImageTint(tint, C2D_TopRight, color, blend);
129  C2D_SetImageTint(tint, C2D_BotLeft, color, blend);
130  C2D_SetImageTint(tint, C2D_BotRight, color, blend);
131 }
132 
133 /** @brief Configures an image tint structure to just apply transparency to the image
134  * @param[in] tint Image tint structure
135  * @param[in] alpha Alpha transparency value to apply to the image
136  */
137 static inline void C2D_AlphaImageTint(C2D_ImageTint* tint, float alpha)
138 {
139  C2D_PlainImageTint(tint, C2D_Color32f(0.0f, 0.0f, 0.0f, alpha), 0.0f);
140 }
141 
142 /** @brief Configures an image tint structure with the specified tint parameters applied to the top side (e.g. for gradients)
143  * @param[in] tint Image tint structure
144  * @param[in] color RGB tint color and Alpha transparency
145  * @param[in] blend Blending strength of the tint color (0.0~1.0)
146  */
147 static inline void C2D_TopImageTint(C2D_ImageTint* tint, u32 color, float blend)
148 {
149  C2D_SetImageTint(tint, C2D_TopLeft, color, blend);
150  C2D_SetImageTint(tint, C2D_TopRight, color, blend);
151 }
152 
153 /** @brief Configures an image tint structure with the specified tint parameters applied to the bottom side (e.g. for gradients)
154  * @param[in] tint Image tint structure
155  * @param[in] color RGB tint color and Alpha transparency
156  * @param[in] blend Blending strength of the tint color (0.0~1.0)
157  */
158 static inline void C2D_BottomImageTint(C2D_ImageTint* tint, u32 color, float blend)
159 {
160  C2D_SetImageTint(tint, C2D_BotLeft, color, blend);
161  C2D_SetImageTint(tint, C2D_BotRight, color, blend);
162 }
163 
164 /** @brief Configures an image tint structure with the specified tint parameters applied to the left side (e.g. for gradients)
165  * @param[in] tint Image tint structure
166  * @param[in] color RGB tint color and Alpha transparency
167  * @param[in] blend Blending strength of the tint color (0.0~1.0)
168  */
169 static inline void C2D_LeftImageTint(C2D_ImageTint* tint, u32 color, float blend)
170 {
171  C2D_SetImageTint(tint, C2D_TopLeft, color, blend);
172  C2D_SetImageTint(tint, C2D_BotLeft, color, blend);
173 }
174 
175 /** @brief Configures an image tint structure with the specified tint parameters applied to the right side (e.g. for gradients)
176  * @param[in] tint Image tint structure
177  * @param[in] color RGB tint color and Alpha transparency
178  * @param[in] blend Blending strength of the tint color (0.0~1.0)
179  */
180 static inline void C2D_RightImageTint(C2D_ImageTint* tint, u32 color, float blend)
181 {
182  C2D_SetImageTint(tint, C2D_TopRight, color, blend);
183  C2D_SetImageTint(tint, C2D_BotRight, color, blend);
184 }
185 
186 /** @} */
187 
188 /** @defgroup Base Basic functions
189  * @{
190  */
191 
192 /** @brief Initialize citro2d
193  * @param[in] maxObjects Maximum number of 2D objects that can be drawn per frame.
194  * @remarks Pass C2D_DEFAULT_MAX_OBJECTS as a starting point.
195  * @returns true on success, false on failure
196  */
197 bool C2D_Init(size_t maxObjects);
198 
199 /** @brief Deinitialize citro2d */
200 void C2D_Fini(void);
201 
202 /** @brief Prepares the GPU for rendering 2D content
203  * @remarks This needs to be done only once in the program if citro2d is the sole user of the GPU.
204  */
205 void C2D_Prepare(void);
206 
207 /** @brief Ensures all 2D objects so far have been drawn */
208 void C2D_Flush(void);
209 
210 /** @brief Configures the size of the 2D scene.
211  * @param[in] width The width of the scene, in pixels.
212  * @param[in] height The height of the scene, in pixels.
213  * @param[in] tilt Whether the scene is tilted like the 3DS's sideways screens.
214  */
215 void C2D_SceneSize(u32 width, u32 height, bool tilt);
216 
217 /** @brief Configures the size of the 2D scene to match that of the specified render target.
218  * @param[in] target Render target
219  */
220 static inline void C2D_SceneTarget(C3D_RenderTarget* target)
221 {
222  C2D_SceneSize(target->frameBuf.width, target->frameBuf.height, target->linked);
223 }
224 
225 /** @brief Resets the model transformation matrix. */
226 void C2D_ViewReset(void);
227 
228 /** @brief Saves the current model transformation matrix.
229  * @param[out] matrix Pointer to save the current matrix to
230  */
231 void C2D_ViewSave(C3D_Mtx* matrix);
232 
233 /** @brief Restores a previously saved model transformation matrix.
234  * @param[in] matrix Pointer to matrix to restor
235  */
236 void C2D_ViewRestore(const C3D_Mtx* matrix);
237 
238 /** @brief Translates everything drawn via the model matrix.
239  * @param[in] x Translation in the x direction
240  * @param[in] y Translation in the y direction
241  */
242 void C2D_ViewTranslate(float x, float y);
243 
244 /** @brief Rotates everything drawn via the model matrix.
245  * @param[in] rotation Rotation in the counterclockwise direction in radians
246  */
247 void C2D_ViewRotate(float rotation);
248 
249 /** @brief Rotates everything drawn via the model matrix.
250  * @param[in] rotation Rotation in the counterclockwise direction in degrees
251  */
252 static inline void C2D_ViewRotateDegrees(float rotation)
253 {
254  C2D_ViewRotate(C3D_AngleFromDegrees(rotation));
255 }
256 
257 /** @brief Shears everything drawn via the model matrix.
258  * @param[in] x Shear factor in the x direction
259  * @param[in] y Shear factor in the y direction
260  */
261 void C2D_ViewShear(float x, float y);
262 
263 /** @brief Scales everything drawn via the model matrix.
264  * @param[in] x Scale factor in the x direction
265  * @param[in] y Scale factor in the y direction
266  */
267 void C2D_ViewScale(float x, float y);
268 
269 /** @brief Helper function to create a render target for a screen
270  * @param[in] screen Screen (GFX_TOP or GFX_BOTTOM)
271  * @param[in] side Side (GFX_LEFT or GFX_RIGHT)
272  * @returns citro3d render target object
273  */
274 C3D_RenderTarget* C2D_CreateScreenTarget(gfxScreen_t screen, gfx3dSide_t side);
275 
276 /** @brief Helper function to clear a rendertarget using the specified color
277  * @param[in] target Render target to clear
278  * @param[in] color 32-bit RGBA color value to fill the target with
279  */
280 void C2D_TargetClear(C3D_RenderTarget* target, u32 color);
281 
282 /** @brief Helper function to begin drawing a 2D scene on a render target
283  * @param[in] target Render target to draw the 2D scene to
284  */
285 static inline void C2D_SceneBegin(C3D_RenderTarget* target)
286 {
287  C2D_Flush();
288  C3D_FrameDrawOn(target);
289  C2D_SceneTarget(target);
290 }
291 
292 /** @} */
293 
294 /** @defgroup Env Drawing environment functions
295  * @{
296  */
297 
298 /** @brief Configures the fading color
299  * @param[in] color 32-bit RGBA color value to be used as the fading color (0 by default)
300  * @remark The alpha component of the color is used as the strength of the fading color.
301  * If alpha is zero, the fading color has no effect. If it is the highest value,
302  * the rendered pixels will all have the fading color. Everything inbetween is
303  * rendered as a blend of the original pixel color and the fading color.
304  */
305 void C2D_Fade(u32 color);
306 
307 /** @} */
308 
309 /** @defgroup Drawing Drawing functions
310  * @{
311  */
312 
313 /** @brief Draws an image using the GPU (variant accepting C2D_DrawParams)
314  * @param[in] img Handle of the image to draw
315  * @param[in] params Parameters with which to draw the image
316  * @param[in] tint Tint parameters to apply to the image (optional, can be null)
317  * @returns true on success, false on failure
318  */
319 bool C2D_DrawImage(C2D_Image img, const C2D_DrawParams* params, const C2D_ImageTint* tint C2D_OPTIONAL(nullptr));
320 
321 /** @brief Draws an image using the GPU (variant accepting position/scaling)
322  * @param[in] img Handle of the image to draw
323  * @param[in] x X coordinate at which to place the top left corner of the image
324  * @param[in] y Y coordinate at which to place the top left corner of the image
325  * @param[in] depth Depth value to draw the image with
326  * @param[in] tint Tint parameters to apply to the image (optional, can be null)
327  * @param[in] scaleX Horizontal scaling factor to apply to the image (optional, by default 1.0f); negative values apply a horizontal flip
328  * @param[in] scaleY Vertical scaling factor to apply to the image (optional, by default 1.0f); negative values apply a vertical flip
329  */
330 static inline bool C2D_DrawImageAt(C2D_Image img, float x, float y, float depth,
331  const C2D_ImageTint* tint C2D_OPTIONAL(nullptr),
332  float scaleX C2D_OPTIONAL(1.0f), float scaleY C2D_OPTIONAL(1.0f))
333 {
334  C2D_DrawParams params =
335  {
336  { x, y, scaleX*img.subtex->width, scaleY*img.subtex->height },
337  { 0.0f, 0.0f },
338  depth, 0.0f
339  };
340  return C2D_DrawImage(img, &params, tint);
341 }
342 
343 /** @brief Draws an image using the GPU (variant accepting position/scaling/rotation)
344  * @param[in] img Handle of the image to draw
345  * @param[in] x X coordinate at which to place the center of the image
346  * @param[in] y Y coordinate at which to place the center of the image
347  * @param[in] depth Depth value to draw the image with
348  * @param[in] angle Angle (in radians) to rotate the image by, counter-clockwise
349  * @param[in] tint Tint parameters to apply to the image (optional, can be null)
350  * @param[in] scaleX Horizontal scaling factor to apply to the image (optional, by default 1.0f); negative values apply a horizontal flip
351  * @param[in] scaleY Vertical scaling factor to apply to the image (optional, by default 1.0f); negative values apply a vertical flip
352  */
353 static inline bool C2D_DrawImageAtRotated(C2D_Image img, float x, float y, float depth, float angle,
354  const C2D_ImageTint* tint C2D_OPTIONAL(nullptr),
355  float scaleX C2D_OPTIONAL(1.0f), float scaleY C2D_OPTIONAL(1.0f))
356 {
357  C2D_DrawParams params =
358  {
359  { x, y, scaleX*img.subtex->width, scaleY*img.subtex->height },
360  { (scaleX*img.subtex->width)/2.0f, (scaleY*img.subtex->height)/2.0f },
361  depth, angle
362  };
363  return C2D_DrawImage(img, &params, tint);
364 }
365 
366 /** @brief Draws a plain triangle using the GPU
367  * @param[in] x0 X coordinate of the first vertex of the triangle
368  * @param[in] y0 Y coordinate of the first vertex of the triangle
369  * @param[in] clr0 32-bit RGBA color of the first vertex of the triangle
370  * @param[in] x1 X coordinate of the second vertex of the triangle
371  * @param[in] y1 Y coordinate of the second vertex of the triangle
372  * @param[in] clr1 32-bit RGBA color of the second vertex of the triangle
373  * @param[in] x2 X coordinate of the third vertex of the triangle
374  * @param[in] y2 Y coordinate of the third vertex of the triangle
375  * @param[in] clr2 32-bit RGBA color of the third vertex of the triangle
376  * @param[in] depth Depth value to draw the triangle with
377  */
378 bool C2D_DrawTriangle(
379  float x0, float y0, u32 clr0,
380  float x1, float y1, u32 clr1,
381  float x2, float y2, u32 clr2,
382  float depth);
383 
384 /** @brief Draws a plain line using the GPU
385  * @param[in] x0 X coordinate of the first vertex of the line
386  * @param[in] y0 Y coordinate of the first vertex of the line
387  * @param[in] clr0 32-bit RGBA color of the first vertex of the line
388  * @param[in] x1 X coordinate of the second vertex of the line
389  * @param[in] y1 Y coordinate of the second vertex of the line
390  * @param[in] clr1 32-bit RGBA color of the second vertex of the line
391  * @param[in] thickness Thickness, in pixels, of the line
392  * @param[in] depth Depth value to draw the line with
393  */
394 bool C2D_DrawLine(
395  float x0, float y0, u32 clr0,
396  float x1, float y1, u32 clr1,
397  float thickness, float depth);
398 
399 /** @brief Draws a plain rectangle using the GPU
400  * @param[in] x X coordinate of the top-left vertex of the rectangle
401  * @param[in] y Y coordinate of the top-left vertex of the rectangle
402  * @param[in] z Z coordinate (depth value) to draw the rectangle with
403  * @param[in] w Width of the rectangle
404  * @param[in] h Height of the rectangle
405  * @param[in] clr0 32-bit RGBA color of the top-left corner of the rectangle
406  * @param[in] clr1 32-bit RGBA color of the top-right corner of the rectangle
407  * @param[in] clr2 32-bit RGBA color of the bottom-left corner of the rectangle
408  * @param[in] clr3 32-bit RGBA color of the bottom-right corner of the rectangle
409  */
410 bool C2D_DrawRectangle(
411  float x, float y, float z, float w, float h,
412  u32 clr0, u32 clr1, u32 clr2, u32 clr3);
413 
414 /** @brief Draws a plain rectangle using the GPU (with a solid color)
415  * @param[in] x X coordinate of the top-left vertex of the rectangle
416  * @param[in] y Y coordinate of the top-left vertex of the rectangle
417  * @param[in] z Z coordinate (depth value) to draw the rectangle with
418  * @param[in] w Width of the rectangle
419  * @param[in] h Height of the rectangle
420  * @param[in] clr 32-bit RGBA color of the rectangle
421  */
422 static inline bool C2D_DrawRectSolid(
423  float x, float y, float z, float w, float h,
424  u32 clr)
425 {
426  return C2D_DrawRectangle(x,y,z,w,h,clr,clr,clr,clr);
427 }
428 
429 /** @brief Draws an ellipse using the GPU
430  * @param[in] x X coordinate of the top-left vertex of the ellipse
431  * @param[in] y Y coordinate of the top-left vertex of the ellipse
432  * @param[in] z Z coordinate (depth value) to draw the ellipse with
433  * @param[in] w Width of the ellipse
434  * @param[in] h Height of the ellipse
435  * @param[in] clr0 32-bit RGBA color of the top-left corner of the ellipse
436  * @param[in] clr1 32-bit RGBA color of the top-right corner of the ellipse
437  * @param[in] clr2 32-bit RGBA color of the bottom-left corner of the ellipse
438  * @param[in] clr3 32-bit RGBA color of the bottom-right corner of the ellipse
439  * @note Switching to and from "circle mode" internally requires an expensive state change. As such, the recommended usage of this feature is to draw all non-circular objects first, then draw all circular objects.
440 */
441 bool C2D_DrawEllipse(
442  float x, float y, float z, float w, float h,
443  u32 clr0, u32 clr1, u32 clr2, u32 clr3);
444 
445 /** @brief Draws a ellipse using the GPU (with a solid color)
446  * @param[in] x X coordinate of the top-left vertex of the ellipse
447  * @param[in] y Y coordinate of the top-left vertex of the ellipse
448  * @param[in] z Z coordinate (depth value) to draw the ellipse with
449  * @param[in] w Width of the ellipse
450  * @param[in] h Height of the ellipse
451  * @param[in] clr 32-bit RGBA color of the ellipse
452  * @note Switching to and from "circle mode" internally requires an expensive state change. As such, the recommended usage of this feature is to draw all non-circular objects first, then draw all circular objects.
453 */
454 static inline bool C2D_DrawEllipseSolid(
455  float x, float y, float z, float w, float h,
456  u32 clr)
457 {
458  return C2D_DrawEllipse(x,y,z,w,h,clr,clr,clr,clr);
459 }
460 
461 /** @brief Draws a circle (an ellipse with identical width and height) using the GPU
462  * @param[in] x X coordinate of the center of the circle
463  * @param[in] y Y coordinate of the center of the circle
464  * @param[in] z Z coordinate (depth value) to draw the ellipse with
465  * @param[in] radius Radius of the circle
466  * @param[in] clr0 32-bit RGBA color of the top-left corner of the ellipse
467  * @param[in] clr1 32-bit RGBA color of the top-right corner of the ellipse
468  * @param[in] clr2 32-bit RGBA color of the bottom-left corner of the ellipse
469  * @param[in] clr3 32-bit RGBA color of the bottom-right corner of the ellipse
470  * @note Switching to and from "circle mode" internally requires an expensive state change. As such, the recommended usage of this feature is to draw all non-circular objects first, then draw all circular objects.
471 */
472 static inline bool C2D_DrawCircle(
473  float x, float y, float z, float radius,
474  u32 clr0, u32 clr1, u32 clr2, u32 clr3)
475 {
476  return C2D_DrawEllipse(
477  x - radius,y - radius,z,radius*2,radius*2,
478  clr0,clr1,clr2,clr3);
479 }
480 
481 /** @brief Draws a circle (an ellipse with identical width and height) using the GPU (with a solid color)
482  * @param[in] x X coordinate of the center of the circle
483  * @param[in] y Y coordinate of the center of the circle
484  * @param[in] z Z coordinate (depth value) to draw the ellipse with
485  * @param[in] radius Radius of the circle
486  * @param[in] clr 32-bit RGBA color of the ellipse
487  * @note Switching to and from "circle mode" internally requires an expensive state change. As such, the recommended usage of this feature is to draw all non-circular objects first, then draw all circular objects.
488 */
489 static inline bool C2D_DrawCircleSolid(
490  float x, float y, float z, float radius,
491  u32 clr)
492 {
493  return C2D_DrawCircle(x,y,z,radius,clr,clr,clr,clr);
494 }
495 /** @} */
bool C2D_DrawTriangle(float x0, float y0, u32 clr0, float x1, float y1, u32 clr1, float x2, float y2, u32 clr2, float depth)
Draws a plain triangle using the GPU.
static void C2D_TopImageTint(C2D_ImageTint *tint, u32 color, float blend)
Configures an image tint structure with the specified tint parameters applied to the top side (e...
Definition: base.h:147
static void C2D_SetImageTint(C2D_ImageTint *tint, C2D_Corner corner, u32 color, float blend)
Configures one corner of an image tint structure.
Definition: base.h:114
static void C2D_BottomImageTint(C2D_ImageTint *tint, u32 color, float blend)
Configures an image tint structure with the specified tint parameters applied to the bottom side (e...
Definition: base.h:158
C2D_CONSTEXPR u32 C2D_Color32(u8 r, u8 g, u8 b, u8 a)
Builds a 32-bit RGBA color value.
Definition: base.h:91
Bottom left corner.
Definition: base.h:45
static void C2D_AlphaImageTint(C2D_ImageTint *tint, float alpha)
Configures an image tint structure to just apply transparency to the image.
Definition: base.h:137
void C2D_Fini(void)
Deinitialize citro2d.
void C2D_TargetClear(C3D_RenderTarget *target, u32 color)
Helper function to clear a rendertarget using the specified color.
static void C2D_ViewRotateDegrees(float rotation)
Rotates everything drawn via the model matrix.
Definition: base.h:252
Bottom right corner.
Definition: base.h:46
static bool C2D_DrawCircleSolid(float x, float y, float z, float radius, u32 clr)
Draws a circle (an ellipse with identical width and height) using the GPU (with a solid color) ...
Definition: base.h:489
bool C2D_DrawRectangle(float x, float y, float z, float w, float h, u32 clr0, u32 clr1, u32 clr2, u32 clr3)
Draws a plain rectangle using the GPU.
void C2D_ViewReset(void)
Resets the model transformation matrix.
void C2D_Prepare(void)
Prepares the GPU for rendering 2D content.
void C2D_Flush(void)
Ensures all 2D objects so far have been drawn.
C2D_CONSTEXPR float C2D_Clamp(float x, float min, float max)
Clamps a value between bounds.
Definition: base.h:70
C2D_CONSTEXPR u32 C2D_Color32f(float r, float g, float b, float a)
Builds a 32-bit RGBA color value from float values.
Definition: base.h:103
static void C2D_PlainImageTint(C2D_ImageTint *tint, u32 color, float blend)
Configures an image tint structure with the specified tint parameters applied to all corners...
Definition: base.h:125
bool C2D_DrawImage(C2D_Image img, const C2D_DrawParams *params, const C2D_ImageTint *tint C2D_OPTIONAL(nullptr))
Draws an image using the GPU (variant accepting C2D_DrawParams)
Definition: base.h:49
void C2D_ViewTranslate(float x, float y)
Translates everything drawn via the model matrix.
static void C2D_LeftImageTint(C2D_ImageTint *tint, u32 color, float blend)
Configures an image tint structure with the specified tint parameters applied to the left side (e...
Definition: base.h:169
static void C2D_SceneTarget(C3D_RenderTarget *target)
Configures the size of the 2D scene to match that of the specified render target. ...
Definition: base.h:220
Definition: base.h:35
void C2D_ViewRotate(float rotation)
Rotates everything drawn via the model matrix.
static bool C2D_DrawEllipseSolid(float x, float y, float z, float w, float h, u32 clr)
Draws a ellipse using the GPU (with a solid color)
Definition: base.h:454
Definition: base.h:55
Top left corner.
Definition: base.h:43
float blend
Blending strength of the tint color (0.0~1.0)
Definition: base.h:38
C3D_RenderTarget * C2D_CreateScreenTarget(gfxScreen_t screen, gfx3dSide_t side)
Helper function to create a render target for a screen.
static void C2D_RightImageTint(C2D_ImageTint *tint, u32 color, float blend)
Configures an image tint structure with the specified tint parameters applied to the right side (e...
Definition: base.h:180
void C2D_Fade(u32 color)
Configures the fading color.
void C2D_SceneSize(u32 width, u32 height, bool tilt)
Configures the size of the 2D scene.
Definition: base.h:19
static bool C2D_DrawRectSolid(float x, float y, float z, float w, float h, u32 clr)
Draws a plain rectangle using the GPU (with a solid color)
Definition: base.h:422
static bool C2D_DrawImageAt(C2D_Image img, float x, float y, float depth, const C2D_ImageTint *tint C2D_OPTIONAL(nullptr), float scaleX C2D_OPTIONAL(1.0f), float scaleY C2D_OPTIONAL(1.0f))
Draws an image using the GPU (variant accepting position/scaling)
Definition: base.h:330
C2D_CONSTEXPR u8 C2D_FloatToU8(float x)
Converts a float to u8.
Definition: base.h:79
Top right corner.
Definition: base.h:44
void C2D_ViewRestore(const C3D_Mtx *matrix)
Restores a previously saved model transformation matrix.
u32 color
RGB tint color and Alpha transparency.
Definition: base.h:37
C2D_Corner
Definition: base.h:41
void C2D_ViewShear(float x, float y)
Shears everything drawn via the model matrix.
static bool C2D_DrawCircle(float x, float y, float z, float radius, u32 clr0, u32 clr1, u32 clr2, u32 clr3)
Draws a circle (an ellipse with identical width and height) using the GPU.
Definition: base.h:472
bool C2D_DrawEllipse(float x, float y, float z, float w, float h, u32 clr0, u32 clr1, u32 clr2, u32 clr3)
Draws an ellipse using the GPU.
void C2D_ViewScale(float x, float y)
Scales everything drawn via the model matrix.
bool C2D_DrawLine(float x0, float y0, u32 clr0, float x1, float y1, u32 clr1, float thickness, float depth)
Draws a plain line using the GPU.
void C2D_ViewSave(C3D_Mtx *matrix)
Saves the current model transformation matrix.
static void C2D_SceneBegin(C3D_RenderTarget *target)
Helper function to begin drawing a 2D scene on a render target.
Definition: base.h:285
static bool C2D_DrawImageAtRotated(C2D_Image img, float x, float y, float depth, float angle, const C2D_ImageTint *tint C2D_OPTIONAL(nullptr), float scaleX C2D_OPTIONAL(1.0f), float scaleY C2D_OPTIONAL(1.0f))
Draws an image using the GPU (variant accepting position/scaling/rotation)
Definition: base.h:353
bool C2D_Init(size_t maxObjects)
Initialize citro2d.