Last active
May 15, 2019 17:08
-
-
Save giupo/eb54eada9198b0ac9d870fe430ff585a to your computer and use it in GitHub Desktop.
Smashing my head on FalconTexturesSharedMemoryArea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment