Results 1 to 4 of 4

Thread: Texture mapping non-smoothing

  1. #1
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    6

    Texture mapping non-smoothing

    Dears,

    I have a question on texture mapping using OpenGL. I have tried to texture map a photo onto a sphere hoping that it could have a more realistic metalic looking.
    I mapped each texture to each sphere but there is something looking not smooth just like the first shown picture below.
    I hope to have the result like the second picture shown below but I cannot figure out where the problem is. The texture mapping code list here:
    Code :
     //Part of the code: To generate the texture
     
                                    QPixmap pixmap(materialFileName);
                                    glGenTextures(1, &ID);      
                                    glBindTexture(GL_TEXTURE_2D, ID);  
                                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
                                    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_LINEAR);
                                    QImage tx = this->convertToGLFormat(pixmap.toImage());
                                    gluBuild2DMipmaps(GL_TEXTURE_2D, 4, tx.width(), tx.height(), GL_RGBA, GL_UNSIGNED_BYTE, tx.bits());
     
     
                                    //Not continue from above
                                    //Part of the code: To bind the texture
                                    glEnable(GL_TEXTURE_2D);    //enable texture mapping 
                    glEnable(GL_TEXTURE_GEN_S); 
                    glEnable(GL_TEXTURE_GEN_T); 
                    glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); //Preset the texture mapping mode 
                    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
                    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP); 
                    glBindTexture (GL_TEXTURE_2D, _it->front()->getTextureId()); 
                    drawSomething();                                                                                                        //The place to draw the sphere 
                    glDisable(GL_TEXTURE_GEN_S);//disable texture generate 
                    glDisable(GL_TEXTURE_GEN_T); 
                    glDisable(GL_TEXTURE_2D);    //disable texture mapping

    Can anyone help and explain?


  2. #2
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,672

    Re: Texture mapping non-smoothing

    Can anyone help and explain?
    2D textures are squares (technically rectangles). Spheres are... well, spheres. There is no method by which you can map a rectangle onto a sphere with no distortion.

    This is why every flat map of the Earth has some distortion relative to an actual globe.

    The best you can do is use a cubemap, which is 6 2D images. Now, there will still be some distortion, but it will be very slight compared to what you have now.

  3. #3
    Junior Member Newbie
    Join Date
    May 2011
    Posts
    6

    Re: Texture mapping non-smoothing

    Thanks Alfonse, I get your point.

    Yet the second picture is obtained from a program written by other person like(Our teacher)=.=.

    I was asked to redo the same result by using OpenGL's texture mapping, but the first figure>.<

    So Im wondering why that person can but me with similar opengl libraries.

  4. #4
    Senior Member OpenGL Lord
    Join Date
    Mar 2015
    Posts
    6,672

    Re: Texture mapping non-smoothing

    So Im wondering why that person can but me with similar opengl libraries.
    Probably because they were not applying the texture to the sphere with sphere mapping.

    The texture you're using is intended to be a reflection of the surrounding environment, correct? This means that the texture coordinates need to be generated by performing reflection computations based on the camera.

    This would not introduce the kinds of distortions you were getting, but nor would it represent an actual reflection. It wouldn't really be a reflection, but it would look kind of like one.

    I honestly don't remember what the texture coordinate generation settings for that would be, but you could probably find them on the man pages by looking up the legal values for glTexGeni.

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. Smoothing of Circles using Texture Mapping
    By Aravi in forum OpenGL: Basic Coding
    Replies: 8
    Last Post: 07-16-2010, 04:39 PM
  4. FBO, texture smoothing
    By kewuwsi in forum OpenGL: Advanced Coding
    Replies: 10
    Last Post: 01-28-2008, 05:48 AM
  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