Hi,
I found some code which does load the image from my resource. I know it works because was able to save the image out, but I am having trouble getting it into a Sprite. Ok so the following function works, but it isn't one i wrote. I found it on stackoverflow.
sf::Image LoadImageFromResource(const std::string& name)
{
HRSRC rsrcData = FindResource(NULL, name.c_str(), RT_RCDATA);
if (!rsrcData)
throw std::runtime_error("Failed to find resource.");
DWORD rsrcDataSize = SizeofResource(NULL, rsrcData);
if (rsrcDataSize <= 0)
throw std::runtime_error("Size of resource is 0.");
HGLOBAL grsrcData = LoadResource(NULL, rsrcData);
if (!grsrcData)
throw std::runtime_error("Failed to load resource.");
LPVOID firstByte = LockResource(grsrcData);
if (!firstByte)
throw std::runtime_error("Failed to lock resource.");
sf::Image image;
if (!image.loadFromMemory(firstByte, rsrcDataSize))
throw std::runtime_error("Failed to load image from memory.");
return image;
}
So in my main I put this to test if it worked.
sf::Image scotty_png = LoadImageFromResource("SCOTT_PNG");
scotty_png.saveToFile("pp.png");
Good news is that it loaded the png from the resource and actually saved out the Png to a file. So I know the resource is working. The problem is that I don't know how to turn this into a sprite. I think it is already a texture when it comes in. Or have I got that wrong?
I tried this, but it says I am doing a redeclaratoin
sf::Sprite ScottSprite;
ScottSprite.setTexture(scotty_png);
PS. It is actually image. So I am just trying to work out how to convert the image to a Sprite now LOL.
I think with a little help I can get this working.
Asimov