[Change] Target color changes based on target.

This commit is contained in:
Allanis 2013-02-13 14:30:17 +00:00
parent c20a20e103
commit 053d7b75b6
6 changed files with 56 additions and 46 deletions

View File

@ -329,7 +329,7 @@ void gl_getSpriteFromDir(int* x, int* y, const gl_texture* t, const double dir)
// ================ // ================
// Blit the sprite at given position. // Blit the sprite at given position.
void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, const int sy) { void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, const int sy, const glColor* c) {
// Don't bother drawing if offscreen -- waste of cycles. // Don't bother drawing if offscreen -- waste of cycles.
if(fabs(VX(*pos) -VX(*gl_camera)) > gl_screen.w / 2 + sprite->sw / 2 || if(fabs(VX(*pos) -VX(*gl_camera)) > gl_screen.w / 2 + sprite->sw / 2 ||
fabs(VY(*pos) -VY(*gl_camera)) > gl_screen.h / 2 + sprite->sh / 2) fabs(VY(*pos) -VY(*gl_camera)) > gl_screen.h / 2 + sprite->sh / 2)
@ -345,12 +345,13 @@ void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, cons
glPushMatrix(); // Projection translation matrix. glPushMatrix(); // Projection translation matrix.
glTranslated(VX(*pos) - VX(*gl_camera) - sprite->sw/2. + gui_xoff, glTranslated(VX(*pos) - VX(*gl_camera) - sprite->sw/2. + gui_xoff,
VY(*pos) -VY(*gl_camera) - sprite->sh/2. + gui_yoff, 0.); VY(*pos) -VY(*gl_camera) - sprite->sh/2. + gui_yoff, 0.);
glScalef((double)gl_screen.w/SCREEN_W, (double)gl_screen.h/SCREEN_H, 0.); //glScalef((double)gl_screen.w/SCREEN_W, (double)gl_screen.h/SCREEN_H, 0.);
// Actual blitting.... // Actual blitting....
glBindTexture(GL_TEXTURE_2D, sprite->texture); glBindTexture(GL_TEXTURE_2D, sprite->texture);
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
glColor4d(1., 1., 1., 1.); if(c == NULL) glColor4d(1., 1., 1., 1.);
else COLOR(*c);
glTexCoord2d(0., 0.); glTexCoord2d(0., 0.);
glVertex2d(0., 0.); glVertex2d(0., 0.);
glTexCoord2d(sprite->sw/sprite->rw, 0.); glTexCoord2d(sprite->sw/sprite->rw, 0.);
@ -370,17 +371,18 @@ void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, cons
} }
// Just straight out blit the thing at position. // Just straight out blit the thing at position.
void gl_blitStatic(const gl_texture* texture, const Vec2* pos) { void gl_blitStatic(const gl_texture* texture, const Vec2* pos, const glColor* c) {
glEnable(GL_TEXTURE_2D); glEnable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); // Set up translation matrix. glPushMatrix(); // Set up translation matrix.
glTranslated(VX(*pos) - (double)gl_screen.w/2., VY(*pos) - (double)gl_screen.h/2., 0); glTranslated(VX(*pos) - (double)gl_screen.w/2., VY(*pos) - (double)gl_screen.h/2., 0);
glScaled((double)gl_screen.w/SCREEN_W, (double)gl_screen.h/SCREEN_H, 0.); //glScaled((double)gl_screen.w/SCREEN_W, (double)gl_screen.h/SCREEN_H, 0.);
// Actual blitting.. // Actual blitting..
glBindTexture(GL_TEXTURE_2D, texture->texture); glBindTexture(GL_TEXTURE_2D, texture->texture);
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
glColor4d(1., 1., 1., 1.); if(c == NULL) glColor4d(1., 1., 1., 1.);
else COLOR(*c);
glTexCoord2d(0., 0.); glTexCoord2d(0., 0.);
glVertex2d(0., 0.); glVertex2d(0., 0.);
glTexCoord2d(texture->sw/texture->rw, 0.); glTexCoord2d(texture->sw/texture->rw, 0.);
@ -403,7 +405,7 @@ void gl_bindCamera(const Vec2* pos) {
// Print text on screen! YES!!!! Just like printf! But different! // Print text on screen! YES!!!! Just like printf! But different!
// Defaults ft_font to gl_defFont if NULL. // Defaults ft_font to gl_defFont if NULL.
void gl_print(const gl_font* ft_font, const Vec2* pos, const char* fmt, ...) { void gl_print(const gl_font* ft_font, const Vec2* pos, const glColor* c, const char* fmt, ...) {
//float h = ft_font->h / .63; // Slightly increases font size. //float h = ft_font->h / .63; // Slightly increases font size.
char text[256]; char text[256];
va_list ap; va_list ap;
@ -427,7 +429,8 @@ void gl_print(const gl_font* ft_font, const Vec2* pos, const char* fmt, ...) {
glPushMatrix(); // Translation matrix. glPushMatrix(); // Translation matrix.
glTranslated(VX(*pos) - (double)gl_screen.w/2., VY(*pos) - (double)gl_screen.h/2., 0); glTranslated(VX(*pos) - (double)gl_screen.w/2., VY(*pos) - (double)gl_screen.h/2., 0);
glColor4d(1., 1., 1., 1.); if(c == NULL) glColor4d(1., 1., 1., 1.);
else COLOR(*c);
glCallLists(strlen(text), GL_UNSIGNED_BYTE, &text); glCallLists(strlen(text), GL_UNSIGNED_BYTE, &text);
glPopMatrix(); // Translation matrix. glPopMatrix(); // Translation matrix.

View File

@ -25,9 +25,14 @@ typedef struct {
int r, g, b, a; // Framebuffer values in bits. int r, g, b, a; // Framebuffer values in bits.
int doublebuf; // Double buffer. int doublebuf; // Double buffer.
} gl_info; } gl_info;
extern gl_info gl_screen; // Local structure set with gl_init etc. extern gl_info gl_screen; // Local structure set with gl_init etc.
// Colors.
typedef struct {
double r, g, b, a;
} glColor;
#define COLOR(x) glColor4d((x).r, (x).g, (x).b, (x).a)
// Spritesheet info. // Spritesheet info.
typedef struct { typedef struct {
double w, h; // Real size of the image (excluding POT buffer. double w, h; // Real size of the image (excluding POT buffer.
@ -58,10 +63,12 @@ gl_texture* gl_newSprite(const char* path, const int sx, const int sy);
void gl_freeTexture(gl_texture* texture); void gl_freeTexture(gl_texture* texture);
// Rendering. // Rendering.
void gl_blitSprite(const gl_texture* sprite, const Vec2* pos, const int sx, const int sy); void gl_blitSprite(const gl_texture* sprite, const Vec2* pos,
void gl_blitStatic(const gl_texture* texture, const Vec2* pos); const int sx, const int sy, const glColor* c);
void gl_blitStatic(const gl_texture* texture, const Vec2* pos, const glColor* c);
void gl_bindCamera(const Vec2* pos); void gl_bindCamera(const Vec2* pos);
void gl_print(const gl_font* ft_font, const Vec2* pos, const char* fmt, ...); void gl_print(const gl_font* ft_font, const Vec2* pos, const glColor* c, const char* fmt, ...);
// Initialize/cleanup. // Initialize/cleanup.
int gl_init(void); int gl_init(void);

View File

@ -154,7 +154,7 @@ void pilot_render(Pilot* p) {
// Get the sprite corresponding to the direction facing. // Get the sprite corresponding to the direction facing.
gl_getSpriteFromDir(&sx, &sy, p->ship->gfx_space, p->solid->dir); gl_getSpriteFromDir(&sx, &sy, p->ship->gfx_space, p->solid->dir);
gl_blitSprite(p->ship->gfx_space, &p->solid->pos, sx, sy); gl_blitSprite(p->ship->gfx_space, &p->solid->pos, sx, sy, NULL);
} }
// Update the pilot. // Update the pilot.

View File

@ -50,25 +50,21 @@ extern Pilot** pilot_stack;
extern int pilots; extern int pilots;
// GUI crap. // GUI crap.
// Need these offsets to render properly. -- Used in opengl.c
// -- Colors.
typedef struct {
double r, g, b, a;
} Color;
#define COLOR(x) glColor4d((x).r, (x).g, (x).b, (x).a)
// Standard colors.
Color cInert = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. };
Color cNeutral = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. };
Color cFriend = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. };
Color cHostile = { .r = 0.9, .g = 0.2, .b = 0.2, .a = 1. };
Color cRadar_player = { .r = 0.4, .g = 0.8, .b = 0.4, .a = 1. }; // -- Colors.
Color cRadar_targ = { .r = 0.0, .g = 0.7, .b = 1.0, .a = 1. }; // Standard colors.
Color cRadar_weap = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. }; glColor cInert = { .r = 0.6, .g = 0.6, .b = 0.6, .a = 1. };
glColor cNeutral = { .r = 0.9, .g = 1.0, .b = 0.3, .a = 1. };
glColor cFriend = { .r = 0.0, .g = 1.0, .b = 0.0, .a = 1. };
glColor cHostile = { .r = 0.9, .g = 0.2, .b = 0.2, .a = 1. };
glColor cRadar_player = { .r = 0.4, .g = 0.8, .b = 0.4, .a = 1. };
glColor cRadar_targ = { .r = 0.0, .g = 0.7, .b = 1.0, .a = 1. };
glColor cRadar_weap = { .r = 0.8, .g = 0.2, .b = 0.2, .a = 1. };
// Bars. // Bars.
Color cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. }; glColor cShield = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 1. };
Color cArmor = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. }; glColor cArmor = { .r = 0.5, .g = 0.5, .b = 0.5, .a = 1. };
Color cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. }; glColor cEnergy = { .r = 0.2, .g = 0.8, .b = 0.2, .a = 1. };
typedef struct { typedef struct {
double w,h; // Dimensions. double w,h; // Dimensions.
@ -124,7 +120,7 @@ extern void planets_minimap(const double res, const double w, const double h, co
static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w, double* h); static void rect_parse(const xmlNodePtr parent, double* x, double* y, double* w, double* h);
static int gui_parse(const xmlNodePtr parent, const char* name); static int gui_parse(const xmlNodePtr parent, const char* name);
static void gui_renderPilot(const Pilot* p); static void gui_renderPilot(const Pilot* p);
static void gui_renderBar(const Color* c, const Vec2* p, const Rect* r, const double w); static void gui_renderBar(const glColor* c, const Vec2* p, const Rect* r, const double w);
void player_message(const char* fmt, ...) { void player_message(const char* fmt, ...) {
va_list ap; va_list ap;
@ -151,20 +147,24 @@ void player_render(void) {
int i, j; int i, j;
Pilot* p; Pilot* p;
Vec2 v; Vec2 v;
glColor* c;
// Render the player target graphics. // Render the player target graphics.
if(player_target != PLAYER_ID) { if(player_target != PLAYER_ID) {
p = pilot_get(player_target); p = pilot_get(player_target);
if(pilot_isFlag(p, PILOT_HOSTILE)) c = &cHostile;
else c = &cNeutral;
vect_csetmin(&v, VX(p->solid->pos) - p->ship->gfx_space->sw * PILOT_SIZE_APROX/2., vect_csetmin(&v, VX(p->solid->pos) - p->ship->gfx_space->sw * PILOT_SIZE_APROX/2.,
VY(p->solid->pos) + p->ship->gfx_space->sh * PILOT_SIZE_APROX/2.); VY(p->solid->pos) + p->ship->gfx_space->sh * PILOT_SIZE_APROX/2.);
gl_blitSprite(gui.gfx_targetPilot, &v, 0, 0); // Top left. gl_blitSprite(gui.gfx_targetPilot, &v, 0, 0, c); // Top left.
VX(v) += p->ship->gfx_space->sw * PILOT_SIZE_APROX; VX(v) += p->ship->gfx_space->sw * PILOT_SIZE_APROX;
gl_blitSprite(gui.gfx_targetPilot, &v, 1, 0); // Top right. gl_blitSprite(gui.gfx_targetPilot, &v, 1, 0, c); // Top right.
VY(v) -= p->ship->gfx_space->sh * PILOT_SIZE_APROX; VY(v) -= p->ship->gfx_space->sh * PILOT_SIZE_APROX;
gl_blitSprite(gui.gfx_targetPilot, &v, 1, 1); // Bottom right. gl_blitSprite(gui.gfx_targetPilot, &v, 1, 1, c); // Bottom right.
VX(v) -= p->ship->gfx_space->sw * PILOT_SIZE_APROX; VX(v) -= p->ship->gfx_space->sw * PILOT_SIZE_APROX;
gl_blitSprite(gui.gfx_targetPilot, &v, 0, 1); // Bottom left. gl_blitSprite(gui.gfx_targetPilot, &v, 0, 1, c); // Bottom left.
} }
// Render the player. // Render the player.
@ -172,7 +172,7 @@ void player_render(void) {
// GUI! // GUI!
// -- Frame. // -- Frame.
gl_blitStatic(gui.gfx_frame, &gui.pos_frame); gl_blitStatic(gui.gfx_frame, &gui.pos_frame, NULL);
// -- Radar. // -- Radar.
glMatrixMode(GL_PROJECTION); glMatrixMode(GL_PROJECTION);
glPushMatrix(); glPushMatrix();
@ -229,22 +229,22 @@ void player_render(void) {
if(player_target != PLAYER_ID) { if(player_target != PLAYER_ID) {
p = pilot_get(player_target); p = pilot_get(player_target);
gl_blitStatic(p->ship->gfx_target, &gui.pos_target); gl_blitStatic(p->ship->gfx_target, &gui.pos_target, NULL);
// Target name. // Target name.
gl_print(NULL, &gui.pos_target_name, "%s", p->name); gl_print(NULL, &gui.pos_target_name, NULL, "%s", p->name);
gl_print(&gui.smallFont, &gui.pos_target_faction, "%s", p->faction->name); gl_print(&gui.smallFont, &gui.pos_target_faction, NULL, "%s", p->faction->name);
// Target status. // Target status.
if(p->armor < p->armor_max * PILOT_DISABLED) if(p->armor < p->armor_max * PILOT_DISABLED)
// Disable the pilot. // Disable the pilot.
gl_print(&gui.smallFont, &gui.pos_target_health, "Disabled"); gl_print(&gui.smallFont, &gui.pos_target_health, NULL, "Disabled");
else if(p->shield > p->shield_max / 100.) else if(p->shield > p->shield_max / 100.)
// On shields. // On shields.
gl_print(&gui.smallFont, &gui.pos_target_health, "%s: %.0f%%", "Shield", p->shield/p->shield_max*100.); gl_print(&gui.smallFont, &gui.pos_target_health, NULL, "%s: %.0f%%", "Shield", p->shield/p->shield_max*100.);
else else
// On armor. // On armor.
gl_print(&gui.smallFont, &gui.pos_target_health, "%s: %.0f%%", "Armor", p->armor/p->armor_max*100.); gl_print(&gui.smallFont, &gui.pos_target_health, NULL, "%s: %.0f%%", "Armor", p->armor/p->armor_max*100.);
} }
// Messages. // Messages.
VX(v) = VX(gui.pos_msg); VX(v) = VX(gui.pos_msg);
@ -254,7 +254,7 @@ void player_render(void) {
if(msg_stack[msg_max-i-1].str[0] != '\0') { if(msg_stack[msg_max-i-1].str[0] != '\0') {
if(msg_stack[msg_max-i-1].t < SDL_GetTicks()) if(msg_stack[msg_max-i-1].t < SDL_GetTicks())
msg_stack[msg_max-i-1].str[0] = '\0'; msg_stack[msg_max-i-1].str[0] = '\0';
else gl_print(NULL, &v, "%s", msg_stack[msg_max-i-1].str); else gl_print(NULL, &v, NULL, "%s", msg_stack[msg_max-i-1].str);
} }
} }
} }
@ -300,7 +300,7 @@ static void gui_renderPilot(const Pilot* p) {
} }
// Render a bar. // Render a bar.
static void gui_renderBar(const Color* c, const Vec2* p, const Rect* r, const double w) { static void gui_renderBar(const glColor* c, const Vec2* p, const Rect* r, const double w) {
int x, y, sx, sy; int x, y, sx, sy;
glBegin(GL_QUADS); glBegin(GL_QUADS);

View File

@ -460,7 +460,7 @@ void space_render(double dt) {
void planets_render(void) { void planets_render(void) {
int i; int i;
for(i = 0; i < cur_system->nplanets; i++) for(i = 0; i < cur_system->nplanets; i++)
gl_blitSprite(cur_system->planets[i].gfx_space, &cur_system->planets[i].pos, 0, 0); gl_blitSprite(cur_system->planets[i].gfx_space, &cur_system->planets[i].pos, 0, 0, NULL);
} }
// Clean up the system. // Clean up the system.

View File

@ -115,7 +115,7 @@ static void weapon_render(const Weapon* w) {
// Get the sprite corresponding to the direction facing. // Get the sprite corresponding to the direction facing.
gl_getSpriteFromDir(&sx, &sy, w->outfit->gfx_space, w->solid->dir); gl_getSpriteFromDir(&sx, &sy, w->outfit->gfx_space, w->solid->dir);
gl_blitSprite(w->outfit->gfx_space, &w->solid->pos, sx, sy); gl_blitSprite(w->outfit->gfx_space, &w->solid->pos, sx, sy, NULL);
} }
// Update the weapon. // Update the weapon.