The following code successfully renders an image using an absolute path;
unsigned int renderer_id;
std::string filepath;
unsigned char* local_buffer;
int width;
int height;
int bpp;
std::string filepath("filepath\\here.png");
stbi_set_flip_vertically_on_load(1);
local_buffer = stbi_load(filepath.c_str(), &width, &height, &bpp, 4);
glGenTextures(1, &renderer_id);
glBindTexture(GL_TEXTURE_2D, renderer_id);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, local_buffer);
glBindTexture(GL_TEXTURE_2D, 0);
if (local_buffer) {
stbi_image_free(local_buffer);
}
However if I cut the stbi code out and try to load the image from resources, it renders completely black;
HMODULE hMod = GetModuleHandleW(NULL);
const std::wstring str = utils::Conversions::string_to_wstring("PNG");
HRSRC hRes = FindResourceW(hMod, MAKEINTRESOURCEW(TEST_IMAGE), str.c_str());
std::cout << "1: " << hRes << std::endl; HGLOBAL hGlobal = LoadResource(hMod, hRes);
std::cout << "2: " << hGlobal << std::endl; local_buffer = LockResource(hGlobal);
DWORD pwPngDataBytes = SizeofResource(hMod, hRes);
std::cout << "3: " << pwPngDataBytes << std::endl;
TEST_IMAGE is #defined as 102
resources.rc contains:
TEST_IMAGE PNG "filepath\\here.png"
Here is the PNG metadata, in case any of it is relevant:
img[
^]
As there are no errors and those debug values mean nothing, I'm not sure how to debug this.
What I have tried:
All details already in the question