SHARE
TWEET

Untitled

a guest May 25th, 2019 54 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include "SFML/Graphics.hpp"
  4.  
  5. #include "dds.hpp"
  6.  
  7. #define FALCON_TEXTURE_SHM "FalconTexturesSharedMemoryArea"
  8.  
  9.  
  10. int main(int argc, char** argv) {
  11.   constexpr BOOL  inherited     = FALSE;
  12.   constexpr DWORD access_rights = FILE_MAP_READ;
  13.   constexpr sf::Uint8 offset = sizeof(DirectX::DDS_MAGIC) + sizeof(DirectX::DDS_HEADER);
  14.  
  15.   void* texture_data = NULL;
  16.   sf::Uint8* texture_buffer = NULL;
  17.   HANDLE textureDataMemHandle = NULL;
  18.   std::size_t texture_size = 1200 * 1200 * 4; // width * height * 4 byte per pixel (RGBA);
  19.   textureDataMemHandle = OpenFileMapping(access_rights,
  20.                                          inherited,
  21.                                          FALCON_TEXTURE_SHM);
  22.  
  23.   if (textureDataMemHandle == NULL) {
  24.     std::cout << "Unable to open file. Is Falcon Running?" << std::endl;
  25.     return 1;
  26.   }
  27.  
  28.   texture_data = (void*) MapViewOfFile(textureDataMemHandle,
  29.                                        access_rights,
  30.                                        0, 0, 0);
  31.  
  32.   sf::Uint8* dds_texture = (sf::Uint8*) texture_data + offset;
  33.   texture_buffer = new sf::Uint8[texture_size];
  34.   for(unsigned int i = 0; i < texture_size; i += 4) {
  35.     // changes from BGRA to RGBA
  36.     texture_buffer[i]     = dds_texture[i + 2]; // R
  37.     texture_buffer[i + 1] = dds_texture[i + 1]; // G
  38.     texture_buffer[i + 2] = dds_texture[i]; // B
  39.     texture_buffer[i + 3] = 0xFF; // dds_texture[i]; // A 0xFF
  40.   }
  41.  
  42.   sf::Texture tex;
  43.   tex.create(1200, 1200);
  44.   tex.update(texture_buffer);
  45.   bool result = tex.copyToImage().saveToFile("texture.png");
  46.   std::cout << "Save Result: " << result << std::endl;
  47.   std::cout << "offset dim: " << (unsigned int) offset << std::endl;
  48.   delete texture_buffer;
  49.   return 0;
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top