예제 #1
0
파일: lakka.c 프로젝트: Mbcpro/RetroArch
void lakka_draw_background(void)
{
   GLfloat background_color[] = {
      0.1, 0.74, 0.61, global_alpha,
      0.1, 0.74, 0.61, global_alpha,
      0.1, 0.74, 0.61, global_alpha,
      0.1, 0.74, 0.61, global_alpha,
   };
   gl_t *gl = (gl_t*)driver.video_data;

   if (!gl)
      return;

   glEnable(GL_BLEND);

   gl->coords.tex_coord = gl->tex_coords;
   gl->coords.color = background_color;
   glBindTexture(GL_TEXTURE_2D, 0);

   if (gl->shader && gl->shader->use)
      gl->shader->use(gl, GL_SHADER_STOCK_BLEND);
   gl_shader_set_coords(gl, &gl->coords, &gl->mvp_no_rot);

   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   glDisable(GL_BLEND);
   gl->coords.color = gl->white_color_ptr;
}
예제 #2
0
파일: ps3_ctx.c 프로젝트: Jalle19/RetroArch
static void gfx_ctx_rmenu_frame(void *data)
{
   gl_t *gl = (gl_t*)data;

   gl_shader_use(gl, RARCH_CG_MENU_SHADER_INDEX);
   gl_set_viewport(gl, gl->win_width, gl->win_height, true, false);

   if (gl->shader)
   {
      gl->shader->set_params(gl->win_width, gl->win_height, 
            gl->win_width, gl->win_height, 
            gl->win_width, gl->win_height, 
            g_extern.frame_count, NULL, NULL, NULL, 0);
   }

   glActiveTexture(GL_TEXTURE0);
   glBindTexture(GL_TEXTURE_2D, menu_texture_id);

   gl->coords.vertex = vertexes_flipped;

   gl_shader_set_coords(gl, &gl->coords, &gl->mvp);
   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); 

   glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
   gl_set_viewport(gl, gl->win_width, gl->win_height, false, true);
}
예제 #3
0
void lakka_draw_background(void)
{
   GLfloat color[] = {
      1.0f, 1.0f, 1.0f, global_alpha,
      1.0f, 1.0f, 1.0f, global_alpha,
      1.0f, 1.0f, 1.0f, global_alpha,
      1.0f, 1.0f, 1.0f, global_alpha,
   };

   gl_t *gl = (gl_t*)driver.video_data;
   if (!gl)
      return;

   //glViewport(gl->win_width-1920, 0, 1920, 1080);
   glViewport(0, 0, gl->win_width, gl->win_height);

   glEnable(GL_BLEND);

   gl->coords.vertex = vertex;
   gl->coords.tex_coord = tex_coord;
   gl->coords.color = color;
   glBindTexture(GL_TEXTURE_2D, textures[TEXTURE_BG].id);

   if (gl->shader && gl->shader->use)
      gl->shader->use(gl, GL_SHADER_STOCK_BLEND);

   gl->coords.vertices = 4;
   gl_shader_set_coords(gl, &gl->coords, &gl->mvp_no_rot);

   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   glDisable(GL_BLEND);
   gl->coords.color = gl->white_color_ptr;
}
예제 #4
0
void lakka_draw_icon(GLuint texture, float x, float y, float alpha, float rotation, float scale)
{
   GLfloat color[] = {
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
      1.0f, 1.0f, 1.0f, alpha,
   };

   static const GLfloat vtest[] = {
      0, 0,
      1, 0,
      0, 1,
      1, 1
   };

   gl_t *gl = (gl_t*)driver.video_data;

   if (!gl)
      return;
   
   if (alpha > global_alpha)
      alpha = global_alpha;

   glViewport(x, gl->win_height - y, dim, dim);

   glEnable(GL_BLEND);

   gl->coords.vertex = vtest;
   gl->coords.tex_coord = vtest;
   gl->coords.color = color;
   glBindTexture(GL_TEXTURE_2D, texture);

   if (gl->shader && gl->shader->use)
      gl->shader->use(gl, GL_SHADER_STOCK_BLEND);

   math_matrix mymat;

   math_matrix mrot;
   matrix_rotate_z(&mrot, rotation);
   matrix_multiply(&mymat, &mrot, &gl->mvp_no_rot);

   math_matrix mscal;
   matrix_scale(&mscal, scale, scale, 1);
   matrix_multiply(&mymat, &mscal, &mymat);

   gl->coords.vertices = 4;
   gl_shader_set_coords(gl, &gl->coords, &mymat);

   glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
   glDisable(GL_BLEND);

   gl->coords.vertex = gl->vertex_ptr;
   gl->coords.tex_coord = gl->tex_coords;
   gl->coords.color = gl->white_color_ptr;
}
예제 #5
0
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);
}
예제 #6
0
파일: lakka.c 프로젝트: Mbcpro/RetroArch
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);
}
예제 #7
0
static void render_message(gl_raster_t *font, const char *msg, GLfloat scale, const GLfloat color[4], GLfloat pos_x, GLfloat pos_y)
{
   unsigned i;
   gl_t *gl = font->gl;

   glBindTexture(GL_TEXTURE_2D, font->tex);

#define MAX_MSG_LEN_CHUNK 64
   GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
   GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK]; 
   GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];

   unsigned msg_len_full = strlen(msg);
   unsigned msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK);

   int x = roundf(pos_x * gl->vp.width);
   int y = roundf(pos_y * gl->vp.height);
   int delta_x = 0;
   int delta_y = 0;

   float inv_tex_size_x = 1.0f / font->tex_width;
   float inv_tex_size_y = 1.0f / font->tex_height;
   float inv_win_width  = 1.0f / font->gl->vp.width;
   float inv_win_height = 1.0f / font->gl->vp.height;

   while (msg_len_full)
   {
      // Rebind shaders so attrib cache gets reset.
      if (gl->shader && gl->shader->use)
         gl->shader->use(gl, GL_SHADER_STOCK_BLEND);

      for (i = 0; i < msg_len; i++)
      {
         const struct font_glyph *gly = font->font_driver->get_glyph(font->font_data, (uint8_t)msg[i]);
         if (!gly)
            gly = font->font_driver->get_glyph(font->font_data, '?'); // Do something smarter here ...
         if (!gly)
            continue;

         int off_x  = gly->draw_offset_x;
         int off_y  = gly->draw_offset_y;
         int tex_x  = gly->atlas_offset_x;
         int tex_y  = gly->atlas_offset_y;
         int width  = gly->width;
         int height = gly->height;

         emit(0, 0, 1); // Bottom-left
         emit(1, 1, 1); // Bottom-right
         emit(2, 0, 0); // Top-left

         emit(3, 1, 0); // Top-right
         emit(4, 0, 0); // Top-left
         emit(5, 1, 1); // Bottom-right
#undef emit

         delta_x += gly->advance_x;
         delta_y -= gly->advance_y;
      }

      gl->coords.tex_coord = font_tex_coords;
      gl->coords.vertex    = font_vertex;
      gl->coords.color     = font_color;
      gl->coords.vertices  = 6 * msg_len;
      gl_shader_set_coords(gl, &gl->coords, &gl->mvp_no_rot);
      glDrawArrays(GL_TRIANGLES, 0, 6 * msg_len);

      msg_len_full -= msg_len;
      msg += msg_len;
      msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK);
   }

   // 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;
   gl->coords.vertices  = 4;
   glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]);
}