twn_draw.c: add draw_quad()

This commit is contained in:
veclavtalica 2025-01-14 02:53:18 +03:00
parent 86bf16b680
commit 2351d4114c
3 changed files with 48 additions and 0 deletions

View File

@ -55,6 +55,14 @@ TWN_API void draw_triangle(char const *texture,
Color c1, /* optional, default: all 255 */
Color c2); /* optional, default: all 255 */
TWN_API void draw_quad(char const *texture,
Vec3 v0, /* upper-left */
Vec3 v1, /* bottom-left */
Vec3 v2, /* bottom-right */
Vec3 v3, /* upper-right */
Rect texture_region,
Color color); /* optional, default: all 255 */
TWN_API void draw_billboard(const char *texture,
Vec3 position,
Vec2 size,

View File

@ -145,6 +145,21 @@
]
},
"draw_quad": {
"module": "draw",
"symbol": "quad",
"header": "twn_draw.h",
"params": [
{ "name": "texture", "type": "char *" },
{ "name": "v0", "type": "Vec3" },
{ "name": "v1", "type": "Vec3" },
{ "name": "v2", "type": "Vec3" },
{ "name": "v3", "type": "Vec3" },
{ "name": "texture_region", "type": "Rect" },
{ "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } }
]
},
"draw_billboard": {
"module": "draw",
"symbol": "billboard",

View File

@ -179,6 +179,31 @@ void draw_nine_slice(const char *texture, Vec2 corners, Rect rect, float border_
}
TWN_API void draw_quad(char const *texture,
Vec3 v0, /* upper-left */
Vec3 v1, /* bottom-left */
Vec3 v2, /* bottom-right */
Vec3 v3, /* upper-right */
Rect texture_region,
Color color)
{
Vec2 const uv0 = { texture_region.x, texture_region.y };
Vec2 const uv1 = { texture_region.x, texture_region.y + texture_region.h };
Vec2 const uv2 = { texture_region.x + texture_region.w, texture_region.y + texture_region.h };
Vec2 const uv3 = { texture_region.x + texture_region.w, texture_region.y };
draw_triangle(texture,
v0, v1, v3,
uv0, uv1, uv3,
color, color, color);
draw_triangle(texture,
v3, v1, v2,
uv3, uv1, uv2,
color, color, color);
}
static void render_2d(void) {
use_2d_pipeline();