I'm new, need technical info on lesson 6 pls

Started by
6 comments, last by GameDev.net 19 years ago
Hi all, brand new I'm a novice programmer, I found lesson 6 very confusing for one reason. Please refer to the following code extracted from lesson 6: ... int LoadGLTextures() // Load Bitmaps And Convert To Textures { ... if (TextureImage[0]=LoadBMP("Data/NeHe.bmp")) { Status=TRUE; // Set The Status To TRUE glGenTextures(1, &texture[0]); // Create The Texture ... How is TextureImage[0] and texture[0] related? There seems to be no relations in plain sight. The bitmap is loaded into TextureImage, then the only mention of texture is in a line of code that doesnt include TextureImage... How is the program doing that? So, The bitmap is loaded into TextureImage[0], then all of a sudden the program starts to refer to texture[0] for the bitmap when there is no mention of the relationship between the 2 variables (atleast i'm not aware of it). Yet the program works. Remember I'm new so go easy on the explanation, thanks :)
Advertisement
glGenTextures(1, &texture[0]);

That generates a texture within OpenGL, when that is called however, the texture has no data assigned to it.

glBindTexture(GL_TEXTURE_2D, texture[0]);

That binds the texture you just created to OpenGL so that way any OpenGl methods that make use of textures will either use or effect that texture

glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

That then takes the texture data you got in TextureImage and places it into that texture
Wow nice and fast reply, thanks very much it made it much clearer.

The explanation on the tutorial wasn't so clear abou that bind thing.

TA
Just to add on to what the AP said:

texture[0] is of type unsigned integer. This is just a "handle" to the Texture object that OpenGL creates internally. You cannot access this Texture object, but you use the handle to reference it.

texture[0] is then bound to GL_TEXTURE_2D, so whenever you do somthing with GL_TEXTURE_2D, openGL will make the change to the texture Object this handle refers to.

TextureImage[0] is of type AUX_RGBImageRec* this represents the actual bitmap and is not part of openGL. (It is part of the gl auxilary library I think).
Nehe uses this to pass the actual image data into the Texture Object OpenGL keeps internally. - I personally use SDL_Surface* for this -
I'm also a bit stuck, I think the file is being found alright, because the window opens and the cube rotates, but its all white, no textures there, and I really dont know why, any hints?
Quote:Original post by Anonymous Poster
I'm also a bit stuck, I think the file is being found alright, because the window opens and the cube rotates, but its all white, no textures there, and I really dont know why, any hints?


Did you edit the textures yourself?
If so, it normally indicates that your texture size is non-power of 2, which means that either the width or the height - or both - isn't 2, 4, 8, 16, 32, 64, 128, 256, 512 etc. pixels wide.

If you have edited the source, then that could also be the reason.
Try compile and run the original source, which should work - if it does, then look for changes in yours vs. the original (although I prefer just to use CVS to check for changes in two files - it's a lot easier than searching yourself, if you're using CVS anyways)

[Edited by - nife on April 2, 2005 3:46:30 AM]
Killers don't end up in jailThey end up on a high-score!
now i understand how the texture works and each of its function. thanks to simeon and anonymous poster.
I am also quite confuse in the begining but after some explaination, I am able to understand little by litte. Good that my fren's place got internet line.
Thanks nife! Who knew 2 was such an important number, its still no 1 though.

This topic is closed to new replies.

Advertisement