Issues Rendering Images


#1

Hi, I’m having trouble displaying custom PNG images to an ImGui window. I’m using OpenGL3 with SDL and I’m starting out with modifying the sdl/opengl3 example provided before moving to my project.

The issue I’m having is that the image is being displayed as a black box in the window I want to render it in (exactly like this issue: ImGui::Image with opengl black box instead of the image). I first tried putting the code you provided in the “How do I display an image?” FAQ section in main.cpp, but then after reading more into how OpenGL texture loading works, I ended up with this code (my changes are marked with the “CG Change” comment): http://txt.do/dn8pf

As for the image, I have a simple png that I place in the example_sdl_opengl3 directory along with stb_image.h. Here’s the png I’m using for reference: https://imgur.com/xFsKxDx (you’ll have to change the file name to make it play nice with the code).

Thank you,
Chris Gomez


#2

Hello Chris,

I gave it a shot and realized the examples in the comment was incomplete as per GL defaults mandate the Min/Max filter to be set if we don’t use mipmap.

If you add this before the call to glTexImage2D() it works for me:

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);