   Multiple textures
  I am writing a simple game and have got one texture working, however when I try to add another one all of the textures go wrong. I am using the nvImage.h header file. I start by binding the texture and then calling the texture on the object. The two relevant bits of code are below, in the if loop of the first quote there is also a lot of calls of glTexParameteri but they didn't seem that important to the problem.Quote:if(img.loadImageFromFile("texture.png")){glGenTextures(1, &Texture);glBindTexture(GL_TEXTURE_2D, Texture);Quote: glEnable(GL_TEXTURE_2D);glBindTexture(GL_TEXTURE_2D, Texture);glEnable(GL_BLEND);glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);glBegin(GL_POLYGON);glTexCoord2f(0.0, 0.0); glVertex2f(50,50);glTexCoord2f(0.0, 1.0); glVertex2f(-50,50);glTexCoord2f(1.0, 1.0); glVertex2f(-50,-50);glTexCoord2f(1.0, 0.0); glVertex2f(50,-50);glEnd();glDisable(GL_TEXTURE_2D);glPopMatrix();glPushMatrix();The way I am trying to use more than one texture is simply copying the first code snippet but changing the 1 to a 2 and using a new texture name. Is this right or am I missing something?   
  Typically, one loads the textures at the beginning of the program. These are then drawn inside some form of loop.In OpenGL, each texture is identified by a "handle". In your case, the texture handle is "Texture". This is what you should have two of, two texture handles.I don't see where you upload the texture into this handle. This is something I imagine the "img" object is capable of doing. It is possible the "img" object has an internally generated handle, I have never used this api before.[edit]Some googling shows me that you should have a line like this:glTexImage2D(GL_TEXTURE_2D, 0, img.getInternalFormat(), img.getWidth(), img.getHeight(), 0, img.getFormat(), img.getType(), img.getLevel(0));You may have accidentally omitted it with the calls to glTexParameteri.This would be an sample code structure:Gluint loadTexture(const std::string &file){    GLuint result;    nv::Image img;    if(img.loadImageFromFile(file.c_str()))    {   glGenTextures(1, &result);   glBindTexture(GL_TEXTURE_2D, result);   glTexImage2D(GL_TEXTURE_2D, 0, img.getInternalFormat(), img.getWidth(), img.getHeight(), 0, img.getFormat(), img.getType(), img.getLevel(0));   // calls to glTexParameteri    }    return result;}int main(){    // ...    Gluint texture[2]; // an array of two textures    texture[0] = loadTexture("first.png");    texture[1] = loadTexture("second.png");    bool running = true;    while(running)    {    // clear screen    glBindTexture(GL_TEXTURE_2D, texture[0]);    // draw something    glBindTexture(GL_TEXTURE_2D, texture[1]);    // draw something else   // SwapBuffers or whatever    }};  Thanks for the reply, sorry it has taken so long was on holiday.Bit unsure about how that sample code works, do I need to create a separate text file with all the texture names in? If that is the case how do I then call a certain texture if they are all saved as result?Sorry I am new to texturing.   ;glGenTextures(n, &Texture);This line of code generates n texture handles, and places them into memory starting at address &Texture.Typically one would create a single texture at a time, such asglGenTextures(1, &Texture);This will create a single texture ID and place it into variable Texture.So for each texture you want to create, you will need to call that line, but you will need to store the textureID away somewhere. The simplest way to do this would be to have an array of textureID's as a global variable.Gluint  TextureID[10];And then when you are creating your textures, you call a loop:for (int i = 0; i < 11; i++){  glGenTextures(1, &TextureID);  glTexParameteri() etc.... goes in here.}Now when you are rendering you models, you will need to call glBindTexture() on the appropriate TextureID for that model.If you need a more thorough code snippet, check out my Journal. I've uploaded the code I use for my TGA loader which returns the TextureID.   ;  I assume you are changing 1 into 2 hereglGenTextures(1, &Texture);Well, thats wrong because you are telling to make two textures instead of one. GLuint is a pointer to memory and is capable fo pointing to one place at once. You should have an array of pointers of multiple pointers. You have to make it like this:GLuint Texture[2];//array of two texture pointersglGentextures (2, Texture); //this will now work///...glBindTexture (GL_TEXTURE_2D, Texture[0]);glBindTexture (GL_TEXTURE_2D, Texture[1]); //use like this (note decrease by one in index)OrGLuint TextureOne, TextureTwo;//array of two texture pointersglGentextures (1, TextureOne);glGentextures (1, TextureTwo);///...glBindTexture (GL_TEXTURE_2D, TextureOne);glBindTexture (GL_TEXTURE_2D, TextureTwo); //use like thisedit: damn, too slow...   ;Quote:Original post by transistor09GLuint is a pointer to memory and is capable fo pointing to one place at once.GLuint is an unsigned integer value type, not a pointer type.   ;Quote:Original post by Brother BobGLuint is an unsigned integer value type, not a pointer type.Well, after a minute I've realized that I was going to regret saying that ;) but anyway, it is used as pointer of some sort by OpenGL. At least that is how I understand it.   ;Quote:Original post by transistor09Quote:Original post by Brother BobGLuint is an unsigned integer value type, not a pointer type.Well, after a minute I've realized that I was going to regret saying that ;) but anyway, it is used as pointer of some sort by OpenGL. At least that is how I understand it.It both is, and is uses as, an unsigned integer value type. A pointer of some type implies that the pointed to value have a meaning, but the meaning of the texture handle is completely disconnected from its internal meaning.   ;  Thanks for the help, sort of understand but how does it know what texture is which id. Like if I had texture1.png, texture2.png etc how does it know which one I want to call?   ;  When you bind a texture ID, operations apply to that texture ID. Here's a rough example.GLubyte *data1 = loadimage("texture1.png"); // 1GLubyte *data2 = loadimage("texture2.png"); // 2GLuint id1;GLuint id2;glGenTextures(1, &id1); // 3glGenTextures(1, &id2); // 4glBindTexture(GL_TEXTURE_2D, id1); // 5glTexImage2D(..., data1);// 6glBindTexture(GL_TEXTURE_2D, id2); // 7glTexImage2D(..., data2);// 8Line 1 and 2 loads the image and returns the data, and line 3 and 4 allocates new texture IDs.Line 5 binds the first ID, and any following call to texture functions will apply to that texture ID. So, line 6 loads the texture data from "texture1.png" into texture id1.Line 7 binds the second ID, and so line 8 loads the texture data from "texture2.png" into texture id2.Now, any time you bind id1 or id2, OpenGL knows which image to use because the data has been associated with the ID by binding the ID with glBindTexture followed by loading the data with glTexImage2D.   