Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <Windows.h>
- #include "SFML/Graphics.hpp"
- #include "dds.hpp"
- #define FALCON_TEXTURE_SHM "FalconTexturesSharedMemoryArea"
- int main(int argc, char** argv) {
- constexpr BOOL inherited = FALSE;
- constexpr DWORD access_rights = FILE_MAP_READ;
- constexpr sf::Uint8 offset = sizeof(DirectX::DDS_MAGIC) + sizeof(DirectX::DDS_HEADER);
- void* texture_data = NULL;
- sf::Uint8* texture_buffer = NULL;
- HANDLE textureDataMemHandle = NULL;
- std::size_t texture_size = 1200 * 1200 * 4; // width * height * 4 byte per pixel (RGBA);
- textureDataMemHandle = OpenFileMapping(access_rights,
- inherited,
- FALCON_TEXTURE_SHM);
- if (textureDataMemHandle == NULL) {
- std::cout << "Unable to open file. Is Falcon Running?" << std::endl;
- return 1;
- }
- texture_data = (void*) MapViewOfFile(textureDataMemHandle,
- access_rights,
- 0, 0, 0);
- sf::Uint8* dds_texture = (sf::Uint8*) texture_data + offset;
- texture_buffer = new sf::Uint8[texture_size];
- for(unsigned int i = 0; i < texture_size; i += 4) {
- // changes from BGRA to RGBA
- texture_buffer[i] = dds_texture[i + 2]; // R
- texture_buffer[i + 1] = dds_texture[i + 1]; // G
- texture_buffer[i + 2] = dds_texture[i]; // B
- texture_buffer[i + 3] = 0xFF; // dds_texture[i]; // A 0xFF
- }
- sf::Texture tex;
- tex.create(1200, 1200);
- tex.update(texture_buffer);
- bool result = tex.copyToImage().saveToFile("texture.png");
- std::cout << "Save Result: " << result << std::endl;
- std::cout << "offset dim: " << (unsigned int) offset << std::endl;
- delete texture_buffer;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement