diff --git a/include/defines.h b/include/defines.h index e30e2ec..6e3de9b 100644 --- a/include/defines.h +++ b/include/defines.h @@ -5,6 +5,7 @@ #define CENTERX SCREENXRES/2 #define CENTERY SCREENYRES/2 #define FOV CENTERX +#define FOG_COLOR {128, 128, 128} // Default to neutral grey #define CLEAR_COLOR_R 0 #define CLEAR_COLOR_G 0 #define CLEAR_COLOR_B 0 diff --git a/include/psx.h b/include/psx.h index 4a58c05..3ff301b 100644 --- a/include/psx.h +++ b/include/psx.h @@ -11,7 +11,7 @@ // PSX setup void setLightEnv(DRAWENV draw[2], CVECTOR * BGc, VECTOR * BKc, MATRIX * cmat); -void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BG, VECTOR * BK ); +void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BG, VECTOR * BK, VECTOR * FC ); void ScrRst(void); void display(DISPENV * disp, DRAWENV * draw, u_long * otdisc, char * primbuff, char ** nextprim, char * db); diff --git a/src/graphics.c b/src/graphics.c index e61f78a..57e956f 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -26,7 +26,7 @@ void transformMesh(CAMERA * camera, MESH * mesh){ void drawPoly(MESH * mesh, long * Flag, int atime, int * camMode, char ** nextpri, u_long * ot, char * db, DRAWENV * draw) { long nclip, t = 0; // mesh is POLY_GT3 ( triangle ) - for (int i = 0; i < (mesh->totalVerts);) { + for (int i = 0; i < (mesh->totalVerts) && (mesh->totalVerts - i) > 2;) { if (mesh->index[t].code == 4) { t = drawTri(mesh, Flag, atime, camMode, nextpri, ot, db, draw, t, i); i += 3; diff --git a/src/main.c b/src/main.c index 55e3100..b782aaa 100644 --- a/src/main.c +++ b/src/main.c @@ -54,8 +54,9 @@ int primcnt=0; // Primitive counter char * nextpri = primbuff[0]; // Primitive counter char db = 0; // Current buffer counter // Lighting -CVECTOR BGc = {128, 128, 128, 0}; // Default Far color - This can be set in each level. +CVECTOR BGc = {128, 128, 128, 0}; // Default Far color - This can be set in each level. VECTOR BKc = {128, 128, 128, 0}; // Back color +VECTOR FC = FOG_COLOR; // Far (Fog) color SVECTOR lgtang = {0, 0, 0}; MATRIX rotlgt, light; short vs; @@ -130,7 +131,7 @@ int main() { } levelWas = level; // Init dislay, Gte.. - init(disp, draw, db, curLvl.cmat, curLvl.BGc, curLvl.BKc); + init(disp, draw, db, curLvl.cmat, curLvl.BGc, curLvl.BKc, &FC); // Init Pads InitPAD(controllers[0].pad, 34, controllers[1].pad, 34); StartPAD(); diff --git a/src/psx.c b/src/psx.c index 46df548..20737ab 100644 --- a/src/psx.c +++ b/src/psx.c @@ -12,7 +12,7 @@ void setLightEnv(DRAWENV draw[2], CVECTOR * BGc, VECTOR * BKc, MATRIX * cmat){ SetColorMatrix(cmat); }; -void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BGc, VECTOR * BKc) { +void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * BGc, VECTOR * BKc, VECTOR * FC) { ResetCallback(); // Init pad //~ PadInit(0); @@ -37,7 +37,6 @@ void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * B } // Set Draw area color setLightEnv(draw, BGc, BKc, cmat); - // Set Draw area clear flag draw[0].isbg = 1; draw[1].isbg = 1; @@ -53,6 +52,7 @@ void init(DISPENV disp[2], DRAWENV draw[2], short db, MATRIX * cmat, CVECTOR * B FNT_SCR_BG, FNT_SCR_MAX_CHAR ); + SetFarColor(FC->vx, FC->vy, FC->vz); // TODO : Move this to level files SetFogNearFar( FOG_NEAR, FOG_FAR, SCREENXRES ); };