Results 1 to 5 of 5

Thread: Texturing looks funky (and not in a good way)

  1. #1
    Junior Member Newbie
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    15

    Texturing looks funky (and not in a good way)

    Im trying to texture a maze with a brick wall tag file but when I run it, the bricks are in different directions on different sides of the polygon. Instead of using a cube , I am using a cube with no top or bottom...don't know if that makes a difference.

    here's the code:
    Code :
    /*** This is where the image is read into array and image is filled ****/
    void texture_load()
    {
        GLuint texture;
        int width;
        int height;
        GLubyte *data;
        FILE *file;
     
        // open texture data
        file = fopen("wall.tga", "rb");
     
        // allocate buffer
        data = (unsigned char*) malloc(width * height * 4);
     
        // read texture data
        fread(data, width * height * 4, 1, file);
        fclose(file);
     
        // allocate a texture name
        glGenTextures(1, &texture);
     
        // select our current texture
        glBindTexture(GL_TEXTURE_2D, texture);
     
        // select modulate to mix texture with color for shading
        glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
     
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
     
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, 
                     (GLvoid *)data);
     
        // when texture area is small, bilinear filter the closest mipmap
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
        // when texture area is large, bilinear filter the first mipmap
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
     
        // texture should tile
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
        glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
     
        // build our texture mipmaps
        //gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
     
        // free buffer
        free(data);
     
    }
    and here's my walls:
    Code :
    void drawWalls(int i,  int j) {
     
    	GLfloat v[][3] = {{i * BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, 0},
    		{i * BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, WALL_HEIGHT},
    		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, WALL_HEIGHT},
    		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, 0},
    		{i * BLOCK_SIZE, j * BLOCK_SIZE, 0},
    		{i * BLOCK_SIZE, j * BLOCK_SIZE, WALL_HEIGHT},
    		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE, WALL_HEIGHT},
    		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE, 0}};
     
    	polygon(v[0], v[3], v[2], v[1]);
        polygon(v[2], v[3], v[7], v[6]);
        polygon(v[4], v[5], v[6], v[7]);
        polygon(v[0], v[1], v[5], v[4]);
    }
     
    void polygon(GLfloat* a, GLfloat* b, GLfloat* c, GLfloat* d)
    {
        //glGenTextures(1, &texture);
        //glBindTexture(GL_TEXTURE_2D, texture);
        glEnable(GL_TEXTURE_2D);
        glBegin(GL_POLYGON);
          glColor3f(0, 0, 1);
        glNormal3f(0.0f, 1.0f, 0.0f);
        glTexCoord2d(0.0,0.0);
          glVertex3fv(a);
        glTexCoord2d(0.0,1.0);
          glVertex3fv(b);
        glTexCoord2d(1.0,1.0);
          glVertex3fv(c);
        glTexCoord2d(1.0,0.0);
          glVertex3fv(d);
        glEnd();
        glDisable(GL_TEXTURE_2D);
    }
    What in the.....????!!

  2. #2
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Texturing looks funky (and not in a good way)

    the bricks are in different directions on different sides of the polygon ...
    Could u show us a snapshot of what you are getting?

    Just a side note here, GL_DECAL cannot be used for mini/magnification filtering. It is used with the glTexEnv so I think you should remove these calls.
    Code :
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
    //glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
    Regards,
    Mobeen

  3. #3
    Junior Member Newbie
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    15

    Re: Texturing looks funky (and not in a good way)

    ooops! lol attached is my screen shot.
    What in the.....????!!

  4. #4
    Senior Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Karachi, Pakistan
    Posts
    810

    Re: Texturing looks funky (and not in a good way)

    Either your texture coordinates are incorrect for those walls or the vertices are not given in the correct winding order. Recheck your code.

    The simplest approach to debug for texture mapping errors is to disable texturing and simply set the texture coordinates as color. If the tex. coords. are fine, you should have a continuous gradient for the whole scene. Identify the walls where there are discontinuities in the texture coordinates and correct them.

    For a simpler solution, I think you should see the wrongly ordered polygons and correct their winding.
    Regards,
    Mobeen

  5. #5
    Junior Member Newbie
    Join Date
    Oct 2011
    Location
    New Jersey
    Posts
    15

    Re: Texturing looks funky (and not in a good way)

    ok. Thanks a lot.
    What in the.....????!!

Similar Threads

  1. Multi-Texturing and .... normal texturing?
    By Andy Gilbert in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 04-06-2010, 05:30 PM
  2. funky problem with NPOT 3D texture
    By hifuGL in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 01-20-2006, 11:08 AM
  3. funky lines on my objects
    By chester in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 11-26-2002, 12:38 PM
  4. funky lines on the surfaces of my objects
    By chester in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 11-15-2002, 12:47 PM
  5. Terrain texturing, any nice,fast,good ideas ?
    By vic in forum OpenGL: Advanced Coding
    Replies: 5
    Last Post: 11-09-2000, 10:08 AM

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