working on loading mesh data

This commit is contained in:
Samuel Walker 2025-03-29 16:21:30 -06:00
parent d0cac74dd0
commit 6b120a617c
4 changed files with 80 additions and 5 deletions

46
ISO/Assets/cube.obj Normal file
View File

@ -0,0 +1,46 @@
# Blender 4.4.0
# www.blender.org
mtllib Untitled.mtl
o Cube
v 1.000000 1.000000 -1.000000
v 1.000000 -1.000000 -1.000000
v 1.000000 1.000000 1.000000
v 1.000000 -1.000000 1.000000
v -1.000000 1.000000 -1.000000
v -1.000000 -1.000000 -1.000000
v -1.000000 1.000000 1.000000
v -1.000000 -1.000000 1.000000
vn -0.0000 1.0000 -0.0000
vn -0.0000 -0.0000 1.0000
vn -1.0000 -0.0000 -0.0000
vn -0.0000 -1.0000 -0.0000
vn 1.0000 -0.0000 -0.0000
vn -0.0000 -0.0000 -1.0000
vt 0.875000 0.500000
vt 0.625000 0.750000
vt 0.625000 0.500000
vt 0.375000 1.000000
vt 0.375000 0.750000
vt 0.625000 0.000000
vt 0.375000 0.250000
vt 0.375000 0.000000
vt 0.375000 0.500000
vt 0.125000 0.750000
vt 0.125000 0.500000
vt 0.625000 0.250000
vt 0.875000 0.750000
vt 0.625000 1.000000
s 0
usemtl Material
f 5/1/1 3/2/1 1/3/1
f 3/2/2 8/4/2 4/5/2
f 7/6/3 6/7/3 8/8/3
f 2/9/4 8/10/4 6/11/4
f 1/3/5 4/5/5 2/9/5
f 5/12/6 2/9/6 6/7/6
f 5/1/1 7/13/1 3/2/1
f 3/2/2 7/14/2 8/4/2
f 7/6/3 5/12/3 6/7/3
f 2/9/4 4/5/4 8/10/4
f 1/3/5 3/2/5 4/5/5
f 5/12/6 1/3/6 2/9/6

6
include/mesh.h Normal file
View File

@ -0,0 +1,6 @@
#include "math3d.h"
struct mesh {
VECTOR *verticies;
};
int load_file(const char *fname, char *b, int b_len);

View File

@ -11,6 +11,7 @@
#include <gs_gp.h>
#include <stdlib.h>
#include "gs.h"
#include "mesh.h"
#define myftoi4(x) ((x)<<4)
@ -53,14 +54,18 @@ uint64_t red = 0xf0;
uint64_t blue = 0x0f;
uint64_t green = 0xf0;
qword_t *draw(qword_t *q) {
q->dw[0] = 0xD000000000000001;
q->dw[1] = 0x0005151515151510;
q->dw[0] = 0x1000000000000001;
q->dw[1] = 0x0000000000000000;
q++;
q->dw[0] = GS_PRIM_TRIANGLE;
q->dw[1] = 0;
q++;
q->dw[0] = 0x6000000000000002;
q->dw[1] = 0x0000000000515151;
q++;
int cx = myftoi4(2048 - (VID_W/2));
int cy = myftoi4(2048 - (VID_H/2));
@ -98,6 +103,8 @@ int main() {
state.vmode = GRAPH_MODE_NTSC;
gs_init(&state, GS_PSM_32, GS_PSMZ_24);
DEBUG_MSG("GS Initialized...\n");
// clear screen
// build buffer with triangle data
@ -105,10 +112,11 @@ int main() {
qword_t *buf = malloc(vid_buf_size);
graph_wait_vsync();
while(1) {
dma_wait_fast();
green++;
if(green > 0xFF) {
green = 0;
red++;
if(red > 0xFF) {
red = 0;
}
qword_t *q = buf;
q = draw_disable_tests(q, 0, &state.zb);

15
src/mesh.c Normal file
View File

@ -0,0 +1,15 @@
#include <mesh.h>
#include <stdio.h>
int load_file(const char *fname, char *b, int b_len) {
FILE *f = fopen(fname, "rb");
fseek(f, 0, SEEK_END);
int len = ftell(f);
fseek(f, 0, SEEK_SET);
if (len >= b_len) {
return 0;
}
size_t byte_read = fread(b, 1, len, f);
fclose(f);
return byte_read;
}