static void gl_set_rotation(void *data, unsigned rotation) { struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; gl_t *gl = (gl_t*)driver.video_data; gl->rotation = 90 * rotation; gl_set_projection(gl, &ortho, true); }
void gl_set_viewport(gl_t *gl, unsigned width, unsigned height, bool force_full, bool allow_rotate) { unsigned x = 0, y = 0; struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; if (gl->keep_aspect && !force_full) { float desired_aspect = g_settings.video.aspect_ratio; float device_aspect = (float)width / height; float delta; #ifdef RARCH_CONSOLE if (g_console.aspect_ratio_index == ASPECT_RATIO_CUSTOM) { x = g_console.viewports.custom_vp.x; y = g_console.viewports.custom_vp.y; width = g_console.viewports.custom_vp.width; height = g_console.viewports.custom_vp.height; } else #endif { if (fabs(device_aspect - desired_aspect) < 0.0001) { // If the aspect ratios of screen and desired aspect ratio are sufficiently equal (floating point stuff), // assume they are actually equal. } else if (device_aspect > desired_aspect) { delta = (desired_aspect / device_aspect - 1.0) / 2.0 + 0.5; x = (unsigned)(width * (0.5 - delta)); width = (unsigned)(2.0 * width * delta); } else { delta = (device_aspect / desired_aspect - 1.0) / 2.0 + 0.5; y = (unsigned)(height * (0.5 - delta)); height = (unsigned)(2.0 * height * delta); } } } glViewport(x, y, width, height); gl_set_projection(gl, &ortho, allow_rotate); gl->vp_width = width; gl->vp_height = height; // Set last backbuffer viewport. if (!force_full) { gl->vp_out_width = width; gl->vp_out_height = height; } //RARCH_LOG("Setting viewport @ %ux%u\n", width, height); }
static void setup_font(void *data, const char *msg, GLfloat scale, GLfloat pos_x, GLfloat pos_y) { gl_t *gl = (gl_t*)data; if (!gl->font) return; gl_shader_use(gl, 0); gl_set_viewport(gl, gl->win_width, gl->win_height, false, false); glEnable(GL_BLEND); GLfloat font_vertex[8]; GLfloat font_vertex_dark[8]; GLfloat font_tex_coords[8]; glBindTexture(GL_TEXTURE_2D, gl->font_tex); gl->coords.tex_coord = font_tex_coords; struct font_output_list out; // If we get the same message, there's obviously no need to render fonts again ... if (strcmp(gl->font_last_msg, msg) != 0) { gl->font_driver->render_msg(gl->font, msg, &out); struct font_output *head = out.head; struct font_rect geom; calculate_msg_geometry(head, &geom); adjust_power_of_two(gl, &geom); blit_fonts(gl, head, &geom); gl->font_driver->free_output(gl->font, &out); strlcpy(gl->font_last_msg, msg, sizeof(gl->font_last_msg)); gl->font_last_width = geom.width; gl->font_last_height = geom.height; } calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords, scale, pos_x, pos_y); gl->coords.vertex = font_vertex_dark; gl->coords.color = gl->font_color_dark; gl_shader_set_coords(gl, &gl->coords, &gl->mvp); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); gl->coords.vertex = font_vertex; gl->coords.color = gl->font_color; gl_shader_set_coords(gl, &gl->coords, &gl->mvp); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // Post - Go back to old rendering path. gl->coords.vertex = vertexes_flipped; gl->coords.tex_coord = gl->tex_coords; gl->coords.color = white_color; glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glDisable(GL_BLEND); struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; gl_set_projection(gl, &ortho, true); }
static void lakka_draw_text(struct font_output_list *out, float x, float y, float scale, float alpha) { int i; struct font_output *head; struct font_rect geom; struct gl_ortho ortho = {0, 1, 0, 1, -1, 1}; gl_t *gl = (gl_t*)driver.video_data; if (alpha > global_alpha) alpha = global_alpha; if (!font || !gl || !out) return; for (i = 0; i < 4; i++) { font_color[4 * i + 0] = 1.0; font_color[4 * i + 1] = 1.0; font_color[4 * i + 2] = 1.0; font_color[4 * i + 3] = alpha; } if (gl->shader && gl->shader->use) gl->shader->use(gl, GL_SHADER_STOCK_BLEND); gl_set_viewport(gl, gl->win_width, gl->win_height, true, false); glEnable(GL_BLEND); GLfloat font_vertex[8]; GLfloat font_vertex_dark[8]; GLfloat font_tex_coords[8]; glBindTexture(GL_TEXTURE_2D, font_tex); gl->coords.tex_coord = font_tex_coords; head = (struct font_output*)out->head; calculate_msg_geometry(head, &geom); adjust_power_of_two(gl, &geom); blit_fonts(gl, head, &geom); font_last_width = geom.width; font_last_height = geom.height; calculate_font_coords(gl, font_vertex, font_vertex_dark, font_tex_coords, scale, x / gl->win_width, (gl->win_height - y) / gl->win_height); gl->coords.vertex = font_vertex; gl->coords.color = font_color; gl_shader_set_coords(gl, &gl->coords, &gl->mvp); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); // Post - Go back to old rendering path. gl->coords.vertex = gl->vertex_ptr; gl->coords.tex_coord = gl->tex_coords; gl->coords.color = gl->white_color_ptr; glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_MAIN].id); glDisable(GL_BLEND); gl_set_projection(gl, &ortho, true); }