PDA

View Full Version : loading bmp files using opengl



phil67rpg
12-14-2010, 05:44 PM
how do you load a bmp file into opengl.

mhagain
12-14-2010, 05:49 PM
Write a BMP loading function or use a BMP loading library.

Seriously, OpenGL has no support for loading specific image formats at all; that's not a design goal of it. You need to either provide your own code or use a library to get at the raw pixel data and send that through glTexImage2D.

Which library to use depends on what OS you're on, whether or not portability is a concern for your program, what language you're using and other factors.

phil67rpg
12-14-2010, 06:07 PM
well I am using win 7 and and c++.

mhagain
12-14-2010, 06:28 PM
Well there are a number of options. On that platform I like using GDI+ because it means that you can distribute your application to other Windows (XP, Vista or 7) users without requiring them to install additional DLLs to get it running. Something like this will do it (untested, for illustrative purposes only):

Bitmap theImage (name);
BitmapData bmpData;
Rect lockRect (0, 0, theImage.GetWidth (), theImage.GetHeight ());
theImage.LockBits (&lockRect, ImageLockModeRead, PixelFormat32bppARGB, &bmpData);
glTexImage2D (...);
theImage.UnlockBits (&bmpData);

You'll also need to correctly start up and shut down GDI+ in your program; info here: http://msdn.microsoft.com/en-us/library/ms533895%28VS.85%29.aspx

ugluk
12-14-2010, 11:17 PM
http://www.nothings.org/stb_image.c

MaxH
12-15-2010, 12:11 AM
I have a simple demo that loads .bmp files and displays them as textures or as an image (glDrawPixels). The .bmp loading routines are contained in the demo. You don't have to mess with any libraries. See -

http://www.mfwweb.com/OpenGL/Loading_Textures/