Results 1 to 4 of 4

Thread: multiple textures

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    5

    multiple textures

    hey guys im a bit new at the opengl stuff, what i wanted to know is how to do multiple textures in a level, im able to texture the floor of my game level but i want texture cubes as well but i dont know how to call multiple textures

    struct Image
    {
    unsigned long size_x;
    unsigned long size_y;
    char *data;
    };

    typedef struct Image Image;

    const int textureCount = 1;

    Image myTextureData[textureCount];
    GLuint theTexture[textureCount];


    char* textureFilenames[textureCount] = {"road.bmp"};
    and my texture loader code

    void textureLoader()
    {

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    for(int k=0; k < textureCount; k++)
    {
    if(!imageLoader(textureFilenames[k], &amp;myTextureData[k]))
    exit(1);


    glGenTextures(1, &amp;theTexture[k]);

    glBindTexture(GL_TEXTURE_2D, theTexture[k]);


    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL _REPEAT);
    glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL _REPEAT);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR_MIPMAP_NEAREST);

    gluBuild2DMipmaps(GL_TEXTURE_2D, 3, myTextureData[k].size_x, myTextureData[k].size_y, GL_RGB, GL_UNSIGNED_BYTE, myTextureData[k].data);
    }

  2. #2
    Junior Member Newbie
    Join Date
    Mar 2011
    Location
    England
    Posts
    1

    Re: multiple textures

    Hey Man

    If you want to apply different Textures to different objects in a level or to different walls for example The easiest way to do it is to place glEnable(GL_TEXTURE_2D) at the top of each section of code to do with your wall/object, Then place your glBindTexture(GL_TEXTURE_2D, theTexture[k]); directly underneith this and then place glEnd() at the end of them, of course you should push and pop the matrix each time this is done.

    This is the basics of the basics for textures so I dont know how much this will help but I hope it does.

    Good luck mate.

  3. #3
    Junior Member Newbie
    Join Date
    Aug 2011
    Location
    Montana, USA
    Posts
    16

    Re: multiple textures

    Fatch1990 is right, You should use GL_TEXTURE_2D for each object unless you are using 3D textures. A good way to texture each object is to generate your textures using:

    glGenTextures(GLsizei n, GLuint *textures);

    This will give you some "handles" to the textures that then you use to bind the textures before the rending of each object:

    glBindTexture(GL_TEXTURE_2D, texture[<index>]);
    <Render Object>

    That should work.
    I hope that helps!
    assert(this.post != (new BadPost(this.guyname, 1/0).IsTerrible());
    Assertion Failed!

  4. #4
    Junior Member Newbie
    Join Date
    Jul 2011
    Posts
    22

    Re: multiple textures

    Check out this site, it has video tutorials on the subject, I believe it's lesson 5. If your level is going to be large your going to want to pack all your textures into one big one, then read only part of the file at a time. You can only use one texture per render call (or so I was told a while back when I asked this same question), and your game is going to slow down after so many render calls. Sadly there isn't a tutorial on that site for this...I guess the MD2 animation tutorial goes into it a little bit, but it barely goes into any depth on the subject.

    Hope that helps some!
    Goblin

Similar Threads

  1. Replies: 9
    Last Post: 11-02-2018, 08:16 AM
  2. multiple textures
    By tnt1674 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 06-18-2016, 08:29 AM
  3. Multiple Viewports, Multiple Textures - 3D
    By Cyndy in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 04-08-2010, 04:47 PM
  4. multiple lights and multiple textures
    By jide in forum OpenGL: GLSL
    Replies: 4
    Last Post: 10-26-2005, 06:47 AM
  5. multiple textures
    By Thr33d in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 04-27-2000, 04:07 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean