Advertisement
xerpi

tinyfont gu copy

Oct 5th, 2013
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.64 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2013, xerpi
  3. */
  4.  
  5.  
  6. #include "tinyfont.h"
  7. #include <pspgu.h>
  8. #include <psputils.h>
  9. #include <stdarg.h>
  10. #include <string.h>
  11. #include <stdio.h>
  12.  
  13. extern const char vincent_font_data[];
  14. static Vertex3S __attribute__((aligned(16))) _tinyfont_static_vertices[8 * 8];
  15. static void *_tinyfont_framebuffer = NULL;
  16.  
  17. static void _tinyfont_draw_gu_char(int x, int y, unsigned int color, char c)
  18. {
  19.     if(c == ' ' || x > 480 || y > 272 || x < 0 || y < 0) return;
  20.     int offset_pos = c * 8;
  21.    
  22.     int i, j, b, count = 0;
  23.     for(i = 0; i < 8; i++) {
  24.         b = vincent_font_data[offset_pos + i];
  25.         for(j = 0; j < 8; j++) {
  26.             if(b & (1<<j)) {
  27.                 _tinyfont_static_vertices[count] = (Vertex3S){(short)(x+(7-j)), (short)(y+i), 0};
  28.                 ++count;
  29.             }
  30.         }
  31.     }
  32.     Vertex3S *vertices = sceGuGetMemory(count * sizeof(Vertex3S));
  33.     for(i = 0; i < count; i++) {
  34.         vertices[i] = _tinyfont_static_vertices[i];
  35.     }
  36.     sceGuDrawArray(GU_POINTS, GU_VERTEX_16BIT|GU_TRANSFORM_2D, count, 0, vertices);
  37. }
  38.  
  39.  
  40. static void _tinyfont_draw_copy_char(int x, int y, unsigned int color, char c)
  41. {
  42.     if(c == ' ' || x > 480 || y > 272 || x < 0 || y < 0) return;
  43.     int offset_pos = c * 8;
  44.    
  45.     unsigned int __attribute__((aligned(16))) glyph[8*8];
  46.     int l;
  47.     for(l = 0;  l < 8*8; ++l)
  48.         glyph[l] = 0;
  49.    
  50.     int i, j, b;
  51.     for(i = 0; i < 8; i++) {
  52.         b = vincent_font_data[offset_pos + i];
  53.         for(j = 0; j < 8; j++) {
  54.             if(b & (1<<j)) {
  55.                 glyph[(7-j) + i*8] = color;
  56.             }
  57.         }
  58.     }
  59.    
  60.     sceKernelDcacheWritebackRange(glyph, 8*8 * sizeof(unsigned int));
  61.     sceGuCopyImage(GU_PSM_8888,0,0,8,8,8,glyph,x,y,512,(void*)(0x04000000+(u32)_tinyfont_framebuffer));
  62. }
  63.  
  64.  
  65. void tinyfont_set_framebuffer(void *framebuffer)
  66. {
  67.     _tinyfont_framebuffer = framebuffer;
  68. }
  69.  
  70. void tinyfont_draw_char(int x, int y, unsigned int color, char c)
  71. {
  72.     //sceGuColor(color);
  73.     //_tinyfont_draw_gu_char(x, y, color, c);
  74.     _tinyfont_draw_texture_char(x, y, color, c);
  75. }
  76.  
  77. void tinyfont_draw_string(int x, int y, unsigned int color, const char *string)
  78. {
  79.     if(string == NULL) return;
  80.     int startx = x;
  81.     const char *s = string;
  82.     //sceGuColor(color);
  83.     while(*s) {
  84.         if(*s == '\n') {
  85.             x = startx;
  86.             y+=8;
  87.         } else if(*s == '\t') {
  88.             x+=8*4;
  89.         } else {
  90.             tinyfont_draw_char(x, y, color, *s);
  91.             x+=8;
  92.         }
  93.         ++s;
  94.     }
  95. }
  96.  
  97. void tinyfont_draw_stringf(int x, int y, unsigned int color, const char *s, ...)
  98. {
  99.     char buffer[256];
  100.     va_list args;
  101.     va_start(args, s);
  102.     vsnprintf(buffer, 256, s, args);
  103.     tinyfont_draw_string(x, y, color, buffer);
  104.     va_end(args);
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement