api changes and progress on filling in twn_api.json

This commit is contained in:
veclavtalica 2025-01-07 14:14:21 +03:00
parent 5c89c55b3e
commit 8c401eda75
5 changed files with 92 additions and 23 deletions

View File

@ -159,7 +159,10 @@ static void draw_terrain(SceneIngame *scn) {
(Vec3){ (float)x, d3, (float)y - 1 },
(Vec2){ 128, 128 },
(Vec2){ 128, 0 },
(Vec2){ 0, 128 });
(Vec2){ 0, 128 },
(Color){255, 255, 255, 255},
(Color){255, 255, 255, 255},
(Color){255, 255, 255, 255});
draw_triangle("/assets/grass.png",
(Vec3){ (float)x + 1, d1, (float)y },
@ -167,7 +170,10 @@ static void draw_terrain(SceneIngame *scn) {
(Vec3){ (float)x, d3, (float)y - 1 },
(Vec2){ 128, 0 },
(Vec2){ 0, 0 },
(Vec2){ 0, 128 });
(Vec2){ 0, 128 },
(Color){255, 255, 255, 255},
(Color){255, 255, 255, 255},
(Color){255, 255, 255, 255});
draw_billboard("/assets/grasses/10.png",
(Vec3){ (float)x, d0 + 0.15f, (float)y },

View File

@ -15,7 +15,7 @@ function game_tick()
}
draw.sprite {
path = "/assets/title.png",
texture = "/assets/title.png",
rect = {
x = 320 - (320 / 2),
y = 180 - (128 / 2),

View File

@ -50,22 +50,10 @@ TWN_API void draw_triangle(char const *texture,
Vec3 v2,
Vec2 uv0,
Vec2 uv1,
Vec2 uv2);
// TODO: decide whether it's needed to begin with?
// intended usage for it is baked lighting, i would think.
// TODO: instead add optional color parameters to 'draw_triangle'
/* pushes a colored textured 3d triangle onto the render queue */
// void unfurl_colored_triangle(const char *path,
// Vec3 v0,
// Vec3 v1,
// Vec3 v2,
// Vec2sh uv0,
// Vec2sh uv1,
// Vec2sh uv2,
// Color c0,
// Color c1,
// Color c2);
Vec2 uv2,
Color c0, /* optional, default: all 255 */
Color c1, /* optional, default: all 255 */
Color c2); /* optional, default: all 255 */
TWN_API void draw_billboard(const char *texture,
Vec3 position,
@ -90,9 +78,13 @@ TWN_API DrawCameraFromPrincipalAxesResult draw_camera_from_principal_axes(Vec3 p
float yaw);
/* expects '*' masks that will be expanded to 6 names: 'up', 'down', 'east', 'west', 'north' and 'south' */
TWN_API void draw_skybox(const char *paths);
TWN_API void draw_skybox(const char *textures);
TWN_API void draw_fog(float start, float end, float density, Color color);
/* only one for setting is supported for a frame, any call overwrites previous */
TWN_API void draw_fog(float start, /* optional, default: 0.0 */
float end, /* optional, default: 1.0 */
float density, /* optional, default: 0.0 */
Color color); /* optional, default: all 255 */
#ifndef TWN_NOT_C

View File

@ -66,7 +66,7 @@
"symbol": "sprite",
"header": "twn_draw.h",
"params": [
{ "name": "path", "type": "char *" },
{ "name": "texture", "type": "char *" },
{ "name": "rect", "type": "Rect" },
{ "name": "texture_region", "type": "Rect *", "default": {} },
{ "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } },
@ -121,6 +121,71 @@
{ "name": "font", "type": "char *", "default": {} }
],
"return": "float"
},
"draw_nine_slice": {
"module": "draw",
"symbol": "nine_slice",
"header": "twn_draw.h",
"params": [
{ "name": "texture", "type": "char *" },
{ "name": "corners", "type": "Vec2" },
{ "name": "rect", "type": "Rect" },
{ "name": "border_thickness", "type": "float", "default": 0 },
{ "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } }
]
},
"draw_triangle": {
"module": "draw",
"symbol": "triangle",
"header": "twn_draw.h",
"params": [
{ "name": "texture", "type": "char *" },
{ "name": "v0", "type": "Vec3" },
{ "name": "v1", "type": "Vec3" },
{ "name": "v2", "type": "Vec3" },
{ "name": "uv0", "type": "Vec2" },
{ "name": "uv1", "type": "Vec2" },
{ "name": "uv2", "type": "Vec2" },
{ "name": "c0", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } },
{ "name": "c1", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } },
{ "name": "c2", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } }
]
},
"draw_billboard": {
"module": "draw",
"symbol": "billboard",
"header": "twn_draw.h",
"params": [
{ "name": "texture", "type": "char *" },
{ "name": "position", "type": "Vec3" },
{ "name": "size", "type": "Vec2" },
{ "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } },
{ "name": "cylindrical", "type": "bool", "default": false }
]
},
"draw_skybox": {
"module": "draw",
"symbol": "skybox",
"header": "twn_draw.h",
"params": [
{ "name": "textures", "type": "char *", "default": {} }
]
},
"draw_fog": {
"module": "draw",
"symbol": "fog",
"header": "twn_draw.h",
"params": [
{ "name": "start", "type": "float", "default": 0 },
{ "name": "end", "type": "float", "default": 1 },
{ "name": "density", "type": "float", "default": 0 },
{ "name": "color", "type": "Color", "default": { "r": 255, "g": 255, "b": 255, "a": 255 } }
]
}
},

View File

@ -15,8 +15,14 @@ void draw_triangle(const char *path,
Vec3 v2,
Vec2 uv0,
Vec2 uv1,
Vec2 uv2)
Vec2 uv2,
Color c0,
Color c1,
Color c2)
{
// TODO: support color
(void)c0; (void)c1; (void)c2;
// TODO: order drawing by atlas id as well, so that texture rebinding is not as common
const TextureKey texture_key = textures_get_key(&ctx.texture_cache, path);