X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=bootcensus;a=blobdiff_plain;f=src%2Fcensus%2F3dgfx.c;fp=src%2Fcensus%2F3dgfx.c;h=a028262b51ae11f65960aa076709e9a823912fa5;hp=9058d284c608ce70f4ab6ca31ca3523b2715ff25;hb=22dd4db1a4ff756f76bdd87062c2252fe3091228;hpb=10843571c724084c68d33d0438167d400cc8de2e diff --git a/src/census/3dgfx.c b/src/census/3dgfx.c index 9058d28..a028262 100644 --- a/src/census/3dgfx.c +++ b/src/census/3dgfx.c @@ -585,20 +585,22 @@ void g3d_normal(float x, float y, float z) st->imm_curv.nz = z; } +#define CLAMP(x, a, b) ((x) < (a) ? (a) : ((x) > (b) ? (b) : (x))) + void g3d_color3b(unsigned char r, unsigned char g, unsigned char b) { - st->imm_curv.r = r; - st->imm_curv.g = g; - st->imm_curv.b = b; + st->imm_curv.r = CLAMP(r, 0, 255); + st->imm_curv.g = CLAMP(g, 0, 255); + st->imm_curv.b = CLAMP(b, 0, 255); st->imm_curv.a = 255; } void g3d_color4b(unsigned char r, unsigned char g, unsigned char b, unsigned char a) { - st->imm_curv.r = r; - st->imm_curv.g = g; - st->imm_curv.b = b; - st->imm_curv.a = a; + st->imm_curv.r = CLAMP(r, 0, 255); + st->imm_curv.g = CLAMP(g, 0, 255); + st->imm_curv.b = CLAMP(b, 0, 255); + st->imm_curv.a = CLAMP(a, 0, 255); } void g3d_color3f(float r, float g, float b) @@ -606,9 +608,9 @@ void g3d_color3f(float r, float g, float b) int ir = r * 255.0f; int ig = g * 255.0f; int ib = b * 255.0f; - st->imm_curv.r = ir > 255 ? 255 : ir; - st->imm_curv.g = ig > 255 ? 255 : ig; - st->imm_curv.b = ib > 255 ? 255 : ib; + st->imm_curv.r = CLAMP(ir, 0, 255); + st->imm_curv.g = CLAMP(ig, 0, 255); + st->imm_curv.b = CLAMP(ib, 0, 255); st->imm_curv.a = 255; } @@ -618,10 +620,10 @@ void g3d_color4f(float r, float g, float b, float a) int ig = g * 255.0f; int ib = b * 255.0f; int ia = a * 255.0f; - st->imm_curv.r = ir > 255 ? 255 : ir; - st->imm_curv.g = ig > 255 ? 255 : ig; - st->imm_curv.b = ib > 255 ? 255 : ib; - st->imm_curv.a = ia > 255 ? 255 : ia; + st->imm_curv.r = CLAMP(ir, 0, 255); + st->imm_curv.g = CLAMP(ig, 0, 255); + st->imm_curv.b = CLAMP(ib, 0, 255); + st->imm_curv.a = CLAMP(ia, 0, 255); } void g3d_texcoord(float u, float v)