In the OpenGL tutorials on nehe.gamedev.net they don't tell you how to load multiple textures. I've been experimenting with the original code to do this but I just can't figure out how to do this yet. Anybody know?
Printable View
In the OpenGL tutorials on nehe.gamedev.net they don't tell you how to load multiple textures. I've been experimenting with the original code to do this but I just can't figure out how to do this yet. Anybody know?
Umm I'm assuiming you're doing lesson 4 or 5 or whatever the first texture example is. If that's the case they do tell you how to load multiple textures. I'm assuimg you have the same setup as nehe. create a global GLuint texture array, and call the LoadTexture function for each element of that array. When you go to draw, call glBindTexture(GL_TEXTURE_2D, texture[x]); before you draw the polygon and make sure it is outside of the glBegin/glEnd block;
Code:
GLuint texture[2]; //storage for 2 textures
...
//in your initialize function (InitGL() in nehe)
texture[0] = LoadTextures("crap.bmp"); //this function name may be different than nehe's but they are fundamentally the same
texture[1] = LoadTextures("bitmap.bmp");
...
//in your drawglscene function (DrawGLScene() in nehe)
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
glLoadIdentity(); // Reset The Current Modelview Matrix
gluLookAt(0.0f, 0.0f, 0.0f, 0.0f, 0.0f, -150.0f, 0.0f, 1.0f, 0.0f);
glPushMatrix();
glTranslatef(-20.0f, 0.0f, 0.0f);
glBindTexture(GL_TEXTURE_2D, texture[0]); //MAKES THIS OUR CURRENT TEXTURE
glBegin(GL_QUADS);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-15.0f, -5, -75.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(15.0, -5, -75.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(15.0, 5, -75);
glTexCoord2f(-1.0f, 1.0f); glVertex3f(-15.0f, 5, -75);
glEnd();
glPopMatrix();
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture[1]);
glBegin(GL_QUADS);
glTranslatef(20.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-15.0f, -5, -75.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(15.0, -5, -75.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(15.0, 5, -75);
glTexCoord2f(-1.0f, 1.0f); glVertex3f(-15.0f, 5, -75);
glEnd();
return TRUE; // Everything Went OK
}
Thank you so much. :cool:
Didn't work, here's the source:
?
here is that example, sorry it took so long