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