1

can someone give a simple example with freeimage(with opengl) and glfw3 ?

when using image er("io.png"); er->gen(); only blackscree is rendered

code for the program

    class image
    {
    public:
        FREE_IMAGE_FORMAT format;
        FIBITMAP * img;
        GLubyte* texture;
        char* pixels;
        GLuint texID;
        int w,h;
        image(char* cr){
            format = FreeImage_GetFileType(cr);
            img = FreeImage_Load(format,cr);

            w = FreeImage_GetWidth(img);
            h = FreeImage_GetHeight(img);
            cout << w << " " << h << endl;
            pixels = (char*)FreeImage_GetBits(img);
        }
        void gen()
        {
            glGenTextures(1,&texID);
            glBindTexture(GL_TEXTURE_2D,texID);
            glTexImage2D(GL_TEXTURE_2D,0,GL_BGR,w,h,0,GL_BGR,GL_TEXTURE_2D,pixels);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

        }
    };

I'm trying to use a image as background opengl application

Sam
  • 41
  • 1
  • 6

1 Answers1

0

FreeImage_GetBits() function returns a pointer to the data stored in a FreeImage-internal format. Where each scanline is usually aligned to a 4-bytes boundary. This will work fine while you have power-of-two textures. However, for NPOT textures you will need to specify the correct unpack alignment for OpenGL.

There is another function in FreeImage which will allow you to get unaligned tightly packed array of pixels: FreeImage_ConvertToRawBits(). Use it.

Sergey K.
  • 24,894
  • 13
  • 106
  • 174