diff --git a/conf/config_file.c b/conf/config_file.c index d6bf82fa92..8a6b5add6c 100644 --- a/conf/config_file.c +++ b/conf/config_file.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "strl.h" struct entry_list @@ -216,8 +217,15 @@ bool config_get_int(config_file_t *conf, const char *key, int *in) { if (strcmp(key, list->key) == 0) { - *in = strtol(list->value, NULL, 0); - return true; + errno = 0; + int val = strtol(list->value, NULL, 0); + if (errno == 0) + { + *in = val; + return true; + } + return + false; } list = list->next; } @@ -232,8 +240,15 @@ bool config_get_hex(config_file_t *conf, const char *key, unsigned *in) { if (strcmp(key, list->key) == 0) { - *in = strtol(list->value, NULL, 16); - return true; + errno = 0; + unsigned val = strtoul(list->value, NULL, 16); + if (errno == 0) + { + *in = val; + return true; + } + else + return false; } list = list->next; } diff --git a/config.def.h b/config.def.h index 190e41bded..63175e98a9 100644 --- a/config.def.h +++ b/config.def.h @@ -150,6 +150,8 @@ static const unsigned font_size = 48; // Offset for where messages will be placed on-screen. Values are in range [0.0, 1.0]. static const float message_pos_offset_x = 0.05; static const float message_pos_offset_y = 0.05; +// Color of the message. +static const uint32_t message_color = 0xffffff; // RGB hex value. // Render-to-texture before rendering to screen (multi-pass shaders) static const bool render_to_texture = false; diff --git a/general.h b/general.h index a033b11e18..032d43e3d9 100644 --- a/general.h +++ b/general.h @@ -98,6 +98,9 @@ struct settings unsigned font_size; float msg_pos_x; float msg_pos_y; + float msg_color_r; + float msg_color_g; + float msg_color_b; bool force_16bit; bool disable_composition; diff --git a/gfx/gl.c b/gfx/gl.c index e385928d30..17a404d5f5 100644 --- a/gfx/gl.c +++ b/gfx/gl.c @@ -622,6 +622,7 @@ static void gl_render_msg(gl_t *gl, const char *msg) // Need blending. // Using fixed function pipeline here since we cannot guarantee presence of shaders (would be kinda overkill anyways). glEnable(GL_BLEND); + glColor4f(g_settings.video.msg_color_r, g_settings.video.msg_color_g, g_settings.video.msg_color_b, 1); struct font_output_list out; font_renderer_msg(gl->font, msg, &out); @@ -654,10 +655,13 @@ static void gl_render_msg(gl_t *gl, const char *msg) } font_renderer_free_output(&out); + glColor4f(1, 1, 1, 1); + // Go back to old rendering path. glTexCoordPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), gl->tex_coords); glVertexPointer(2, GL_FLOAT, 2 * sizeof(GLfloat), vertexes_flipped); glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); + glDisable(GL_BLEND); #endif } diff --git a/gfx/shader_cg.c b/gfx/shader_cg.c index 8a12fdd680..2a3a716ce6 100644 --- a/gfx/shader_cg.c +++ b/gfx/shader_cg.c @@ -37,20 +37,23 @@ static const char* stock_cg_program = "(" " float4 position : POSITION," " float2 texCoord : TEXCOORD0," + " float4 color : COLOR," "" " uniform float4x4 modelViewProj," "" " out float4 oPosition : POSITION," - " out float2 otexCoord : TEXCOORD0" + " out float2 otexCoord : TEXCOORD0," + " out float4 oColor : COLOR" ")" "{" " oPosition = mul(modelViewProj, position);" " otexCoord = texCoord;" + " oColor = color;" "}" "" - "float4 main_fragment(float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR" + "float4 main_fragment(in float4 color : COLOR, float2 tex : TEXCOORD0, uniform sampler2D s0 : TEXUNIT0) : COLOR" "{" - " return tex2D(s0, tex);" + " return color * tex2D(s0, tex);" "}"; #ifdef SSNES_CG_DEBUG diff --git a/settings.c b/settings.c index ae7643e7ad..e9416436ff 100644 --- a/settings.c +++ b/settings.c @@ -135,6 +135,10 @@ static void set_defaults(void) g_settings.video.font_size = font_size; g_settings.video.msg_pos_x = message_pos_offset_x; g_settings.video.msg_pos_y = message_pos_offset_y; + + g_settings.video.msg_color_r = ((message_color >> 16) & 0xff) / 255.0f; + g_settings.video.msg_color_g = ((message_color >> 8) & 0xff) / 255.0f; + g_settings.video.msg_color_b = ((message_color >> 0) & 0xff) / 255.0f; #endif #if defined(HAVE_CG) || defined(HAVE_XML) @@ -322,6 +326,14 @@ static void parse_config_file(void) CONFIG_GET_INT(video.font_size, "video_font_size"); CONFIG_GET_DOUBLE(video.msg_pos_x, "video_message_pos_x"); CONFIG_GET_DOUBLE(video.msg_pos_y, "video_message_pos_y"); + + unsigned msg_color; + if (config_get_hex(conf, "video_message_color", &msg_color)) + { + g_settings.video.msg_color_r = ((msg_color >> 16) & 0xff) / 255.0f; + g_settings.video.msg_color_g = ((msg_color >> 8) & 0xff) / 255.0f; + g_settings.video.msg_color_b = ((msg_color >> 0) & 0xff) / 255.0f; + } #endif CONFIG_GET_BOOL(video.hires_record, "video_hires_record"); diff --git a/ssnes.cfg b/ssnes.cfg index bbcbd3191b..847bda5634 100644 --- a/ssnes.cfg +++ b/ssnes.cfg @@ -93,6 +93,10 @@ # video_message_pos_x = 0.05 # video_message_pox_y = 0.05 +# Color for message. The value is treated as a hexadecimal value. +# It is a regular RGB hex number, i.e. red is "ff0000". +# video_message_color = ffffff + #### Audio # Enable audio.