ImGui::Image with opengl black box instead of the image


#1

Hi all,
I’m trying to show a simple png image, using the documentation on imgui.cpp and modifying example_glfw_opengl3, but probably I’d doing something very stupid because instead of the image I see a black box.

My code:

int my_image_width, my_image_height;
unsigned char* my_image_data = stbi_load("test.png", &my_image_width, &my_image_height, NULL, 4);
// Turn the RGBA pixel data into an OpenGL texture:
GLuint my_opengl_texture;
glGenTextures(1, &my_opengl_texture);
glBindTexture(GL_TEXTURE_2D, my_opengl_texture);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, my_image_width, my_image_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, my_image_data);
// Now that we have an OpenGL texture, assuming our imgui rendering function (imgui_impl_xxx.cpp file) takes GLuint as ImTextureID, we can display it:
ImGui::Image((void*)(intptr_t)my_opengl_texture, ImVec2(my_image_width, my_image_height));

The image data seems to be read properly from the filesystem, since the box size is the correct one. I’ve attached also a screenshot of the metric window for reference.

12

Thanks for your help.
Andrea


Issues Rendering Images
#2

That’s the code in the imgui.cpp comments. It’s not clear what you are actually doing since the first part is “loading” code and the second part is “output” code to be submitted every frame.
It would be best to submit an actual full/complete repro with all the code and the test.png file you are using.