Search code examples
c++opengltexturestexture-mapping

opengl texture mapping


i have got a single texture working in my opengl project the problem is it only lets me use one texture i was wondering how i can change this so i can use multiple textures maybe an array? when i load in more than one bitmap image i can't seem to get it to work

this is the code i am using to create the texture

glEnable (GL_TEXTURE_2D);
    Bitmap image;

    image.loadBMP ("TEXTURE1.bmp");
    glGenTextures(1, &m_TextureID);
    glBindTexture ( GL_TEXTURE_2D, m_TextureID);

    glTexEnvf ( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE , GL_MODULATE);
    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameterf ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    gluBuild2DMipmaps ( GL_TEXTURE_2D, 3, image.width, image.height, GL_RGB, GL_UNSIGNED_BYTE, image.data);
    glDisable (GL_TEXTURE_2D)

can anybody point me in the right direction thanks


Solution

  • Besides calling glGenTextures n times, you can do this :

    const GLsizei n = 5;
    GLuint textureIDs = new GLuint[ n ];
    glGenTextures( n, textureIDs );