View Full Version : glDrawPixels + FreeImage need help

08-20-2010, 06:07 AM
I want to load a PNG file with freeimage and then render it with glDrawPixels but it dont work.

void ImageLoader::LoadImage(const char *filename){

FIBITMAP *dib(0);

fif = FreeImage_GetFileType(filename, 0);

if(fif == FIF_UNKNOWN)
fif = FreeImage_GetFIFFromFilename(filename);

dib = FreeImage_Load(fif, filename);

bits = FreeImage_GetBits(dib);

width = FreeImage_GetWidth(dib);
height = FreeImage_GetHeight(dib);



This functon loads a file and then I render it:

ImageLoader pic;


glClearColor(0.9, 0.9, 0.9, 0.0);

glDrawPixels(pic.width, pic.height, GL_RGBA, GL_INT, pic.bits);


Can someone help me? I dont want to use a texture.

08-20-2010, 07:44 AM
OK, I try to ask in another way:
How can I load files with freeimage and render it with glDrawPixels?

08-20-2010, 08:50 AM
glDrawPixels() is a bad choice. People usually draw quads and plaster them with 2D textures. Another option are point sprites and some extensions.

opengl faq (http://www.opengl.org/resources/faq/technical/transformations.htm)

You can also google for 2D with opengl or somesuch, there's a ton of resources. Maybe you can try to do it without the FreeImage library at first, for testing. There's:

stb_image (http://nothings.org/stb_image.c)

Rosario Leonardi
08-21-2010, 12:46 PM
bits = FreeImage_GetBits(dib);

You are taking the pointer to the picture data and the you destroy the picture.

glDrawPixels(pic.width, pic.height, GL_RGBA, GL_INT, pic.bits);

DrawPixel as already saw is not the best choise but should work. Are you sure that the picture is RGBA and not only RGB? Also why you use GL_INT? The picture should be 8bit per channel, so GL_UNSIGNED_BYTE. If you will send RGB data take care of the pack_alignment parameter of the pixel store function

Also when you ask a question is better specify what do you see on the screen or post a screen shot. "Don't work" can be "black screen", "I see random pixel", "distorted image" .

ps: by the way. FreeImage let you query the number of bit per pixel and all the data you need.