Add scripting for rendering colors

This commit is contained in:
John Alanbrook 2024-04-17 08:57:45 -05:00
parent 3b3cb14421
commit 5bb7ea32bf
5 changed files with 22 additions and 8 deletions

View file

@ -8,6 +8,7 @@ game.loadurs();
console.info(`window size: ${window.size}, render size: ${window.rendersize}`); console.info(`window size: ${window.size}, render size: ${window.rendersize}`);
player[0].control(debug); player[0].control(debug);
render.clear_color([35,60,92,255].map(x => x/255));
var show_frame = true; var show_frame = true;
@ -486,7 +487,7 @@ var editor = {
render.text("lock", obj,screenpos()); render.text("lock", obj,screenpos());
}); });
render.grid(1, editor.grid_size, Color.Editor.grid.alpha(0.3)); render.grid(1, editor.grid_size, editor.grid_color);
var startgrid = game.camera.view2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); }); var startgrid = game.camera.view2world([-20,0]).map(function(x) { return Math.snap(x, editor.grid_size); });
var endgrid = game.camera.view2world([window.width, window.height]); var endgrid = game.camera.view2world([window.width, window.height]);

View file

@ -152,7 +152,6 @@ console.transcript = "";
console.say = function(msg) { console.say = function(msg) {
msg += "\n"; msg += "\n";
console.print(msg); console.print(msg);
return;
console.transcript += msg; console.transcript += msg;
}; };
console.log = console.say; console.log = console.say;

View file

@ -611,6 +611,11 @@ JSC_CCALL(render_end_pass,
JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1))) JSC_SCALL(render_text_size, ret = bb2js(text_bb(str, js2number(argv[1]), js2number(argv[2]), 1)))
JSC_CCALL(render_set_camera, useproj = projection) JSC_CCALL(render_set_camera, useproj = projection)
JSC_CCALL(render_set_window, useproj = hudproj) JSC_CCALL(render_set_window, useproj = hudproj)
JSC_CCALL(render_clear_color,
sg_color c;
rgba2floats(&c, js2color(argv[0]));
pass_action.colors[0].clear_value = c;
)
static const JSCFunctionListEntry js_render_funcs[] = { static const JSCFunctionListEntry js_render_funcs[] = {
MIST_FUNC_DEF(render, grid, 3), MIST_FUNC_DEF(render, grid, 3),
@ -626,6 +631,7 @@ static const JSCFunctionListEntry js_render_funcs[] = {
MIST_FUNC_DEF(render, text_size, 3), MIST_FUNC_DEF(render, text_size, 3),
MIST_FUNC_DEF(render, set_camera, 0), MIST_FUNC_DEF(render, set_camera, 0),
MIST_FUNC_DEF(render, set_window, 0), MIST_FUNC_DEF(render, set_window, 0),
MIST_FUNC_DEF(render, clear_color, 1),
}; };
JSC_CCALL(gui_flush, text_flush(&useproj)); JSC_CCALL(gui_flush, text_flush(&useproj));
@ -898,8 +904,19 @@ static const JSCFunctionListEntry js_io_funcs[] = {
JSC_CCALL(debug_draw_gameobject, gameobject_draw_debug(js2gameobject(argv[0]));) JSC_CCALL(debug_draw_gameobject, gameobject_draw_debug(js2gameobject(argv[0]));)
JSC_GETSET_GLOBAL(disabled_color, color)
JSC_GETSET_GLOBAL(sleep_color, color)
JSC_GETSET_GLOBAL(dynamic_color, color)
JSC_GETSET_GLOBAL(kinematic_color, color)
JSC_GETSET_GLOBAL(static_color, color)
static const JSCFunctionListEntry js_debug_funcs[] = { static const JSCFunctionListEntry js_debug_funcs[] = {
MIST_FUNC_DEF(debug, draw_gameobject, 1) MIST_FUNC_DEF(debug, draw_gameobject, 1),
CGETSET_ADD(global, disabled_color),
CGETSET_ADD(global, sleep_color),
CGETSET_ADD(global, dynamic_color),
CGETSET_ADD(global, kinematic_color),
CGETSET_ADD(global, static_color),
}; };
JSC_CCALL(physics_sgscale, JSC_CCALL(physics_sgscale,

View file

@ -121,9 +121,6 @@ void capture_screen(int x, int y, int w, int h, const char *path)
#include "HandmadeMath.h" #include "HandmadeMath.h"
//struct rgba editorClearColor = {35,60,92,255};
struct rgba editorClearColor = {0,0,0,255};
sg_pass_action pass_action = {0}; sg_pass_action pass_action = {0};
static struct { static struct {
@ -236,9 +233,8 @@ void render_init() {
sprite_initialize(); sprite_initialize();
model_init(); model_init();
sg_color c;
rgba2floats((float*)&c, editorClearColor);
sg_color c = (sg_color){0,0,0,1};
pass_action = (sg_pass_action){ pass_action = (sg_pass_action){
.colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c}, .colors[0] = {.load_action = SG_LOADACTION_CLEAR, .clear_value = c},
}; };

View file

@ -30,6 +30,7 @@ extern HMM_Vec3 dirl_pos;
extern HMM_Mat4 projection; extern HMM_Mat4 projection;
extern HMM_Mat4 hudproj; extern HMM_Mat4 hudproj;
extern HMM_Mat4 useproj; extern HMM_Mat4 useproj;
extern sg_pass_action pass_action;
struct draw_p { struct draw_p {
float x; float x;