From 93ffbfd66cf1b4161a9616eeb971ea79ad7a709a Mon Sep 17 00:00:00 2001 From: Edgaru089 Date: Sat, 30 Mar 2024 18:55:43 +0800 Subject: [PATCH] Bundle rendering fixes & first bundle --- app_render.cpp | 7 +++++++ render_bundle_draw.cpp | 13 +++++++++---- render_bundle_file.c | 33 +++++++++++++++++++++++++++++---- 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/app_render.cpp b/app_render.cpp index d7f3357..a8da3b3 100644 --- a/app_render.cpp +++ b/app_render.cpp @@ -4,6 +4,7 @@ #include "particle.h" #include "physics.h" #include "easyx.h" +#include "render_bundle.h" #include "util/tree.h" #include "types.h" #include "render_util.h" @@ -48,7 +49,13 @@ void app_Render(App *app) { render_SetModes(mode_rotate, since); render_FillCircleW(app, vec2(200, 100), 20); + + render_DrawBundleW(app, render_FindBundle("info_plate"), vec2(600, 550)); + + // Draw particles + setfillcolor(RGB(255, 255, 255)); + setbkcolor(RGB(0, 0, 0)); particle_Render(app->particle); } } diff --git a/render_bundle_draw.cpp b/render_bundle_draw.cpp index a03d64c..3d29d0e 100644 --- a/render_bundle_draw.cpp +++ b/render_bundle_draw.cpp @@ -2,8 +2,8 @@ #include "camera.h" #include "render_bundle.h" #include "app.h" +#include "render_util.h" #include "util/vector.h" -#include "util/assert.h" #include #include #include @@ -41,20 +41,25 @@ extern "C" void render_DrawPrimitiveW(App *app, render_Primitive *p, Vec2 offset setlinecolor(p->fg); setfillcolor(p->fg); setbkcolor(p->bg); + render_SetModes(p->mode, time_Now()); // Draw the converted primitive switch (p->type) { case render_Lines: if (vector_Size(buff) % 2 != 0) - fprintf(stderr, "[WARN][render_DrawPrimitiveW] render_Lines drawed odd numbers of points"); - for (int i = 0; i < vector_Size(buff); i += 2) { + WARN("render_Lines drawed odd numbers of points", 0); + for (int i = 0; i < vector_Size(buff) - 1; i += 2) { POINT p0 = *(POINT *)vector_At(buff, i); POINT p1 = *(POINT *)vector_At(buff, i + 1); line(p0.x, p0.y, p1.x, p1.y); } break; case render_LineStrip: - polyline((POINT *)vector_Data(buff), vector_Size(buff)); + for (int i = 0; i < vector_Size(buff) - 1; i++) { + POINT p0 = *(POINT *)vector_At(buff, i); + POINT p1 = *(POINT *)vector_At(buff, i + 1); + line(p0.x, p0.y, p1.x, p1.y); + } break; case render_Polygon: fillpolygon((POINT *)vector_Data(buff), vector_Size(buff)); diff --git a/render_bundle_file.c b/render_bundle_file.c index 0aa2172..8a9734f 100644 --- a/render_bundle_file.c +++ b/render_bundle_file.c @@ -1,11 +1,15 @@ #include "render_bundle.h" +#include "render_util.h" #include "util/vector.h" #include #include #include +#define RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16)) + + vector_Vector *render_Bundles; static render_Bundle *_tmpb; static render_Primitive *_tmpp; @@ -49,14 +53,15 @@ static void _render_BundleCommand(char *cmd) { _tmpp->points = vector_Create(sizeof(Vec2)); _tmpp->fg = 0xffffff; _tmpp->bg = 0; + _tmpp->mode = render_ModeDefault; // parse the type char *type = strtok(NULL, " "); - if (strcmp(type, "LINES")) + if (strcmp(type, "LINES") == 0) _tmpp->type = render_Lines; - else if (strcmp(type, "LINESTRIP")) + else if (strcmp(type, "LINESTRIP") == 0) _tmpp->type = render_LineStrip; - else if (strcmp(type, "POLY")) + else if (strcmp(type, "POLY") == 0) _tmpp->type = render_Polygon; @@ -74,10 +79,30 @@ static void _render_BundleCommand(char *cmd) { } else if (CMD("P")) { // Add a Vec2 if (_tmpp) { - Vec2 v = vec2(strtod(strtok(NULL, " "), NULL), strtod(strtok(NULL, " "), NULL)); + double x = strtod(strtok(NULL, " "), NULL); + double y = strtod(strtok(NULL, " "), NULL); + Vec2 v = vec2(x, y); vector_Push(_tmpp->points, &v); } else WARN("P without PRIM first", 0); + } else if (CMD("FG")) { + // Set Foreground color + if (_tmpp) { + int r = atoi(strtok(NULL, " ")); + int g = atoi(strtok(NULL, " ")); + int b = atoi(strtok(NULL, " ")); + _tmpp->fg = RGB(r, g, b); + } else + WARN("FG without PRIM first", 0); + } else if (CMD("BG")) { + // Set Background color + if (_tmpp) { + int r = atoi(strtok(NULL, " ")); + int g = atoi(strtok(NULL, " ")); + int b = atoi(strtok(NULL, " ")); + _tmpp->bg = RGB(r, g, b); + } else + WARN("BG without PRIM first", 0); } else { WARN("unknown command %s", cmd); }