3
0

FontTexture_Windows.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #if !defined(USE_NULLFONT_ALWAYS)
  9. #include <AtomLyIntegration/AtomFont/FontTexture.h>
  10. //-------------------------------------------------------------------------------------------------
  11. int AZ::FontTexture::WriteToFile(const AZStd::string& fileName)
  12. {
  13. AZ::IO::FileIOStream outputFile(fileName.c_str(), AZ::IO::OpenMode::ModeWrite | AZ::IO::OpenMode::ModeBinary);
  14. if (!outputFile.IsOpen())
  15. {
  16. return 0;
  17. }
  18. BITMAPFILEHEADER pHeader;
  19. BITMAPINFOHEADER pInfoHeader;
  20. memset(&pHeader, 0, sizeof(BITMAPFILEHEADER));
  21. memset(&pInfoHeader, 0, sizeof(BITMAPINFOHEADER));
  22. pHeader.bfType = 0x4D42;
  23. pHeader.bfSize = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) + m_width * m_height * 3;
  24. pHeader.bfOffBits = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER);
  25. pInfoHeader.biSize = sizeof(BITMAPINFOHEADER);
  26. pInfoHeader.biWidth = m_width;
  27. pInfoHeader.biHeight = m_height;
  28. pInfoHeader.biPlanes = 1;
  29. pInfoHeader.biBitCount = 24;
  30. pInfoHeader.biCompression = 0;
  31. pInfoHeader.biSizeImage = m_width * m_height * 3;
  32. outputFile.Write(sizeof(BITMAPFILEHEADER), &pHeader);
  33. outputFile.Write(sizeof(BITMAPINFOHEADER), &pInfoHeader);
  34. unsigned char cRGB[3];
  35. for (int i = m_height - 1; i >= 0; i--)
  36. {
  37. for (int j = 0; j < m_width; j++)
  38. {
  39. cRGB[0] = m_buffer[(i * m_width) + j];
  40. cRGB[1] = *cRGB;
  41. cRGB[2] = *cRGB;
  42. outputFile.Write(3, cRGB);
  43. }
  44. }
  45. return 1;
  46. }
  47. #endif