From 952f1c44fe4c2c4a48861ac2c2059c6130be0508 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Wed, 6 Feb 2019 18:39:53 +0100 Subject: [PATCH] minor fixes to color handling --- basegraph.cpp | 3 +-- hyper.h | 2 +- screenshot.cpp | 2 +- shaders.cpp | 11 +++-------- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/basegraph.cpp b/basegraph.cpp index e46cb230..043a8f71 100644 --- a/basegraph.cpp +++ b/basegraph.cpp @@ -306,8 +306,7 @@ void setGLProjection(color_t col) { DEBB(DF_GRAPH, (debugfile,"setGLProjection\n")); GLERR("pre_setGLProjection"); - unsigned char *c = (unsigned char*) (&col); - glClearColor(c[2] / 255.0, c[1] / 255.0, c[0]/255.0, 1); + glClearColor(part(col, 2) / 255.0, part(col, 1) / 255.0, part(col, 0) / 255.0, 1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); GLERR("setGLProjection #1"); diff --git a/hyper.h b/hyper.h index 923239da..20266791 100644 --- a/hyper.h +++ b/hyper.h @@ -3716,7 +3716,7 @@ namespace glhr { void set_depthtest(bool b); glmatrix translate(ld x, ld y, ld z); - void color2(color_t color, ld part = 1); + void color2(color_t color, ld scale = 1); void be_nontextured(shader_projection sp = new_shader_projection); void be_textured(shader_projection sp = new_shader_projection); void set_modelview(const glmatrix& m); diff --git a/screenshot.cpp b/screenshot.cpp index 1eabb294..7504676e 100644 --- a/screenshot.cpp +++ b/screenshot.cpp @@ -53,7 +53,7 @@ namespace svg { } } - char* stylestr(unsigned int fill, unsigned int stroke, ld width=1) { + char* stylestr(color_t fill, color_t stroke, ld width=1) { fixgamma(fill); fixgamma(stroke); static char buf[600]; diff --git a/shaders.cpp b/shaders.cpp index fff21bfd..e1797e94 100644 --- a/shaders.cpp +++ b/shaders.cpp @@ -340,10 +340,10 @@ void id_modelview() { #endif -void color2(color_t color, ld part) { +void color2(color_t color, ld scale) { GLfloat cols[4]; for(int i=0; i<4; i++) - cols[i] = (color >> ((3-i) * 8) & 0xff) / 255.0 * part; + cols[i] = part(color, 3-i) / 255.0 * scale; #if CAP_SHADER // glUniform4fv(current->uFog, 4, cols); if(!current) return; @@ -354,12 +354,7 @@ void color2(color_t color, ld part) { } void colorClear(color_t color) { - unsigned char *c = (unsigned char*) (&color); -#if SDL_BYTEORDER == SDL_BIG_ENDIAN - glClearColor(c[0] / 255.0, c[1] / 255.0, c[2]/255.0, c[3] / 255.0); -#else - glClearColor(c[3] / 255.0, c[2] / 255.0, c[1]/255.0, c[0] / 255.0); -#endif + glClearColor(part(color, 3) / 255.0, part(color, 2) / 255.0, part(color, 1) / 255.0, part(color, 0) / 255.0); } void be_nontextured(shader_projection sp) { switch_mode(gmColored, sp); }