0

I'm currently learning how to load and use images in openGL. I tried many examples of several tutorials. Many of the tutorials use a function: LoadBMP or something. This function was not declared by the headers I use.

Do you need an appart header for the function wich loads an image? I looked at the openGL wikipedia, and they say that there exists 3 such headers.

Or do I have it wrong? Do you need openGL 3.0 or higher to load images?

genpfault
  • 51,148
  • 11
  • 85
  • 139
abcdef
  • 236
  • 1
  • 5
  • 17
  • 1
    LoadBMP is not part of OpenGL proper. I believe glaux.h may have some functions that help you with image loading (at least for bitmaps). These functions will return you an AUX_RGBImageRec which would have the RGBA data you'd load using glTexImage. – Aeluned Jan 05 '13 at 15:52
  • So I first have to download the glaux.h header? Just a header file no .dll files? – abcdef Jan 05 '13 at 15:56
  • DevIL image library is one example of a commonly used image library. – Grimmy Jan 05 '13 at 17:39

2 Answers2

10

OpenGL doesn't have any functions to load images. You can either write a LoadBMP function yourself or use a third party library. There are many available, and you can find some of them in this answer to a related question.

You can then pass the raw image data to an OpenGL texture creation function, like glTexImage2D, to create the texture.

Community
  • 1
  • 1
Plow
  • 4,001
  • 3
  • 20
  • 21
  • If you want to write your one, say: loadJPEG to load a JPEG image, Do you have to decode the JPEG format? – abcdef Jan 06 '13 at 16:07
3

OpenGL is only an API for accessing the GPU. There is no functionality to load any media files (images, 3d models, etc). There isn't even support for creating windows in a given OS (OS API needs to glue with OpenGL).

You need to load bytes from the images (using another library) and then you can upload it to GPU using OpenGL.

For simple purposes I use a library called SOIL which I think is great. There is a list of related toolkits and APIs on the OpenGL wiki which may be useful.

Samuel Harmer
  • 4,264
  • 5
  • 33
  • 67
fen
  • 9,835
  • 5
  • 34
  • 57