5

I have read around on this, including Nehe and here for solutions, but I cant find a specific answer.

I am trying to load a a photo, called stars.jpg. I want to make this my background of the scene, by mapping it using uv coordinates, doing it by

glBegin(GL_QUADS);
glTexCoord2f(0,0);
glVertex2f(0,0);

However I am just very confused about how to load the actual textures in, all the calls for

glActiveTexture();
glEnable(GL_TEXTURE_2d);
glBindTexture(GL_TEXTURE);

All they do is confuse me, what do all these mean/do, and in what order am I suppose to put these in, in order to get the stars.jpg to be my background?

Jim
  • 3,236
  • 8
  • 33
  • 43
  • maybe you should take a look at http://nehe.gamedev.net to get some basics about OpenGL, it sounds that you are a bit lost. – AndersK Nov 27 '10 at 09:46

2 Answers2

4

Your number-one tool for loading textures in OpenGL is the Simple OpenGL Image Loader (SOIL) library. You just need to pass the filename and some flags and you'll get your texture ID.

Also, you're learning very old and outdated version of OpenGL now - you might want to have a google for newer tutorials or browse the specs whenever you feel ready.

Kos
  • 70,399
  • 25
  • 169
  • 233
  • The operating system I am writing on is very outdated, and is not going to be upgraded. – Jim Nov 27 '10 at 21:08
  • The GPU and the drivers matter, not the underlying OS. But the remark about SOIL still holds even for old GL versions. – Kos Nov 28 '10 at 00:16
3

Here's a step by step tutorial on loading textures
http://www.nullterminator.net/gltexture.html

Its important to remember that OpenGL is a state machine, so you have to tell it "I'm going to talk about textures now" that's where the glActiveTexture(); comes in.

Also keep in mind that you will have to load in pixel by pixel the colors from your .jpg (compressed) to your texture array, so either you will need to find a library that will give you bitmap values of your .jpg file or you will need to pre-convert it into a .ppm or a .bmp which will make reading in the values easier.

TJB
  • 13,367
  • 4
  • 34
  • 46
  • "you have to tell it "I'm going to talk about textures now" that's where the glActiveTexture(); comes in" - untrue. This call takes one parameter (a constant from `GL_TEXTURE0` to `GL_TEXTUREn` with `n` being the id of last texture unit) and indicates that the given texture unit is the "active" one (affected by the further calls). To have a simple texture object, you just need one texture unit (the default), so you don't need to call it. – Kos Nov 27 '10 at 12:41
  • Now, the website you gave works (it helps me understand it), I just cant get the texture to actually display as the background... – Jim Nov 27 '10 at 22:22
  • Did you use the image loader specified in @Kos answer? http://stackoverflow.com/questions/4290870/texture-mapping-c-opengl/4291404#4291404 or are you still using the jpg format? – TJB Nov 28 '10 at 02:13