Atom888

https://stackoverflow.com/posts/70620450

Jan 7th, 2022 (edited)
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. class Something {
  2. private:
  3.     // Console window, console stream handles.
  4.     HDC    cwd;
  5.     HANDLE chd;
  6.     HWND   cwn;
  7.  
  8.     // ... //
  9.  
  10.     // Rendering
  11.     uint32_t* frontBuf;
  12.     uint32_t* backBuf;
  13.     size_t    gbufSize;
  14.  
  15.     // ... //
  16.  
  17. public:
  18.     // ... //
  19.  
  20.     // Intiailizes/prepares the application.
  21.     void Initialize() {
  22.         // get handles
  23.         cwd = GetDC(GetConsoleWindow());
  24.         chd = GetStdHandle(STD_OUTPUT_HANDLE);
  25.         cwn = GetConsoleWindow();
  26.  
  27.         // prepare for rendering
  28.         gbufSize = sizeof(uint32_t) * w * h;
  29.         backBuf  = (uint32_t*)malloc(gbufSize);
  30.         frontBuf = (uint32_t*)malloc(gbufSize);
  31.  
  32.         // ... //
  33.     }
  34.  
  35.     // ... //
  36.  
  37.     // Swaps front and back buffers and
  38.     // displays the new front buffer on the screen.
  39.     void GSwap() {
  40.         // swap pointers
  41.         uint32_t* frontTmp = frontBuf;
  42.         frontBuf = backBuf;
  43.         backBuf = frontTmp;
  44.  
  45.         // clear new back buffer
  46.         memset(backBuf, 0, gbufSize);
  47.  
  48.         // draw on screen
  49.         /* ??? */
  50.     }
  51.  
  52.     size_t GFlatten(int x, int y) {
  53.         return y * h + x;
  54.     }
  55.  
  56.     void GSetPixel(int x, int y, uint32_t color) {
  57.         backBuf[GFlatten(x, y)] = color;
  58.     }
  59.  
  60.     void GFillRect(int x, int y, int w, int h, uint32_t color) {
  61.         for (int ix = x; ix < x + w; ix++) {
  62.             for (int iy = y; iy < y + h; iy++) {
  63.                 GSetPixel(ix, iy, color);
  64.             }
  65.         }
  66.     }
  67.  
  68.     void GFillScreen(uint32_t color) {
  69.         memset(backBuf, color, gbufSize);
  70.     }
  71.  
  72. };
Add Comment
Please, Sign In to add comment