Results 1 to 7 of 7

Thread: texture mapping

  1. #1
    Member Contributor
    Join Date
    Feb 2009
    Posts
    73

    texture mapping

    I'm trying to learn to use textures using the redbook and the "superbible"; I've also been thru the gl game programming wiki and some other tutorials; none of these use exactly the same procedure, but it still seems like it should be DEAD SIMPLE.

    Can someone tell me why what I doing does not work? This is my initialization/setup function which loads the texture. The "gltLoadTGA" is from the superbible toolkit and works in the demos there:
    Code :
    void init(float R, float G, float B) {
            GLubyte *tximg;
            GLint wd, hgt, comp;
            GLenum form;
            GLuint Texture;
     
            glClearColor(R,G,B,1.0f);
     
            glEnable(GL_TEXTURE_2D);
     
            glGenTextures(1,&Texture);
     
            glPixelStorei(GL_UNPACK_ALIGNMENT, 1);   /* because of tga format */
            tximg = gltLoadTGA("hexpattern.tga",&wd,&hgt,&comp,&form); 
            glTexImage2D(GL_TEXTURE,0,comp,wd,hgt,0,form,GL_UNSIGNED_BYTE,tximg);
            free(tximg);
     
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            glBindTexture(GL_TEXTURE_2D,Texture);   
    }
    I've tried a few different options with TexParameter and TexEnv. Then the scene rendering function:
    Code :
    void scene() {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
            glColor4f(1.0f,1.0f,1.0f,1.0f);
            glBegin(GL_QUADS);
                    glTexCoord2f(0.0f,0.0f); glVertex3f(-10.0f,-10.0f,0.0f);  
                    glTexCoord2f(0.0f,1.0f); glVertex3f(-10.0f,10.0f,0.0f);  
                    glTexCoord2f(1.0f,1.0f); glVertex3f(10.0f,10.0f,0.0f);  
                    glTexCoord2f(1.0f,0.0f); glVertex3f(10.0f,-10.0f,0.0f);
            glEnd();
            gluLookAt(0.0f,0.0f,50.0f,0.0f,0.0f,0.0f,0.0f,1.0f,0.0f);
            glutSwapBuffers();
    }
    I have no lighting enabled in this because it's a simplification of the original scene, and no one implies that it is necessary. But no matter what I do, all I end with is a white square.

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: texture mapping

    "If texturing is enabled (and TEXTURE_MIN_FILTER is one that requires a mipmap) at the time a primitive is rasterized and if the set of arrays 0 through n is incomplete, based on the dimensions of array 0, then it is as if texture mapping were disabled."

    By default, texture min filter does require a mipmap.
    http://www.opengl.org/resources/feat...es/oglpitfall/

    A quick fix to actually see your texture is change the env setting of MIN filter to one that does not require a mipmap :
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    Ugly, but should work.

    Better, let the hardware autogenerate mipmaps whenever it feels the need :
    glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);

    Even better, to trigger manually the generation of mipmaps by the card, use the newer :
    glGenerateMipmapEXT(GL_TEXTURE_2D);

  3. #3
    Member Contributor
    Join Date
    Feb 2009
    Posts
    73

    Re: texture mapping

    Quote Originally Posted by ZbuffeR
    glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );

    Ugly, but should work.
    That's in the OP. The second choice did nothing, and the third one actually caused my X server to crash (I don't have a real graphics card, so I'm using software emulation, which is fine, I'm not a gamer).

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,574

    Re: texture mapping

    oops sorry, these tiny boxes are hard to read.
    well the rest seem ok, I am not familiar to gltLoadTGA, what are the values of wd,hgt,comp,form after it is called ?

    Have a try with a basic array, to rule out a file or loader problem :
    // the texture (2x2)
    GLbyte textureData[] = { 128, 128, 128, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 0 };
    GLsizei width = 2;
    GLsizei heigth = 2;
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, width, height, 0, GL_UNSIGNED_BYTE, (GLvoid*)textureData);

  5. #5
    Member Contributor
    Join Date
    Feb 2009
    Posts
    73

    Re: texture mapping

    Quote Originally Posted by ZbuffeR
    Have a try with a basic array, to rule out a file or loader problem :
    Good idea. Same thing. This is the new initialization.
    Code :
    void init(float R, float G, float B) {
            GLuint Texture;
            GLbyte textureData[] = { 128, 128, 128, 255, 0, 0, 0, 255, 0, 0, 0, 255, 255, 255, 0 };
            GLsizei width = 2;
            GLsizei heigth = 2;
     
            glClearColor(R,G,B,1.0f);
     
            glEnable(GL_TEXTURE_2D);
     
            glGenTextures(1,&Texture);
     
            glTexImage2D(GL_TEXTURE,0,GL_RGB8,width,heigth,0,GL_RGB,GL_UNSIGNED_BYTE,(GLvoid*)textureData);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
     
            glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
            glBindTexture(GL_TEXTURE_2D,Texture);   
    }

    There's an odd number of bytes in textureData -- is that right? (Adding an extra zero didn't make much difference anyway)

    Can you take a close look at the TexCoord/Vertex combinations in the OP to make sure I have understood this correctly?

  6. #6
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,367

    Re: texture mapping

    Ithink it should be:

    GL<u>u</u>byte textureData[]

  7. #7
    Junior Member Newbie
    Join Date
    Apr 2009
    Posts
    1

    Re: texture mapping

    Try moving "glBindTexture" to immediately after "glGenTextures".
    glTexImage2D, glTexParameteri, and the like are sensitive to the current texture, which in your case is undefined.
    glBindTexture is kind of like glMatrixMode -- if it's not the very first thing you do, you should known why not.

Similar Threads

  1. Texture mapping ::: 3D Face Mapping
    By 3render3 in forum OpenGL: General
    Replies: 2
    Last Post: 03-24-2013, 06:49 PM
  2. projective texture mapping and shadow mapping
    By phoenix_gl in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 10-08-2012, 08:00 PM
  3. Replies: 0
    Last Post: 01-09-2005, 05:53 PM
  4. Replies: 1
    Last Post: 01-09-2005, 05:50 PM
  5. Texture Mapping / Environmental Mapping.
    By imported_Andrew in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 12-09-2000, 01:20 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