New code snippets?
/* ------------------------------------------------------------------------- */
static void
text_generate_mesh(struct context_t* context, struct text_t* text)
{
const wchar_t* iterator;
GLfloat dist_between_chars;
GLfloat space_dist;
GLfloat x, y;
INDEX_DATA_TYPE base_index;
/* start base index at 0 */
base_index = 0;
/* distance between characters */
dist_between_chars = 3.0f / (GLfloat)window_width();
space_dist = 20.0f / (GLfloat)window_width();
/*
* If text is centered, figure out total width and set x coordinate
* accordingly. Otherwise just use x and y values passed in. */
if(text->is_centered)
{
x = 0;
for(iterator = text->string; *iterator; ++iterator)
{
struct char_info_t* info;
/* the space character requires some extra attention */
if(wcsncmp(iterator, L" ", 1) == 0)
{
x += space_dist;
continue;
}
/* lookup character info */
info = (struct char_info_t*)bstv_find(&text->group->char_info, (uint32_t)*iterator);
if(!info)
{
char buffer[sizeof(wchar_t)+1];
memcpy(buffer, iterator, sizeof(wchar_t));
buffer[sizeof(wchar_t)] = '\0';
llog(LOG_ERROR, context->game, PLUGIN_NAME, "Failed to look up character: \"%s\"", buffer);
continue;
}
/* advance */
x += info->width + dist_between_chars;
}
/* x is now the total width of the string in GL screen space. */
x = text->pos.x - (x / 2.0f);
y = text->pos.y;
}
else
{
x = text->pos.x;
y = text->pos.y;
}
/* generate new vertices and insert into text vertex buffer */
for(iterator = text->string; *iterator; ++iterator)
{
struct char_info_t* info;
struct vertex_quad_t* vertex;
/* the space character requires some extra attention */
if(wcsncmp(iterator, L" ", 1) == 0)
{
x += space_dist;
continue;
}
/* lookup character info */
info = (struct char_info_t*)bstv_find(&text->group->char_info, (uint32_t)*iterator);
if(!info)
{
char buffer[sizeof(wchar_t)+1];
memcpy(buffer, iterator, sizeof(wchar_t));
buffer[sizeof(wchar_t)] = '\0';
llog(LOG_ERROR, context->game, PLUGIN_NAME, "Failed to look up character: \"%s\"", buffer);
continue;
}
/* top left vertex */
vertex = (struct vertex_quad_t*)ordered_vector_push_emplace(&text->vertex_buffer);
vertex->position[0] = x;
vertex->position[1] = y - info->bearing_y;
vertex->tex_coord[0] = info->uv_left;
vertex->tex_coord[1] = info->uv_top;
/* top right vertex */
vertex = (struct vertex_quad_t*)ordered_vector_push_emplace(&text->vertex_buffer);
vertex->position[0] = x + info->width;
vertex->position[1] = y - info->bearing_y;
vertex->tex_coord[0] = info->uv_left + info->uv_width;
vertex->tex_coord[1] = info->uv_top;
/* bottom left vertex */
vertex = (struct vertex_quad_t*)ordered_vector_push_emplace(&text->vertex_buffer);
vertex->position[0] = x;
vertex->position[1] = y - info->bearing_y - info->height;
vertex->tex_coord[0] = info->uv_left;
vertex->tex_coord[1] = info->uv_top + info->uv_height;
/* bottom right vertex */
vertex = (struct vertex_quad_t*)ordered_vector_push_emplace(&text->vertex_buffer);
vertex->position[0] = x + info->width;
vertex->position[1] = y - info->bearing_y - info->height;
vertex->tex_coord[0] = info->uv_left + info->uv_width;
vertex->tex_coord[1] = info->uv_top + info->uv_height;
/* generate indices */
*(INDEX_DATA_TYPE*)ordered_vector_push_emplace(&text->index_buffer) = base_index + 0;
*(INDEX_DATA_TYPE*)ordered_vector_push_emplace(&text->index_buffer) = base_index + 2;
*(INDEX_DATA_TYPE*)ordered_vector_push_emplace(&text->index_buffer) = base_index + 1;
*(INDEX_DATA_TYPE*)ordered_vector_push_emplace(&text->index_buffer) = base_index + 1;
*(INDEX_DATA_TYPE*)ordered_vector_push_emplace(&text->index_buffer) = base_index + 2;
*(INDEX_DATA_TYPE*)ordered_vector_push_emplace(&text->index_buffer) = base_index + 3;
x += info->width + dist_between_chars;
base_index += 4;
}
/* let text group about mesh update */
text_group_inform_updated_text_object(text->group);
}
[EDIT] Oh god, it's one of
those snippets. I hate these because of what happens when you double click on the code.
\"Windows 10 doesn\'t only include spyware, it is
designed as spyware\" --
Gaius Publius, The Big Picture RT Interview
\"[...] we will access, disclose and
preserve personal data, including your content (such as the content of your emails, other
private communications or files in
private folders), when we have a good faith belief that doing so is necessary\" --
Windows 10 Privacy Statement