summaryrefslogtreecommitdiff
path: root/3de.c
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2024-07-13 23:46:14 +1000
committerquou <quou@disroot.org>2024-07-13 23:46:31 +1000
commitd7160d62b5d78e9191b4d61d7f491deb728cb478 (patch)
tree0bbb087df0fa32b2e47f00d8fc602f4921eec5a7 /3de.c
parenta43eb70ebe7844db0a4ffece47c22ae12384781b (diff)
Model loading and basic lighting.
Diffstat (limited to '3de.c')
-rw-r--r--3de.c43
1 files changed, 14 insertions, 29 deletions
diff --git a/3de.c b/3de.c
index 9a5295f..a1bd9bb 100644
--- a/3de.c
+++ b/3de.c
@@ -1,10 +1,10 @@
+#include "asset.h"
#include "config.h"
#include "maths.h"
#include "memory.h"
#include "plat.h"
#include "render.h"
#include "tile.h"
-#include "torus.h"
#include <stdio.h>
@@ -17,39 +17,18 @@ void draw_spinny(Renderer* r, Colour c) {
a += 20;
}
-void draw_torus(Renderer* r) {
+void draw_monkey(Renderer* r) {
static int a = 0;
+ const Mesh* m = get_mesh(asset_id_monkey);
Bitmap tex = { (Colour*)tile_pixels, 16, 16 };
- const int pc = sizeof torus_points / sizeof *torus_points;
- int asp = (r->clip.w << fbits) / r->clip.h;
- int p[4 * 3] = { 0, 0, 5 << fbits, f1, 0, 0, 0, f1, 0, 0, 0, f1 }, * wp;
- int v[8 * 3];
- int i, j;
+ int p[] = { 0, 0, 5 << fbits, f1 };
mtx_push_trans(p);
mtx_push_rot_x(a);
mtx_push_rot_y(a);
mtx_push_rot_z(a);
- for (i = 0; i < pc; i += 3 * 5) {
- for (j = 0; j < 3; j++) {
- wp = &p[j * 4];
- vec_cpy(wp, &torus_points[i + j * 5], 3);
- mtx_apply(mtx_peek(), wp);
- persp(wp, asp);
- ndc2clip((int*)&r->clip, wp);
- }
- for (j = 0; j < 3; j++) {
- int j8 = j * 8;
- vec_cpy(&v[j8], &p[j * 4], 3);
- v[j8 + 3] = torus_points[i + j * 5];
- v[j8 + 4] = torus_points[i + j * 5 + 1];
- v[j8 + 5] = f1;
- v[j8 + 6] = f1;
- v[j8 + 7] = f1;
- }
- ren_tri(r, &v[0], &v[8], &v[16], &tex);
- }
+ ren_mesh(r, m, &tex);
mtx_popn(4);
- a += 3;
+ a++;
}
void draw_tri(Renderer* r, int x, int y) {
@@ -69,6 +48,7 @@ int entrypoint(int argc, const char** argv, Arena* a) {
FPS f;
char buf[32];
int* depth = 0;
+ Arena preload;
Colour blue = make_aliceblue();
(void)argc;
(void)argv;
@@ -78,6 +58,11 @@ int entrypoint(int argc, const char** argv, Arena* a) {
arena_alloc(a, app_memory_size),
app_memory_size
);
+ init_arena(
+ &preload,
+ arena_alloc(a, asset_preload_memory_size),
+ asset_preload_memory_size
+ );
app = new_app(&h, 640, 480, "3D Engine");
if (!app) return app->err;
init_fps(&f, 20);
@@ -86,6 +71,7 @@ int entrypoint(int argc, const char** argv, Arena* a) {
print_err("Out of memory.\n");
return error_out_of_memory;
}
+ preload_assets(&preload);
while (app->o) {
fps_begin(&f);
while (f.now >= f.next) {
@@ -99,8 +85,7 @@ int entrypoint(int argc, const char** argv, Arena* a) {
ren_text(&r, blue, 3, 13, buf);
sprintf(buf, "MOUSE: %d, %d", app->mx, app->my);
ren_text(&r, blue, 3, 23, buf);
- draw_torus(&r);
- draw_tri(&r, app->mx, app->my);
+ draw_monkey(&r);
ren_end(&r);
app_end(app);
fps_update(&f);