Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define char_width = 8
- #define char_height = 8
- // buffor for the font, load it from file or something
- // byte 0 = no pixel, byte 1 (or anything really) pixel is black
- char* font[94 * char_width * char_height];
- #define window_char_width 80
- #define window_char_height 25
- // buffer for your window, write here to display your chars
- char* buffer[window_char_width * window_char_height];
- // pointer to your framebuffer, when you call SDL
- // to create a window, it will give you a framebuffer, you can
- // draw to it yourself instead of using SDL functions.
- char* framebuffer; // = SDL_GetWindow()... or smh (writing from my head)
- // pixel resolution of your window
- #define window_w = 80*8
- #define window_h = 25*8
- // code that will blit one char at position X / Y
- // of your real SDL window (pixel position, not char position)
- void BlitOneChar(char c, int x, int y)
- {
- // ascii has 127 chars, but our font starts from space (32)
- c-= 32;
- if (!c)
- {
- // space doesn't have graphics so dont bother drawing
- return;
- }
- // calc the pointer to the char
- char* charPtr = (c * char_width * char_height) + font;
- // calc the pointer to framebuffer
- char* framePtr = (window_w * y) + x + framebuffer;
- for (int yloop = 0; yloop < 8; yloop++)
- {
- for (int xloop = 0; xloop < 8; xloop++)
- {
- framebuffer[xloop] = charPtr[xloop];
- }
- // advance char ptr and framebuffer ptr
- // to next line
- charPtr += char_width;
- framebuffer += window_w;
- }
- }
- // blit all chars
- void BlitTerminal()
- {
- int pixelY = 0;
- int pixelX = 0;
- char bufferPtr = buffer;
- for (int y = 0; y < window_char_height * char_height; y += char_height)
- {
- for (int x = 0; x < window_char_width * char_width; x += char_width)
- {
- BlitOneChar(*bufferPtr++, x, y);
- }
- }
- }
- // your generic sdl code that will call blitTermianl on
- // every frame and do SDL_Flip()
Advertisement
Add Comment
Please, Sign In to add comment