Index: src/MD2.m ================================================================== --- src/MD2.m +++ src/MD2.m @@ -1,9 +1,11 @@ #import "MD2.h" #include "cube.h" +#import "OFColor+Cube.h" + struct md2_header { int magic; int version; int skinWidth, skinHeight; int frameSize; @@ -155,13 +157,11 @@ glPushMatrix(); glTranslatef(position.x, position.y, position.z); 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); xtraverts += _displaylistverts; } else { ADDED src/OFColor+Cube.h Index: src/OFColor+Cube.h ================================================================== --- /dev/null +++ src/OFColor+Cube.h @@ -0,0 +1,5 @@ +#import + +@interface OFColor (Cube) +- (void)cube_setAsGLColor; +@end ADDED src/OFColor+Cube.m Index: src/OFColor+Cube.m ================================================================== --- /dev/null +++ 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 Index: src/editing.m ================================================================== --- src/editing.m +++ src/editing.m @@ -219,18 +219,27 @@ float h1 = sheight(s, s, z); float h2 = sheight(s, SWS(s, 1, 0, ssize), z); 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)) line(ix + 1, iy, h2, ix + 1, iy + 1, h3); if (!(iy & GRIDM)) @@ -240,22 +249,25 @@ } } 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); } } static OFMutableData *undos; // unlimited undo Index: src/meson.build ================================================================== --- src/meson.build +++ src/meson.build @@ -12,10 +12,11 @@ 'MD2.m', 'MapModelInfo.m', 'Menu.m', 'MenuItem.m', 'Monster.m', + 'OFColor+Cube.m', 'OFString+Cube.m', 'Player.m', 'Projectile.m', 'ResolverResult.m', 'ResolverThread.m', Index: src/protos.h ================================================================== --- src/protos.h +++ src/protos.h @@ -164,11 +164,11 @@ // renderextras 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( int w, int h, int curfps, int nquads, int curvert, bool underwater); extern void readdepth(int w, int h); Index: src/renderextras.m ================================================================== --- src/renderextras.m +++ src/renderextras.m @@ -2,10 +2,11 @@ #include "cube.h" #import "Command.h" #import "Entity.h" +#import "OFColor+Cube.h" #import "Player.h" #import "Variable.h" void line(int x1, int y1, float z1, int x2, int y2, float z2) @@ -18,14 +19,14 @@ glEnd(); xtraverts += 4; } 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 box(const struct block *b, float z1, float z2, float z3, float z4) { @@ -57,22 +58,28 @@ glDepthMask(GL_FALSE); glDisable(GL_TEXTURE_2D); 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); glVertex2i(x1, y2); glEnd(); 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); glVertex2i(x1, y2); glEnd(); @@ -124,11 +131,14 @@ glBindTexture(GL_TEXTURE_2D, 4); 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); glCallList(1); glScalef(0.8f, 0.8f, 0.8f); @@ -349,13 +359,19 @@ if (dblend || 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); glVertex2i(0, VIRTH); glEnd(); @@ -379,18 +395,21 @@ renderscores(); if (!rendermenu()) { 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); glVertex2f(VIRTW / 2 - chsize, VIRTH / 2 - chsize); glTexCoord2d(1.0, 0.0); Index: src/rendergl.m ================================================================== --- src/rendergl.m +++ src/rendergl.m @@ -4,10 +4,11 @@ #include "cube.h" #import "Command.h" #import "Monster.h" +#import "OFColor+Cube.h" #import "OFString+Cube.h" #import "Player.h" #import "Variable.h" #ifdef DARWIN @@ -469,11 +470,11 @@ glLoadIdentity(); 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); glDepthFunc(GL_LESS); glEnable(GL_FOG); Index: src/rendertext.m ================================================================== --- src/rendertext.m +++ src/rendertext.m @@ -1,8 +1,10 @@ // rendertext.cpp: based on Don's gl_text.cpp #include "cube.h" + +#import "OFColor+Cube.h" short char_coords[96][4] = { { 0, 0, 25, 64 }, //! { 25, 0, 54, 64 }, //" { 54, 0, 107, 64 }, // # @@ -146,11 +148,11 @@ void 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; int i; @@ -166,11 +168,14 @@ x = (x - left + PIXELTAB) / PIXELTAB * PIXELTAB + left; continue; } if (c == '\f') { - glColor3ub(64, 255, 128); + [[OFColor colorWithRed:0.25f + green:1.0f + blue:0.5f + alpha:1.0f] cube_setAsGLColor]; continue; } if (c == ' ') { x += FONTH / 2;