PDA

View Full Version : Texture distortion at bigger object size



Garanixx
04-19-2011, 09:37 AM
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



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:

http://i166.photobucket.com/albums/u95/garanixx/sizedEarth.jpg

And this is what it should look like:

http://i166.photobucket.com/albums/u95/garanixx/NormalEarth.jpg

dorbie
04-19-2011, 10:51 AM
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.

mhagain
04-19-2011, 11:29 AM
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.

Garanixx
04-19-2011, 11:30 AM
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!

Garanixx
04-19-2011, 11:33 AM
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!

Garanixx
04-19-2011, 12:30 PM
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

Garanixx
04-19-2011, 12:44 PM
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! :D