Bundle rendering fixes & first bundle
This commit is contained in:
		| @@ -4,6 +4,7 @@ | |||||||
| #include "particle.h" | #include "particle.h" | ||||||
| #include "physics.h" | #include "physics.h" | ||||||
| #include "easyx.h" | #include "easyx.h" | ||||||
|  | #include "render_bundle.h" | ||||||
| #include "util/tree.h" | #include "util/tree.h" | ||||||
| #include "types.h" | #include "types.h" | ||||||
| #include "render_util.h" | #include "render_util.h" | ||||||
| @@ -48,7 +49,13 @@ void app_Render(App *app) { | |||||||
| 	render_SetModes(mode_rotate, since); | 	render_SetModes(mode_rotate, since); | ||||||
| 	render_FillCircleW(app, vec2(200, 100), 20); | 	render_FillCircleW(app, vec2(200, 100), 20); | ||||||
|  |  | ||||||
|  |  | ||||||
|  | 	render_DrawBundleW(app, render_FindBundle("info_plate"), vec2(600, 550)); | ||||||
|  |  | ||||||
|  |  | ||||||
| 	// Draw particles | 	// Draw particles | ||||||
|  | 	setfillcolor(RGB(255, 255, 255)); | ||||||
|  | 	setbkcolor(RGB(0, 0, 0)); | ||||||
| 	particle_Render(app->particle); | 	particle_Render(app->particle); | ||||||
| } | } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -2,8 +2,8 @@ | |||||||
| #include "camera.h" | #include "camera.h" | ||||||
| #include "render_bundle.h" | #include "render_bundle.h" | ||||||
| #include "app.h" | #include "app.h" | ||||||
|  | #include "render_util.h" | ||||||
| #include "util/vector.h" | #include "util/vector.h" | ||||||
| #include "util/assert.h" |  | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <math.h> | #include <math.h> | ||||||
| #include <easyx.h> | #include <easyx.h> | ||||||
| @@ -41,20 +41,25 @@ extern "C" void render_DrawPrimitiveW(App *app, render_Primitive *p, Vec2 offset | |||||||
| 	setlinecolor(p->fg); | 	setlinecolor(p->fg); | ||||||
| 	setfillcolor(p->fg); | 	setfillcolor(p->fg); | ||||||
| 	setbkcolor(p->bg); | 	setbkcolor(p->bg); | ||||||
|  | 	render_SetModes(p->mode, time_Now()); | ||||||
|  |  | ||||||
| 	// Draw the converted primitive | 	// Draw the converted primitive | ||||||
| 	switch (p->type) { | 	switch (p->type) { | ||||||
| 		case render_Lines: | 		case render_Lines: | ||||||
| 			if (vector_Size(buff) % 2 != 0) | 			if (vector_Size(buff) % 2 != 0) | ||||||
| 				fprintf(stderr, "[WARN][render_DrawPrimitiveW] render_Lines drawed odd numbers of points"); | 				WARN("render_Lines drawed odd numbers of points", 0); | ||||||
| 			for (int i = 0; i < vector_Size(buff); i += 2) { | 			for (int i = 0; i < vector_Size(buff) - 1; i += 2) { | ||||||
| 				POINT p0 = *(POINT *)vector_At(buff, i); | 				POINT p0 = *(POINT *)vector_At(buff, i); | ||||||
| 				POINT p1 = *(POINT *)vector_At(buff, i + 1); | 				POINT p1 = *(POINT *)vector_At(buff, i + 1); | ||||||
| 				line(p0.x, p0.y, p1.x, p1.y); | 				line(p0.x, p0.y, p1.x, p1.y); | ||||||
| 			} | 			} | ||||||
| 			break; | 			break; | ||||||
| 		case render_LineStrip: | 		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; | 			break; | ||||||
| 		case render_Polygon: | 		case render_Polygon: | ||||||
| 			fillpolygon((POINT *)vector_Data(buff), vector_Size(buff)); | 			fillpolygon((POINT *)vector_Data(buff), vector_Size(buff)); | ||||||
|   | |||||||
| @@ -1,11 +1,15 @@ | |||||||
|  |  | ||||||
| #include "render_bundle.h" | #include "render_bundle.h" | ||||||
|  | #include "render_util.h" | ||||||
| #include "util/vector.h" | #include "util/vector.h" | ||||||
| #include <stdio.h> | #include <stdio.h> | ||||||
| #include <string.h> | #include <string.h> | ||||||
| #include <ctype.h> | #include <ctype.h> | ||||||
|  |  | ||||||
|  |  | ||||||
|  | #define RGB(r, g, b) ((r) | ((g) << 8) | ((b) << 16)) | ||||||
|  |  | ||||||
|  |  | ||||||
| vector_Vector           *render_Bundles; | vector_Vector           *render_Bundles; | ||||||
| static render_Bundle    *_tmpb; | static render_Bundle    *_tmpb; | ||||||
| static render_Primitive *_tmpp; | static render_Primitive *_tmpp; | ||||||
| @@ -49,14 +53,15 @@ static void _render_BundleCommand(char *cmd) { | |||||||
| 		_tmpp->points = vector_Create(sizeof(Vec2)); | 		_tmpp->points = vector_Create(sizeof(Vec2)); | ||||||
| 		_tmpp->fg     = 0xffffff; | 		_tmpp->fg     = 0xffffff; | ||||||
| 		_tmpp->bg     = 0; | 		_tmpp->bg     = 0; | ||||||
|  | 		_tmpp->mode   = render_ModeDefault; | ||||||
|  |  | ||||||
| 		// parse the type | 		// parse the type | ||||||
| 		char *type = strtok(NULL, " "); | 		char *type = strtok(NULL, " "); | ||||||
| 		if (strcmp(type, "LINES")) | 		if (strcmp(type, "LINES") == 0) | ||||||
| 			_tmpp->type = render_Lines; | 			_tmpp->type = render_Lines; | ||||||
| 		else if (strcmp(type, "LINESTRIP")) | 		else if (strcmp(type, "LINESTRIP") == 0) | ||||||
| 			_tmpp->type = render_LineStrip; | 			_tmpp->type = render_LineStrip; | ||||||
| 		else if (strcmp(type, "POLY")) | 		else if (strcmp(type, "POLY") == 0) | ||||||
| 			_tmpp->type = render_Polygon; | 			_tmpp->type = render_Polygon; | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -74,10 +79,30 @@ static void _render_BundleCommand(char *cmd) { | |||||||
| 	} else if (CMD("P")) { | 	} else if (CMD("P")) { | ||||||
| 		// Add a Vec2 | 		// Add a Vec2 | ||||||
| 		if (_tmpp) { | 		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); | 			vector_Push(_tmpp->points, &v); | ||||||
| 		} else | 		} else | ||||||
| 			WARN("P without PRIM first", 0); | 			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 { | 	} else { | ||||||
| 		WARN("unknown command %s", cmd); | 		WARN("unknown command %s", cmd); | ||||||
| 	} | 	} | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user