Advertisement

Texture loading...

Started by November 25, 2001 02:59 AM
5 comments, last by DarkHunter 23 years, 3 months ago
How do i load 6 textures? One for each side of a cube.
What sort of extures do you use (bmp, tga or else)?
Advertisement
Bitmap (.bmp), but i can do others if i need to.
You should check NeHe''s tutorials.
Prosper/LOADED, ummm no offense, but dont you think ihaev CHECKED there??? As i understand it loads the texture to
glTexture[0] and then uses that to make the side, and it reloads another image for each side. Myabe i am not understanding it correctly, which is most likely the case.

Or can sombody just tell me how to load 6 textures in an arry, then i will be set. Thanks
Just use glGenTextures(GLsizei n, GLuint *textures). The first argument is the number of textures OpenGL should allocate, and the second is an array that is used to store the IDs that identify the newly allocated textures. So to create six textures:

GLuint texID[6];
glGenTextures(6, texID);

So each element of the array texID is now (sort of) a pointer to a texture. To actually load graphics into the textures:

for (int j=0; j < 6; j++) {
glBindTexture(texID[j]);
glTexImage2D(...);
}

The arguments for glTexImage2D are the pixel data, format etc for a bmp file (or any other type) that you've loaded into memory. Search Google for an explanation of all the parameters, or look at NeHe's code.
To draw the cube with different textures on each face:

glBegin(GL_TRIANGLES);
glBindTexture(texID[0]); //draw using the first texture
//draw first face, glTexCoord2f and glVertex3f
glBindTexture(texID[1]); //draw using the second texture
//draw second face
...
glEnd();

To deallocate the textures if you know you no longer need them:

glDeleteTextures(6, texID);

The arguments are the same as glGenTextures, the number of textures to delete and the array of IDs to delete.

Hope that helps.

Edited by - Dobbs on November 26, 2001 4:39:53 AM
Advertisement
quote:
Original post by Dobbs
Just use glGenTextures(GLsizei n, GLuint *textures). The first argument is the number of textures OpenGL should allocate, and the second is an array that is used to store the IDs that identify the newly allocated textures. So to create six textures:

GLuint texID[6];
glGenTextures(6, texID);

So each element of the array texID is now (sort of) a pointer to a texture. To actually load graphics into the textures:

for (int j=0; j < 6; j++) {
glBindTexture(texID[j]);
glTexImage2D(...);
}

The arguments for glTexImage2D are the pixel data, format etc for a bmp file (or any other type) that you''ve loaded into memory. Search Google for an explanation of all the parameters, or look at NeHe''s code.
To draw the cube with different textures on each face:

glBegin(GL_TRIANGLES);
glBindTexture(texID[0]); //draw using the first texture
//draw first face, glTexCoord2f and glVertex3f
glBindTexture(texID[1]); //draw using the second texture
//draw second face
...
glEnd();

To deallocate the textures if you know you no longer need them:

glDeleteTextures(6, texID);

The arguments are the same as glGenTextures, the number of textures to delete and the array of IDs to delete.

Hope that helps.

Edited by - Dobbs on November 26, 2001 4:39:53 AM


Put the glBindTexture(texID[n]) outside of
your glBegin..glEnd pair as it is undefined
if used within these calls.

Mark

This topic is closed to new replies.

Advertisement