Results 1 to 7 of 7

Thread: Texture distortion at bigger object size

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

    Texture distortion at bigger object size

    Hello, I have a slight problem with textures that I can't seem to figure out on my own.

    I created a sphere using gluSphere() which I then textured to look like Earth. At first it was small(1.0f radius) and it looked fine, then I decided to change my scale so each unit in the coordinate system represents 1 meter. I therefore rendered a sphere with a radius of 6371000.0 and this is where the problem comes in:

    For some reason, the texture is distorted in a sense that it's too big and only part of it is applied to the sphere. For example, whereas Antarctica normally takes up maybe 1/4 of the sphere's side if you look at it from a 90 degree angle, it now takes up over half the sphere instead. I have tried playing with the various texture parameters but have thus far had no success with solving this problem. Any help would be greatly appreciated. Rendering code below:

    EDIT: If it helps, the texture image is JPG format and is 4096x2048 in size

    Code :
            gluPerspective(50.0*zoomFactor, (GLfloat) w/(GLfloat) h, 2.0, 2000000000000000000000.0);
     
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	glMatrixMode(GL_MODELVIEW);
    	glLoadIdentity();
    	gluLookAt(18000000.0, 0.0, 0.0, 6500000.0, 0.0, 0.0, 0.0, 1.0, 0.0);
    	glRotatef((GLfloat) rotation, 0.0, 1.0, 0.0);
            glLightfv(GL_LIGHT0,GL_POSITION,light_position);	
     
    	cout<<"rotation: "<<test<<endl;
    	glColor3ubv(earthColor);
     
            glGenTextures(1, &amp;texID);
    	glBindTexture(GL_TEXTURE_2D, texID);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    	glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA, w, h, 0, GL_RGBA,GL_UNSIGNED_BYTE,textura );
     
     
    	glEnable(GL_TEXTURE_2D);
     
    	glBindTexture ( GL_TEXTURE_2D, texID);
    	sphere = gluNewQuadric();
    	gluQuadricDrawStyle( sphere, GLU_FILL);
    	gluQuadricNormals( sphere, GLU_SMOOTH);
    	gluQuadricOrientation( sphere, GLU_OUTSIDE);
    	gluQuadricTexture( sphere, GL_TRUE);
     
    	//glColor3f(0.0, 1.0, 0.0);
    	gluSphere( sphere, 6371000, 50, 40);
    	//gluSphere( sphere, 0.2, 50, 40);
     
    	glDisable(GL_TEXTURE_2D);

    As you can see in the below image, Antarctica looks abnormally large:



    And this is what it should look like:


  2. #2
    Super Moderator OpenGL Guru imported_dorbie's Avatar
    Join Date
    Jul 2000
    Location
    Bay Area, CA, USA
    Posts
    3,966

    Re: Texture distortion at bigger object size

    Isn't this a simple perspective problem. i.e. the appearance of the texture is determined by the position of the eye relative to the size of the sphere and antartica looks large because you are closer and australia and south africa are over the horizon....?

    I don't see a projection being set, just a lookat so if projection is sized based on the object (which I'll bet it is) then you should see exactly what you see.

    i.e. you keep the eye in the same place and make the sphere larger, so it gets bigger, but you then adjust the perspective (not shown in code) to make the whole thing visible. So all you see is the texture expand and shrink on a changing portion of the visible sphere.

  3. #3
    Newbie OpenGL Pro
    Join Date
    Jan 2007
    Posts
    1,789

    Re: Texture distortion at bigger object size

    Incidentally, if you're generating new texture and quadric objects each frame in your draw function you've got a serious memory leak problem, as well as something that's going to impair performance.

  4. #4
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    10

    Re: Texture distortion at bigger object size

    Ah, I apologize for not posting that line, but I am not changing perspective at all unless I am zooming in/out which I didn't do in this case:

    gluPerspective(50.0*zoomFactor, (GLfloat) w/(GLfloat) h, 2.0, 2000000000000000000000.0);

    That is my perspective setting, zoomfactor can be anything between 0.1 and 3.0, but I did not change it in this instance so the FoV is 50.

    The way I actually bring the sphere into view is by translating the eye position, hence why the large X eye coordinate in gluLookAt();

    Thank you for the response!

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

    Re: Texture distortion at bigger object size

    Quote Originally Posted by mhagain
    Incidentally, if you're generating new texture and quadric objects each frame in your draw function you've got a serious memory leak problem, as well as something that's going to impair performance.
    The texture isn't being generated each frame, I just compressed the code for easier viewing. As for the quadric object, I shall fix that, thank you for the heads up!

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    10

    Re: Texture distortion at bigger object size

    Either way, I still haven't been able to solve the problem. Dorbie's suggestion would have made sense were I actually manipulating the perspective, but I am not. I am merely moving the eye coordinates further away from the sphere to get a good view, so the textures should not look distorted.. Or is there somekind of little illusion caveat I'm missing here that is related to big objects and eye coordinates?

    Both the screenshots posted above are at the same perspective settings, the only difference is X position of the eye(gluLookAt) and of course, the size of the sphere

  7. #7
    Junior Member Newbie
    Join Date
    Mar 2011
    Posts
    10

    Re: Texture distortion at bigger object size

    I figured it out now!

    It was a simple matter of still having the eye coordinates too close to the sphere. I had them about 3x the radius away, when I set it to 6x the radius instead(eye X of about 36000000), everything looks fine now.

    I can now use perspective change to zoom and the texture remains intact.

    This is what Dorbie was trying to tell me but I didn't figure it out at first. At least I understand it now! I thought it was a texturing problem.

    Thank you very much for your help!

Similar Threads

  1. Image not rsizing properly when window get bigger than initial size
    By bigefrom84 in forum OpenGL: Basic Coding
    Replies: 6
    Last Post: 12-10-2014, 06:49 AM
  2. copy part of a texture to another bigger one
    By LR123 in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 09-06-2009, 02:52 PM
  3. Rotation problems (object distortion)
    By Tindor in forum OpenGL: Basic Coding
    Replies: 5
    Last Post: 12-18-2006, 11:04 AM
  4. rotating texture bigger than viewport
    By pfmaynard in forum OpenGL: General
    Replies: 1
    Last Post: 04-30-2004, 03:18 PM
  5. Replies: 3
    Last Post: 09-14-2000, 11:46 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