This commit is contained in:
Carlos Sanchez 2024-09-21 00:38:46 -04:00
parent 29358c9258
commit 5b437adf8e
3 changed files with 28 additions and 27 deletions

View File

@ -3,7 +3,7 @@
Everything in here is a little sample program or otherwise which Everything in here is a little sample program or otherwise which
uses [haloo3d](https://github.com/randomouscrap98/haloo3d) and uses [haloo3d](https://github.com/randomouscrap98/haloo3d) and
[unigi](https://git.lumen.sh/Fierelier/unigi). It's all software [unigi](https://git.lumen.sh/Fierelier/unigi). It's all software
rendered, but you'll need to get sdl1 so it can render to screen. rendered, but you'll need to get sdl2 so it can render to screen.
The libraries required are set as submodules, so you can pull them The libraries required are set as submodules, so you can pull them
when cloning with: when cloning with:
@ -33,14 +33,13 @@ make FORCE=1 maze.exe
## Unigi ## Unigi
For the time being, unigi is designed such that it expects you to Unigi is a small library and is built manually using the 3dtoys makefile.
compile your entire program as a single unit. This means you must You can tinker around with Unigi if you like; it has its own make system,
include all your .c files into the main file, in the right order. but I'm not sure what is required. The parts that are required for 3dtoys
are handled with the 3dtoys makefile.
This may change in the future.
Unigi expects some kind of graphics backend to run. In this case, Unigi expects some kind of graphics backend to run. In this case,
our samples use SDL1, so you'll need to get that. our samples use SDL2, so you'll need to get that.
## Haloo3d ## Haloo3d

34
scene.c
View File

@ -1,12 +1,11 @@
#include "haloo3d/haloo3d.h" #include "haloo3d/haloo3d.h"
#include "haloo3d/haloo3dex_easy.h" // #include "haloo3d/haloo3dex_easy.h"
#include "haloo3d/haloo3dex_gen.h" #include "haloo3d/haloo3dex_gen.h"
#include "haloo3d/haloo3dex_img.h" #include "haloo3d/haloo3dex_img.h"
#include "haloo3d/haloo3dex_obj.h" #include "haloo3d/haloo3dex_obj.h"
#include "haloo3d/haloo3dex_print.h" #include "haloo3d/haloo3dex_print.h"
#include "unigi/unigi.headers/src/main.h" #include "unigi/main.h"
#include "unigi/unigi.platform.sdl1/src/main.c"
// #include "unigi/unigi.ext/src/main.c" // #include "unigi/unigi.ext/src/main.c"
#include "camera.h" #include "camera.h"
@ -16,7 +15,7 @@
#include <time.h> #include <time.h>
#define DOLIGHTING #define DOLIGHTING
#define FASTTRIS // #define FASTTRIS
// IDK you probably have to change this based on your display. // IDK you probably have to change this based on your display.
// Maybe there's a way to fix this? // Maybe there's a way to fix this?
@ -25,6 +24,7 @@
#define DITHERSTART 100 #define DITHERSTART 100
#define DITHEREND 101 #define DITHEREND 101
#define PCTSTART 100
#define WIDTH 640 #define WIDTH 640
#define HEIGHT 480 #define HEIGHT 480
@ -45,13 +45,13 @@
#define NUMINSTANCES (NUMOBJECTS - 1 + NUMFLOWERS) #define NUMINSTANCES (NUMOBJECTS - 1 + NUMFLOWERS)
#define MAXCAM 1200 #define MAXCAM 1200
#ifdef FASTTRIS // #ifdef FASTTRIS
#define WBUFCLEAR FARCLIP // #define WBUFCLEAR FARCLIP
#define TRIFUNC haloo3d_texturedtriangle_fast // #define TRIFUNC haloo3d_texturedtriangle_fast
#else // #else
#define WBUFCLEAR 0 // #define WBUFCLEAR 0
#define TRIFUNC haloo3d_texturedtriangle // #define TRIFUNC haloo3d_texturedtriangle
#endif // #endif
#define CALCTIME(thistime, start, end, sum) \ #define CALCTIME(thistime, start, end, sum) \
thistime = 1000.0 * (float)(end - start) / CLOCKS_PER_SEC; \ thistime = 1000.0 * (float)(end - start) / CLOCKS_PER_SEC; \
@ -166,6 +166,9 @@ int main(int argc, char **argv) {
// present in this // present in this
haloo3d_trirender rendersettings; haloo3d_trirender rendersettings;
haloo3d_trirender_init(&rendersettings); haloo3d_trirender_init(&rendersettings);
rendersettings.ditherfar = DITHEREND;
rendersettings.ditherclose = DITHERSTART;
rendersettings.pctminsize = PCTSTART;
eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts); eprintf("Scene has %d tris, %d verts\n", totalfaces, totalverts);
@ -198,7 +201,7 @@ int main(int argc, char **argv) {
camera.pitch = cams[cami].pitch + MPI_2; camera.pitch = cams[cami].pitch + MPI_2;
// REMEMBER TO CLEAR DEPTH BUFFER // REMEMBER TO CLEAR DEPTH BUFFER
haloo3d_fb_cleardepth(&fb, WBUFCLEAR); haloo3d_fb_cleardepth(&fb);
// Screen matrix calc. We multiply the modelview matrix with this later // Screen matrix calc. We multiply the modelview matrix with this later
haloo3d_camera_calclook(&camera, matrixcam); haloo3d_camera_calclook(&camera, matrixcam);
@ -223,8 +226,9 @@ int main(int argc, char **argv) {
objects[i].model->vtexture, face); objects[i].model->vtexture, face);
int tris = haloo3d_facef_clip(face, outfaces); int tris = haloo3d_facef_clip(face, outfaces);
if (tris > 0) { if (tris > 0) {
haloo3d_easy_calcdither4x4(&rendersettings, face, DITHERSTART, // haloo3d_getdither4x4(float dither, uint8_t *buf)
DITHEREND); // haloo3d_easy_calcdither4x4(&rendersettings, face, DITHERSTART,
// DITHEREND);
rendersettings.intensity = 1.0; rendersettings.intensity = 1.0;
if (objects[i].lighting) { if (objects[i].lighting) {
haloo3d_obj_facef(objects[i].model, objects[i].model->faces[fi], haloo3d_obj_facef(objects[i].model, objects[i].model->faces[fi],
@ -242,7 +246,7 @@ int main(int argc, char **argv) {
// We still have to convert the points into the view // We still have to convert the points into the view
haloo3d_facef_viewport_into(outfaces[ti], WIDTH, HEIGHT); haloo3d_facef_viewport_into(outfaces[ti], WIDTH, HEIGHT);
// eprintf("RENDER TRI\n"); // eprintf("RENDER TRI\n");
TRIFUNC(&fb, &rendersettings, outfaces[ti]); haloo3d_triangle(&fb, &rendersettings, outfaces[ti]);
} }
} }
} }

View File

@ -4,9 +4,7 @@
#include "haloo3d/haloo3dex_obj.h" #include "haloo3d/haloo3dex_obj.h"
#include "haloo3d/haloo3dex_print.h" #include "haloo3d/haloo3dex_print.h"
#include "unigi/unigi.headers/src/main.h" #include "unigi/main.h"
#include "unigi/unigi.platform.sdl1/src/main.c"
// #include "unigi/unigi.ext/src/main.c"
#include "camera.h" #include "camera.h"
#include "keys.h" #include "keys.h"
@ -227,7 +225,7 @@ int main(int argc, char **argv) {
// camera.pitch = cams[cami].pitch + MPI_2; // camera.pitch = cams[cami].pitch + MPI_2;
// REMEMBER TO CLEAR DEPTH BUFFER // REMEMBER TO CLEAR DEPTH BUFFER
haloo3d_fb_cleardepth(&fb, WBUFCLEAR); haloo3d_fb_cleardepth(&fb);
// Screen matrix calc. We multiply the modelview matrix with this later // Screen matrix calc. We multiply the modelview matrix with this later
haloo3d_camera_calclook(&camera, matrixcam); haloo3d_camera_calclook(&camera, matrixcam);
@ -264,7 +262,7 @@ int main(int argc, char **argv) {
} }
// We still have to convert the points into the view // We still have to convert the points into the view
haloo3d_facef_viewport_into(outfaces[ti], WIDTH, HEIGHT); haloo3d_facef_viewport_into(outfaces[ti], WIDTH, HEIGHT);
TRIFUNC(&fb, &rendersettings, outfaces[ti]); haloo3d_triangle(&fb, &rendersettings, outfaces[ti]);
} }
} }
} }