how do you load a bmp file into opengl.
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.
well I am using win 7 and and c++.
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: Drawing a Line - Win32 apps | Microsoft Learn
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 -