Add coloring to fonts.

This commit is contained in:
Themaister 2011-09-05 17:00:28 +02:00
parent 407ad94f58
commit 0823d72dee
7 changed files with 50 additions and 7 deletions

View File

@ -21,6 +21,7 @@
#include <string.h>
#include <stdio.h>
#include <ctype.h>
#include <errno.h>
#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;
}

View File

@ -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;

View File

@ -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;

View File

@ -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
}

View File

@ -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

View File

@ -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");

View File

@ -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.