Advertisement
Guest User

Defines.h

a guest
Mar 30th, 2022
383
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.55 KB | None | 0 0
  1. #pragma once
  2. #include <fstream>
  3. #include <cassert>
  4.  
  5. struct BmpHeader {
  6.     char bitmapSignatureBytes[2] = { 'B', 'M' };
  7.     uint32_t sizeOfBitmapFile = 54 + 1920 * 1080 * 3;
  8.     uint32_t reservedBytes = 0;
  9.     uint32_t pixelDataOffset = 54;
  10.  
  11.     bool write_to_file(std::ofstream& file)
  12.     {
  13.         assert(file.is_open());
  14.  
  15.         if (file.is_open())
  16.         {
  17.             file.write(this->bitmapSignatureBytes, 2);
  18.             file.write((const char*)&this->sizeOfBitmapFile, sizeof(uint32_t));
  19.             file.write((const char*)&this->reservedBytes, sizeof(uint32_t));
  20.             file.write((const char*)&this->pixelDataOffset, sizeof(uint32_t));
  21.             return true;
  22.         }
  23.  
  24.         return false;
  25.     }
  26. } bmpHeader;
  27.  
  28. struct BmpInfoHeader {
  29.     uint32_t sizeOfThisHeader = 40;
  30.     int32_t width = 1920; // in pixels
  31.     int32_t height = 1080; // in pixels
  32.     uint16_t numberOfColorPlanes = 1; // must be 1
  33.     uint16_t colorDepth = 24;
  34.     uint32_t compressionMethod = 0;
  35.     uint32_t rawBitmapDataSize = 0; // generally ignored
  36.     int32_t horizontalResolution = 3780; // in pixel per meter
  37.     int32_t verticalResolution = 3780; // in pixel per meter
  38.     uint32_t colorTableEntries = 0;
  39.     uint32_t importantColors = 0;
  40.  
  41.     bool write_to_file(std::ofstream& file)
  42.     {
  43.         assert(file.is_open());
  44.  
  45.         if (file.is_open())
  46.         {
  47.             file.write((const char*)&this->sizeOfThisHeader, sizeof(uint32_t));
  48.             file.write((const char*)&this->width, sizeof(int32_t));
  49.             file.write((const char*)&this->height, sizeof(int32_t));
  50.             file.write((const char*)&this->numberOfColorPlanes, sizeof(uint16_t));
  51.             file.write((const char*)&this->colorDepth, sizeof(uint16_t));
  52.             file.write((const char*)&this->compressionMethod, sizeof(uint32_t));
  53.             file.write((const char*)&this->rawBitmapDataSize, sizeof(uint32_t));
  54.             file.write((const char*)&this->horizontalResolution, sizeof(int32_t));
  55.             file.write((const char*)&this->verticalResolution, sizeof(int32_t));
  56.             file.write((const char*)&this->colorTableEntries, sizeof(uint32_t));
  57.             file.write((const char*)&this->importantColors, sizeof(uint32_t));
  58.             return true;
  59.         }
  60.  
  61.         return false;
  62.     }
  63. } bmpInfoHeader;
  64.  
  65. struct Pixel {
  66.     uint8_t blue = 0x00;
  67.     uint8_t green = 0x00;
  68.     uint8_t red = 0x00;
  69.  
  70.     Pixel() = default;
  71.     Pixel(uint8_t _red, uint8_t _green, uint8_t _blue)
  72.         : red(_red), green(_green), blue(_blue) {}
  73.  
  74.     bool write_to_file(std::ofstream& file)
  75.     {
  76.         assert(file.is_open());
  77.  
  78.         if (file.is_open())
  79.         {
  80.             file.write((const char*)&this->blue, sizeof(uint8_t));
  81.             file.write((const char*)&this->green, sizeof(uint8_t));
  82.             file.write((const char*)&this->red, sizeof(uint8_t));
  83.             return true;
  84.         }
  85.         return false;
  86.     }
  87.  
  88.     bool read_file(std::ifstream& file)
  89.     {
  90.         assert(file.is_open());
  91.  
  92.         if (file.is_open())
  93.         {
  94.             file.read((char*)&this->blue, sizeof(uint8_t));
  95.             file.read((char*)&this->green, sizeof(uint8_t));
  96.             file.read((char*)&this->red, sizeof(uint8_t));
  97.  
  98.             return true;
  99.         }
  100.         return false;
  101.     }
  102. };
  103.  
  104. const int32_t canvas_width = bmpInfoHeader.width;
  105. const int32_t canvas_height = bmpInfoHeader.height;
  106. const int32_t viewport_width = 1;
  107. const int32_t viewport_height = 1;
  108. const int32_t projection_plane_z = 1;
  109.  
  110. #define BACKGROUND_COLOR {0.0f, 0.0f, 0.0f};
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement