Thread: OpenGL Texture mapping

  1. #1
    ---
    Join Date
    May 2004
    Posts
    1,379

    OpenGL Texture mapping

    take this snippet of my code
    Code:
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glLoadIdentity();
        
        glEnable(GL_TEXTURE_2D);
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
        glBindTexture(GL_TEXTURE_2D, texture[0]);
        
        glTranslatef(0.0f,0.0f,-20.0f);
        
        glBegin(GL_QUADS);
            glTexCoord2f(0.0,0.0); glVertex3f(-5.0f,5.0f,0.0f); //BACK
            glTexCoord2f(0.0,1.0); glVertex3f(5.0f,5.0f,0.0f);
            glTexCoord2f(1.0,1.0); glVertex3f(5.0f,-5.0f,0.0f);
            glTexCoord2f(1.0,0.0); glVertex3f(-5.0f,-5.0f,0.0f);
            
            glTexCoord2f(0.0,0.0); glVertex3f(5.0f,5.0f,0.0f); //RIGHT
            glTexCoord2f(0.0,1.0); glVertex3f(5.0f,5.0f,50.0f);
            glTexCoord2f(1.0,1.0); glVertex3f(5.0f,-5.0f,50.0f);
            glTexCoord2f(1.0,0.0); glVertex3f(5.0f,-5.0f,0.0f); 
            
            glTexCoord2f(0.0,0.0); glVertex3f(-5.0f,5.0f,50.0f); //LEFT
            glTexCoord2f(0.0,1.0); glVertex3f(5.0f,5.0f,50.0f);
            glTexCoord2f(1.0,1.0); glVertex3f(5.0f,-5.0f,50.0f);
            glTexCoord2f(1.0,0.0); glVertex3f(-5.0f,-5.0f,50.0f);  
            
            glTexCoord2f(0.0,0.0); glVertex3f(-5.0f,5.0f,0.0f); //FRONT
            glTexCoord2f(0.0,1.0); glVertex3f(-5.0f,5.0f,50.0f);
            glTexCoord2f(1.0,1.0); glVertex3f(-5.0f,-5.0f,50.0f);
            glTexCoord2f(1.0,0.0); glVertex3f(-5.0f,-5.0f,0.0f); 
        glEnd();
    
        glBindTexture(GL_TEXTURE_2D, tiles[0]);
        glBegin(GL_QUADS);
            glTexCoord2f(0.0f, 0.0f); glVertex3f(0.0f, 0.0f, 0.0f);
            glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f,0.0f, 0.0f);
            glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 0.0f, 1.0f);
            glTexCoord2f(0.0f, 1.0f); glVertex3f(0.0f, 0.0f, 1.0f);
        glEnd();
             
        SDL_GL_SwapBuffers();
    After I try to change textures and draw my last quad, a blank quad is drawn. I know I'm not changing textures the right way. How do I do it?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Are you sure that tiles[0] is valid and got created successfully? What about if you draw that last quad with the other texture? Does that work?
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

  3. #3
    Registered User jimboob's Avatar
    Join Date
    Jun 2004
    Posts
    40
    I suffered pretty much the same problem... I thought it must of been something I had done wrong. Did you get the texture mapping tutorial from NeHe site?

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    Thanks mr wizard i worked it out.

    and no Im reading the opengl red book. much more comprehensive.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Texture mapping anomaly opengl
    By Shakti in forum Game Programming
    Replies: 1
    Last Post: 04-11-2009, 02:09 AM
  2. OpenGL texture mapping with texCoordArray
    By nempo in forum Game Programming
    Replies: 1
    Last Post: 08-24-2008, 04:00 AM
  3. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  4. Texture mapping in OpenGL
    By Dragon in forum Game Programming
    Replies: 5
    Last Post: 10-19-2003, 09:47 AM
  5. Texture mapping in OpenGL
    By Mithoric in forum Game Programming
    Replies: 3
    Last Post: 09-12-2003, 09:03 AM