Fix grid draw, circle draw, most editor drawing

This commit is contained in:
2023-08-23 22:18:34 +00:00
parent 09765f5336
commit f94c62c5c0
10 changed files with 53 additions and 57 deletions

View File

@@ -85,15 +85,16 @@ struct circle_vertex {
static struct circle_vertex circle_b[v_amt];
/* Writes debug data to buffers, and draws */
void debug_flush(HMM_Mat4 *view)
{
if (poly_c != 0) {
sg_apply_pipeline(poly_pipe);
sg_apply_bindings(&poly_bind);
sg_apply_uniforms(SG_SHADERSTAGE_VS,0,SG_RANGE_REF(*view));
sg_append_buffer(poly_bind.vertex_buffers[0], &(sg_range){
int b = sg_append_buffer(poly_bind.vertex_buffers[0], &(sg_range){
.ptr = poly_b, .size = sizeof(struct poly_vertex)*poly_v});
sg_append_buffer(poly_bind.index_buffer, &(sg_range){
int bi = sg_append_buffer(poly_bind.index_buffer, &(sg_range){
.ptr = poly_bi, .size = sizeof(uint32_t)*poly_c});
sg_draw(poly_sc,poly_c,1);
}
@@ -106,6 +107,7 @@ void debug_flush(HMM_Mat4 *view)
.ptr = point_b,
.size = sizeof(struct point_vertex)*point_c});
sg_draw(point_sc,point_c,1);
YughWarn("DREW %d POINTS", point_c);
}
if (line_c != 0) {
@@ -163,6 +165,7 @@ void debug_newframe()
point_c = 0;
circle_sc = circle_count = line_sv = line_v = line_sc = line_c = poly_sc = poly_c = 0;
poly_sv = poly_v = 0;
}
static sg_shader_uniform_block_desc projection_ubo = {
@@ -569,16 +572,18 @@ void draw_arrow(struct cpVect start, struct cpVect end, struct rgba color, int c
void draw_grid(int width, int span, struct rgba color)
{
cpVect offset = cam_pos();
offset = cpvmult(offset, 1/cam_zoom());
offset.x -= mainwin->width/2;
offset.y -= mainwin->height/2;
cpVect offset = cam_pos();
offset = cpvmult(offset, 1/cam_zoom());
offset.x -= mainwin->width/2;
offset.y -= mainwin->height/2;
// offset.x += span/2;
offset.y += span/2;
sg_apply_pipeline(grid_pipe);
sg_apply_bindings(&grid_bind);
float col[4] = { color.r/255.0 ,color.g/255.0 ,color.b/255.0 ,color.a/255.0 };
float fubo[6];
fubo[0] = 1;
fubo[1] = span;
@@ -596,7 +601,7 @@ void draw_cppoint(struct cpVect point, float r, struct rgba color)
.color = color,
.radius = r
};
memcpy(point_b+point_c, &p, sizeof(struct point_vertex));
point_c++;
}
@@ -604,7 +609,7 @@ void draw_cppoint(struct cpVect point, float r, struct rgba color)
void draw_points(struct cpVect *points, int n, float size, struct rgba color)
{
for (int i = 0; i < n; i++)
draw_cppoint(points[i], size, color);
draw_cppoint(points[i], size, color);
}
void draw_poly(cpVect *points, int n, struct rgba color)
@@ -613,7 +618,7 @@ void draw_poly(cpVect *points, int n, struct rgba color)
int tric = n - 2;
if (tric < 1) return;
uint32_t tridxs[tric*3];
for (int i = 2, ti = 0; i < n; i++, ti+=3) {
@@ -625,11 +630,6 @@ void draw_poly(cpVect *points, int n, struct rgba color)
for (int i = 0; i < tric*3; i++)
tridxs[i] += poly_v+poly_sv;
sg_range trip = {
.ptr = tridxs,
.size = sizeof(uint32_t)*3*tric
};
struct poly_vertex polyverts[n];
for (int i = 0; i < n; i++) {
@@ -639,11 +639,6 @@ void draw_poly(cpVect *points, int n, struct rgba color)
polyverts[i].color = color;
}
sg_range ppp = {
.ptr = polyverts,
.size = sizeof(struct poly_vertex)*n
};
memcpy(poly_b+poly_v, polyverts, sizeof(struct poly_vertex)*n);
memcpy(poly_bi+poly_c, tridxs, sizeof(uint32_t)*3*tric);

View File

@@ -22,6 +22,7 @@ void draw_grid(int width, int span, struct rgba color);
void debug_flush(HMM_Mat4 *view);
void debug_newframe();
void debug_nextpass();
cpVect inflatepoint(cpVect a, cpVect b, cpVect c, float d);
void inflatepoints(cpVect *r, cpVect *p, float d, int n);

View File

@@ -266,6 +266,7 @@ void render_winsize()
static cpBody *camera = NULL;
void set_cam_body(cpBody *body) {
YughWarn("Camera body set to %p", body);
camera = body;
}
@@ -317,7 +318,6 @@ void openglRender(struct window *window) {
draw_model(duck,model, lsm);
*/
// sg_begin_default_pass(&pass_action, window->width, window->height);
sg_begin_pass(crt_post.pass, &pass_action);
//////////// 2D projection
@@ -338,24 +338,19 @@ void openglRender(struct window *window) {
//// DEBUG
if (debugDrawPhysics) {
gameobject_draw_debugs();
call_debugs();
call_debugs();
}
debug_flush(&projection);
// text_flush(&projection);
text_flush(&projection);
////// TEXT && GUI
debug_nextpass();
nuke_start();
call_gui();
nuke_start();
call_gui();
debug_flush(&hudproj);
text_flush(&hudproj);
// nuke_start();
call_nk_gui();
nuke_end();

View File

@@ -246,4 +246,5 @@ void call_debugs() { call_callee(&debug_callee); }
static struct callee draw_callee;
void register_draw(struct callee c) { draw_callee = c; }
void call_draw() { call_callee(&draw_callee); }

View File

@@ -232,10 +232,12 @@ int main(int argc, char **args) {
lastTick = glfwGetTime();
//double wait = fmax(0, renderMS - elapsed);
nuke_input_begin();
if (sim_playing())
input_poll(fmax(0, renderMS-elapsed));
else
input_poll(1000);
window_all_handle_events();
nuke_input_end();
framems[framei++] = elapsed;
@@ -259,10 +261,10 @@ int main(int argc, char **args) {
renderlag += elapsed;
if (renderlag >= renderMS) {
renderlag -= renderMS;
// if (renderlag >= renderMS) {
// renderlag -= renderMS;
window_renderall();
}
// }
gameobjects_cleanup();
}