Skip to content

Commit

Permalink
Add coloring to fonts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Themaister committed Sep 5, 2011
1 parent 407ad94 commit 0823d72
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
23 changes: 19 additions & 4 deletions conf/config_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#include "strl.h"

struct entry_list
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions general.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions gfx/gl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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
}
Expand Down
9 changes: 6 additions & 3 deletions gfx/shader_cg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 4 additions & 0 deletions ssnes.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0823d72

Please sign in to comment.