Make more use of OFColor
FossilOrigin-Name: 932a90c261ff698efcf7980c8790080622cd79e5e6ae9c7c066c27716af83f28
This commit is contained in:
parent
c7ee55e1e3
commit
3a081f18e5
9 changed files with 81 additions and 26 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
|
||||||
|
#import "OFColor+Cube.h"
|
||||||
|
|
||||||
struct md2_header {
|
struct md2_header {
|
||||||
int magic;
|
int magic;
|
||||||
int version;
|
int version;
|
||||||
|
@ -157,9 +159,7 @@ snap(int sn, float f)
|
||||||
glRotatef(yaw + 180, 0, -1, 0);
|
glRotatef(yaw + 180, 0, -1, 0);
|
||||||
glRotatef(pitch, 0, 0, 1);
|
glRotatef(pitch, 0, 0, 1);
|
||||||
|
|
||||||
float red, green, blue;
|
[light cube_setAsGLColor];
|
||||||
[light getRed:&red green:&green blue:&blue alpha:NULL];
|
|
||||||
glColor3f(red, green, blue);
|
|
||||||
|
|
||||||
if (_displaylist && frame == 0 && range == 1) {
|
if (_displaylist && frame == 0 && range == 1) {
|
||||||
glCallList(_displaylist);
|
glCallList(_displaylist);
|
||||||
|
|
5
src/OFColor+Cube.h
Normal file
5
src/OFColor+Cube.h
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
#import <ObjFW/ObjFW.h>
|
||||||
|
|
||||||
|
@interface OFColor (Cube)
|
||||||
|
- (void)cube_setAsGLColor;
|
||||||
|
@end
|
12
src/OFColor+Cube.m
Normal file
12
src/OFColor+Cube.m
Normal file
|
@ -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
|
|
@ -221,14 +221,23 @@ cursorupdate() // called every frame from hud
|
||||||
float h3 = sheight(s, SWS(s, 1, 1, ssize), z);
|
float h3 = sheight(s, SWS(s, 1, 1, ssize), z);
|
||||||
float h4 = sheight(s, SWS(s, 0, 1, ssize), z);
|
float h4 = sheight(s, SWS(s, 0, 1, ssize), z);
|
||||||
if (s->tag)
|
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)
|
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
|
else
|
||||||
linestyle(GRIDW, 0x80, 0x80, 0x80);
|
linestyle(GRIDW, OFColor.gray);
|
||||||
struct block b = { ix, iy, 1, 1 };
|
struct block b = { ix, iy, 1, 1 };
|
||||||
box(&b, h1, h2, h3, h4);
|
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))
|
if (!(ix & GRIDM))
|
||||||
line(ix, iy, h1, ix, iy + 1, h4);
|
line(ix, iy, h1, ix, iy + 1, h4);
|
||||||
if (!(ix + 1 & GRIDM))
|
if (!(ix + 1 & GRIDM))
|
||||||
|
@ -242,18 +251,21 @@ cursorupdate() // called every frame from hud
|
||||||
|
|
||||||
if (!SOLID(s)) {
|
if (!SOLID(s)) {
|
||||||
float ih = sheight(s, s, z);
|
float ih = sheight(s, s, z);
|
||||||
linestyle(GRIDS, 0xFF, 0xFF, 0xFF);
|
linestyle(GRIDS, OFColor.white);
|
||||||
struct block b = { cx, cy, 1, 1 };
|
struct block b = { cx, cy, 1, 1 };
|
||||||
box(&b, ih, sheight(s, SWS(s, 1, 0, ssize), z),
|
box(&b, ih, sheight(s, SWS(s, 1, 0, ssize), z),
|
||||||
sheight(s, SWS(s, 1, 1, ssize), z),
|
sheight(s, SWS(s, 1, 1, ssize), z),
|
||||||
sheight(s, SWS(s, 0, 1, ssize), z));
|
sheight(s, SWS(s, 0, 1, ssize), z));
|
||||||
linestyle(GRIDS, 0xFF, 0x00, 0x00);
|
linestyle(GRIDS, OFColor.red);
|
||||||
dot(cx, cy, ih);
|
dot(cx, cy, ih);
|
||||||
ch = (int)ih;
|
ch = (int)ih;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (selset) {
|
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);
|
box(&sel, (float)selh, (float)selh, (float)selh, (float)selh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ executable('client',
|
||||||
'Menu.m',
|
'Menu.m',
|
||||||
'MenuItem.m',
|
'MenuItem.m',
|
||||||
'Monster.m',
|
'Monster.m',
|
||||||
|
'OFColor+Cube.m',
|
||||||
'OFString+Cube.m',
|
'OFString+Cube.m',
|
||||||
'Player.m',
|
'Player.m',
|
||||||
'Projectile.m',
|
'Projectile.m',
|
||||||
|
|
|
@ -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 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 box(const struct block *b, float z1, float z2, float z3, float z4);
|
||||||
extern void dot(int x, int y, float z);
|
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 newsphere(OFVector3D o, float max, int type);
|
||||||
extern void renderspheres(int time);
|
extern void renderspheres(int time);
|
||||||
extern void gl_drawhud(
|
extern void gl_drawhud(
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#import "Command.h"
|
#import "Command.h"
|
||||||
#import "Entity.h"
|
#import "Entity.h"
|
||||||
|
#import "OFColor+Cube.h"
|
||||||
#import "Player.h"
|
#import "Player.h"
|
||||||
#import "Variable.h"
|
#import "Variable.h"
|
||||||
|
|
||||||
|
@ -20,10 +21,10 @@ line(int x1, int y1, float z1, int x2, int y2, float z2)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
linestyle(float width, int r, int g, int b)
|
linestyle(float width, OFColor *color)
|
||||||
{
|
{
|
||||||
glLineWidth(width);
|
glLineWidth(width);
|
||||||
glColor3ub(r, g, b);
|
[color cube_setAsGLColor];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -59,9 +60,12 @@ blendbox(int x1, int y1, int x2, int y2, bool border)
|
||||||
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
|
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
if (border)
|
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
|
else
|
||||||
glColor3d(1.0, 1.0, 1.0);
|
[OFColor.white cube_setAsGLColor];
|
||||||
glVertex2i(x1, y1);
|
glVertex2i(x1, y1);
|
||||||
glVertex2i(x2, y1);
|
glVertex2i(x2, y1);
|
||||||
glVertex2i(x2, y2);
|
glVertex2i(x2, y2);
|
||||||
|
@ -70,7 +74,10 @@ blendbox(int x1, int y1, int x2, int y2, bool border)
|
||||||
glDisable(GL_BLEND);
|
glDisable(GL_BLEND);
|
||||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||||
glBegin(GL_POLYGON);
|
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(x1, y1);
|
||||||
glVertex2i(x2, y1);
|
glVertex2i(x2, y1);
|
||||||
glVertex2i(x2, y2);
|
glVertex2i(x2, y2);
|
||||||
|
@ -126,7 +133,10 @@ renderspheres(int time)
|
||||||
for (struct sphere *p, **pp = &slist; (p = *pp) != NULL;) {
|
for (struct sphere *p, **pp = &slist; (p = *pp) != NULL;) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
float size = p->size / p->max;
|
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);
|
glTranslatef(p->o.x, p->o.z, p->o.y);
|
||||||
glRotatef(lastmillis / 5.0f, 1, 1, 1);
|
glRotatef(lastmillis / 5.0f, 1, 1, 1);
|
||||||
glScalef(p->size, p->size, p->size);
|
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);
|
glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_COLOR);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
if (dblend)
|
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
|
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(0, 0);
|
||||||
glVertex2i(VIRTW, 0);
|
glVertex2i(VIRTW, 0);
|
||||||
glVertex2i(VIRTW, VIRTH);
|
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);
|
glBlendFunc(GL_SRC_ALPHA, GL_SRC_ALPHA);
|
||||||
glBindTexture(GL_TEXTURE_2D, 1);
|
glBindTexture(GL_TEXTURE_2D, 1);
|
||||||
glBegin(GL_QUADS);
|
glBegin(GL_QUADS);
|
||||||
glColor3ub(255, 255, 255);
|
[OFColor.white cube_setAsGLColor];
|
||||||
if (crosshairfx) {
|
if (crosshairfx) {
|
||||||
if (player1.gunWait)
|
if (player1.gunWait)
|
||||||
glColor3ub(128, 128, 128);
|
[OFColor.gray cube_setAsGLColor];
|
||||||
else if (player1.health <= 25)
|
else if (player1.health <= 25)
|
||||||
glColor3ub(255, 0, 0);
|
[OFColor.red cube_setAsGLColor];
|
||||||
else if (player1.health <= 50)
|
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;
|
float chsize = (float)crosshairsize;
|
||||||
glTexCoord2d(0.0, 0.0);
|
glTexCoord2d(0.0, 0.0);
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#import "Command.h"
|
#import "Command.h"
|
||||||
#import "Monster.h"
|
#import "Monster.h"
|
||||||
|
#import "OFColor+Cube.h"
|
||||||
#import "OFString+Cube.h"
|
#import "OFString+Cube.h"
|
||||||
#import "Player.h"
|
#import "Player.h"
|
||||||
#import "Variable.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.pitch, -1.0, 0.0, 0.0);
|
||||||
glRotated(player1.yaw, 0.0, 1.0, 0.0);
|
glRotated(player1.yaw, 0.0, 1.0, 0.0);
|
||||||
glRotated(90.0, 1.0, 0.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);
|
glDisable(GL_FOG);
|
||||||
glDepthFunc(GL_GREATER);
|
glDepthFunc(GL_GREATER);
|
||||||
draw_envbox(14, fog * 4 / 3);
|
draw_envbox(14, fog * 4 / 3);
|
||||||
|
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
#include "cube.h"
|
#include "cube.h"
|
||||||
|
|
||||||
|
#import "OFColor+Cube.h"
|
||||||
|
|
||||||
short char_coords[96][4] = {
|
short char_coords[96][4] = {
|
||||||
{ 0, 0, 25, 64 }, //!
|
{ 0, 0, 25, 64 }, //!
|
||||||
{ 25, 0, 54, 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);
|
glBlendFunc(GL_ONE, GL_ONE);
|
||||||
glBindTexture(GL_TEXTURE_2D, gl_num);
|
glBindTexture(GL_TEXTURE_2D, gl_num);
|
||||||
glColor3ub(255, 255, 255);
|
[OFColor.white cube_setAsGLColor];
|
||||||
|
|
||||||
int x = left;
|
int x = left;
|
||||||
int y = top;
|
int y = top;
|
||||||
|
@ -168,7 +170,10 @@ draw_text(OFString *string, int left, int top, int gl_num)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c == '\f') {
|
if (c == '\f') {
|
||||||
glColor3ub(64, 255, 128);
|
[[OFColor colorWithRed:0.25f
|
||||||
|
green:1.0f
|
||||||
|
blue:0.5f
|
||||||
|
alpha:1.0f] cube_setAsGLColor];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue