View Full Version : loading bmp files using opengl
12-14-2010, 04:44 PM
how do you load a bmp file into opengl.
12-14-2010, 04: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.
12-14-2010, 05:07 PM
well I am using win 7 and and c++.
12-14-2010, 05: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);
Rect lockRect (0, 0, theImage.GetWidth (), theImage.GetHeight ());
theImage.LockBits (&lockRect, ImageLockModeRead, PixelFormat32bppARGB, &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
12-14-2010, 10:17 PM
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 -
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.