diff --git a/src/MD2.m b/src/MD2.m index 998a6b8..52fb417 100644 --- a/src/MD2.m +++ b/src/MD2.m @@ -2,6 +2,8 @@ #include "cube.h" +#import "OFColor+Cube.h" + struct md2_header { int magic; int version; @@ -157,9 +159,7 @@ snap(int sn, float f) glRotatef(yaw + 180, 0, -1, 0); glRotatef(pitch, 0, 0, 1); - float red, green, blue; - [light getRed:&red green:&green blue:&blue alpha:NULL]; - glColor3f(red, green, blue); + [light cube_setAsGLColor]; if (_displaylist && frame == 0 && range == 1) { glCallList(_displaylist); diff --git a/src/OFColor+Cube.h b/src/OFColor+Cube.h new file mode 100644 index 0000000..d8a6a58 --- /dev/null +++ b/src/OFColor+Cube.h @@ -0,0 +1,5 @@ +#import + +@interface OFColor (Cube) +- (void)cube_setAsGLColor; +@end diff --git a/src/OFColor+Cube.m b/src/OFColor+Cube.m new file mode 100644 index 0000000..bcd4281 --- /dev/null +++ b/src/OFColor+Cube.m @@ -0,0 +1,12 @@ +#include "cube.h" + +#import "OFColor+Cube.h" + +@implementation OFColor (Cube) +- (void)cube_setAsGLColor +{ + float red, green, blue, alpha; + [self getRed:&red green:&green blue:&blue alpha:&alpha]; + glColor4f(red, green, blue, alpha); +} +@end diff --git a/src/editing.m b/src/editing.m index 45b7c8f..e2345de 100644 --- a/src/editing.m +++ b/src/editing.m @@ -221,14 +221,23 @@ cursorupdate() // called every frame from hud float h3 = sheight(s, SWS(s, 1, 1, ssize), z); float h4 = sheight(s, SWS(s, 0, 1, ssize), z); if (s->tag) - linestyle(GRIDW, 0xFF, 0x40, 0x40); + linestyle(GRIDW, [OFColor colorWithRed:1.0f + green:0.25f + blue:0.25f + alpha:1.0f]); else if (s->type == FHF || s->type == CHF) - linestyle(GRIDW, 0x80, 0xFF, 0x80); + linestyle(GRIDW, [OFColor colorWithRed:0.5f + green:1.0f + blue:0.5f + alpha:1.0f]); else - linestyle(GRIDW, 0x80, 0x80, 0x80); + linestyle(GRIDW, OFColor.gray); struct block b = { ix, iy, 1, 1 }; box(&b, h1, h2, h3, h4); - linestyle(GRID8, 0x40, 0x40, 0xFF); + linestyle(GRID8, [OFColor colorWithRed:0.25f + green:0.25f + blue:1.0f + alpha:1.0f]); if (!(ix & GRIDM)) line(ix, iy, h1, ix, iy + 1, h4); if (!(ix + 1 & GRIDM)) @@ -242,18 +251,21 @@ cursorupdate() // called every frame from hud if (!SOLID(s)) { float ih = sheight(s, s, z); - linestyle(GRIDS, 0xFF, 0xFF, 0xFF); + linestyle(GRIDS, OFColor.white); struct block b = { cx, cy, 1, 1 }; box(&b, ih, sheight(s, SWS(s, 1, 0, ssize), z), sheight(s, SWS(s, 1, 1, ssize), z), sheight(s, SWS(s, 0, 1, ssize), z)); - linestyle(GRIDS, 0xFF, 0x00, 0x00); + linestyle(GRIDS, OFColor.red); dot(cx, cy, ih); ch = (int)ih; } if (selset) { - linestyle(GRIDS, 0xFF, 0x40, 0x40); + linestyle(GRIDS, [OFColor colorWithRed:1.0f + green:0.25f + blue:0.25f + alpha:1.0f]); box(&sel, (float)selh, (float)selh, (float)selh, (float)selh); } } diff --git a/src/meson.build b/src/meson.build index ca202e9..e3751fa 100644 --- a/src/meson.build +++ b/src/meson.build @@ -14,6 +14,7 @@ executable('client', 'Menu.m', 'MenuItem.m', 'Monster.m', + 'OFColor+Cube.m', 'OFString+Cube.m', 'Player.m', 'Projectile.m', diff --git a/src/protos.h b/src/protos.h index ec8d348..cf60f03 100644 --- a/src/protos.h +++ b/src/protos.h @@ -166,7 +166,7 @@ extern void pruneundos(int maxremain); extern void line(int x1, int y1, float z1, int x2, int y2, float z2); extern void box(const struct block *b, float z1, float z2, float z3, float z4); extern void dot(int x, int y, float z); -extern void linestyle(float width, int r, int g, int b); +extern void linestyle(float width, OFColor *color); extern void newsphere(OFVector3D o, float max, int type); extern void renderspheres(int time); extern void gl_drawhud( diff --git a/src/renderextras.m b/src/renderextras.m index 8f9f6a6..575ae24 100644 --- a/src/renderextras.m +++ b/src/renderextras.m @@ -4,6 +4,7 @@ #import "Command.h" #import "Entity.h" +#import "OFColor+Cube.h" #import "Player.h" #import "Variable.h" @@ -20,10 +21,10 @@ line(int x1, int y1, float z1, int x2, int y2, float z2) } void -linestyle(float width, int r, int g, int b) +linestyle(float width, OFColor *color) { glLineWidth(width); - glColor3ub(r, g, b); + [color cube_setAsGLColor]; } void @@ -59,9 +60,12 @@ blendbox(int x1, int y1, int x2, int y2, bool border) glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); glBegin(GL_QUADS); if (border) - glColor3d(0.5, 0.3, 0.4); + [[OFColor colorWithRed:0.5f + green:0.3f + blue:0.4f + alpha:1.0f] cube_setAsGLColor]; else - glColor3d(1.0, 1.0, 1.0); + [OFColor.white cube_setAsGLColor]; glVertex2i(x1, y1); glVertex2i(x2, y1); glVertex2i(x2, y2); @@ -70,7 +74,10 @@ blendbox(int x1, int y1, int x2, int y2, bool border) glDisable(GL_BLEND); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glBegin(GL_POLYGON); - glColor3d(0.2, 0.7, 0.4); + [[OFColor colorWithRed:0.2f + green:0.7f + blue:0.4f + alpha:1.0f] cube_setAsGLColor]; glVertex2i(x1, y1); glVertex2i(x2, y1); glVertex2i(x2, y2); @@ -126,7 +133,10 @@ renderspheres(int time) for (struct sphere *p, **pp = &slist; (p = *pp) != NULL;) { glPushMatrix(); float size = p->size / p->max; - glColor4f(1.0f, 1.0f, 1.0f, 1.0f - size); + [[OFColor colorWithRed:1.0f + green:1.0f + blue:1.0f + alpha:1.0f - size] cube_setAsGLColor]; glTranslatef(p->o.x, p->o.z, p->o.y); glRotatef(lastmillis / 5.0f, 1, 1, 1); glScalef(p->size, p->size, p->size); @@ -351,9 +361,15 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater) glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR); glBegin(GL_QUADS); if (dblend) - glColor3d(0.0f, 0.9f, 0.9f); + [[OFColor colorWithRed:0.0f + green:0.9f + blue:0.9f + alpha:1.0f] cube_setAsGLColor]; else - glColor3d(0.9f, 0.5f, 0.0f); + [[OFColor colorWithRed:0.9f + green:0.5f + blue:0.0f + alpha:1.0f] cube_setAsGLColor]; glVertex2i(0, 0); glVertex2i(VIRTW, 0); glVertex2i(VIRTW, VIRTH); @@ -381,14 +397,17 @@ gl_drawhud(int w, int h, int curfps, int nquads, int curvert, bool underwater) glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA); glBindTexture(GL_TEXTURE_2D, 1); glBegin(GL_QUADS); - glColor3ub(255, 255, 255); + [OFColor.white cube_setAsGLColor]; if (crosshairfx) { if (player1.gunWait) - glColor3ub(128, 128, 128); + [OFColor.gray cube_setAsGLColor]; else if (player1.health <= 25) - glColor3ub(255, 0, 0); + [OFColor.red cube_setAsGLColor]; else if (player1.health <= 50) - glColor3ub(255, 128, 0); + [[OFColor colorWithRed:1.0f + green:0.5f + blue:0.0f + alpha:1.0f] cube_setAsGLColor]; } float chsize = (float)crosshairsize; glTexCoord2d(0.0, 0.0); diff --git a/src/rendergl.m b/src/rendergl.m index 9d50f82..921f2e8 100644 --- a/src/rendergl.m +++ b/src/rendergl.m @@ -6,6 +6,7 @@ #import "Command.h" #import "Monster.h" +#import "OFColor+Cube.h" #import "OFString+Cube.h" #import "Player.h" #import "Variable.h" @@ -471,7 +472,7 @@ gl_drawframe(int w, int h, float curfps) glRotated(player1.pitch, -1.0, 0.0, 0.0); glRotated(player1.yaw, 0.0, 1.0, 0.0); glRotated(90.0, 1.0, 0.0, 0.0); - glColor3f(1.0f, 1.0f, 1.0f); + [OFColor.white cube_setAsGLColor]; glDisable(GL_FOG); glDepthFunc(GL_GREATER); draw_envbox(14, fog * 4 / 3); diff --git a/src/rendertext.m b/src/rendertext.m index 3682d71..0239998 100644 --- a/src/rendertext.m +++ b/src/rendertext.m @@ -2,6 +2,8 @@ #include "cube.h" +#import "OFColor+Cube.h" + short char_coords[96][4] = { { 0, 0, 25, 64 }, //! { 25, 0, 54, 64 }, //" @@ -148,7 +150,7 @@ draw_text(OFString *string, int left, int top, int gl_num) { glBlendFunc(GL_ONE, GL_ONE); glBindTexture(GL_TEXTURE_2D, gl_num); - glColor3ub(255, 255, 255); + [OFColor.white cube_setAsGLColor]; int x = left; int y = top; @@ -168,7 +170,10 @@ draw_text(OFString *string, int left, int top, int gl_num) } if (c == '\f') { - glColor3ub(64, 255, 128); + [[OFColor colorWithRed:0.25f + green:1.0f + blue:0.5f + alpha:1.0f] cube_setAsGLColor]; continue; }