PDA

View Full Version : smooth texture mapping on sphere



HarryB
03-05-2005, 12:08 AM
Hi,
I have a problem with texture mapping on a sphere: I can't get the shading to be smooth at the polygon edges. I use the commands

glTexImage2D(GL_TEXTURE_2D,0,3,p_dib->Width(),p_dib->Height(),0,GL_BGR_EXT,GL_UNSIGNED_BYTE,(GLvoid *)p_dib->GetBits());
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);//GL_DECAL);
glEnable( GL_TEXTURE_2D );

and then map the bitmap on the polygons of the wireframe sphere. It looks good until I zoom in. Then I can distinguish the individual polygon shapes, which I don't want.
Can anybody give me a hint on how to get the mapping smooth?
Thanks in advance,
Harry

03-05-2005, 01:40 AM
I assume you are already using smoothshading and provide proper normals. That you still see the edges means your tesselation is way to low, this hasnt anything to do with texturemapping, only with Gouraud shading and the detail level of your object.

See common OpenGL pitfall #2

http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/

Please post any future coding related questions
in the proper forum: "OpenGL coding: beginners".

03-05-2005, 01:47 AM
Ahhh now I got it, by saying "Then I can distinguish the individual polygon shapes, which I don't want." you mean that you can see the egde if each texel in the texturemap and you want bilinear filtering. In this case you want to change the following lines of code:


glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);to this:


glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);