Guest User

Untitled

a guest
Aug 8th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.00 KB | None | 0 0
  1. #define char_width = 8
  2. #define char_height = 8
  3.  
  4. // buffor for the font, load it from file or something
  5. // byte 0 = no pixel, byte 1 (or anything really) pixel is black
  6. char* font[94 * char_width * char_height];
  7.  
  8. #define window_char_width 80
  9. #define window_char_height 25
  10.  
  11. // buffer for your window, write here to display your chars
  12. char* buffer[window_char_width * window_char_height];
  13.  
  14. // pointer to your framebuffer, when you call SDL
  15. // to create a window, it will give you a framebuffer, you can
  16. // draw to it yourself instead of using SDL functions.
  17. char* framebuffer; // = SDL_GetWindow()... or smh (writing from my head)
  18.  
  19. // pixel resolution of your window
  20. #define window_w = 80*8
  21. #define window_h = 25*8
  22. // code that will blit one char at position X / Y
  23. // of your real SDL window (pixel position, not char position)
  24.  
  25. void BlitOneChar(char c, int x, int y)
  26. {
  27.     // ascii has 127 chars, but our font starts from space (32)
  28.     c-= 32;
  29.     if (!c)
  30.     {
  31.         // space doesn't have graphics so dont bother drawing
  32.         return;
  33.     }
  34.     // calc the pointer to the char
  35.     char* charPtr = (c * char_width * char_height) + font;
  36.     // calc the pointer to framebuffer
  37.     char* framePtr = (window_w * y) + x + framebuffer;
  38.     for (int yloop = 0; yloop < 8; yloop++)
  39.     {
  40.         for (int xloop = 0; xloop < 8; xloop++)
  41.         {
  42.             framebuffer[xloop] = charPtr[xloop];
  43.         }
  44.         // advance char ptr and framebuffer ptr
  45.         // to next line
  46.         charPtr += char_width;
  47.         framebuffer += window_w;
  48.     }
  49. }
  50.  
  51. // blit all chars
  52.  
  53. void BlitTerminal()
  54. {
  55.     int pixelY = 0;
  56.     int pixelX = 0;
  57.     char bufferPtr = buffer;
  58.     for (int y = 0; y < window_char_height * char_height; y += char_height)
  59.     {
  60.         for (int x = 0; x < window_char_width * char_width; x += char_width)
  61.         {
  62.             BlitOneChar(*bufferPtr++, x, y);
  63.         }
  64.     }
  65. }
  66.  
  67. // your generic sdl code that will call blitTermianl on
  68. // every frame and do SDL_Flip()
Advertisement
Add Comment
Please, Sign In to add comment