PDA

View Full Version : More texture problems: here we go....again!



gui24a
08-23-2008, 09:04 PM
Hello again friends.

I was just trying to map a texture to a glut solid sphere using automatic texture coordinates. After some hours studying, I realize this won't be so easy (holy sh*t!! there is no ease way with gfx!). The way to go right is using cube map, but I'm struggling to figure out how the hell this thing work!

After loading a texture and building it with gluMipmap2D, I just set the following lines of code before drawing the sphere:



glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_NORMAL_MAP);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);

//Do I really need the R coordinate???
glEnable(GL_TEXTURE_GEN_R);

glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRA P_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRA P_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRA P_R,GL_REPEAT);

glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MAG _FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_MIN _FILTER,GL_LINEAR_MIPMAP_LINEAR);

glEnable(GL_TEXTURE_CUBE_MAP);
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, TextEstrada);

glutSolidSphere(10,32,16);

The problem is as follows:

http://img47.imageshack.us/img47/3113/sidenz1.th.jpg (http://img47.imageshack.us/my.php?image=sidenz1.jpg)

this is Mars, lol. I can see the side of Mars, until...

http://img58.imageshack.us/img58/773/facingmeis5.th.jpg (http://img58.imageshack.us/my.php?image=facingmeis5.jpg)

...I turn the camera! The texture is always facing me!

PS> I didn't set the 6 sides for the textures 'cause I tried this and I had a problem, the render got crazy and the problem above didn't go.

Regards!

ZbuffeR
08-24-2008, 02:17 AM
try with this instead :
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

gui24a
08-24-2008, 09:33 AM
Same thing. :(

gui24a
08-24-2008, 10:36 AM
I just want to texture a torus or a sphere. Is this the correct way to do using automatic texture generation?

V-man
08-24-2008, 03:50 PM
Are you going to apply a cubemap or a 2D texture?
You are calling


glEnable(GL_TEXTURE_CUBE_MAP);
glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, TextEstrada);


If it is for cubemap, then you MUST bind a cubemap.

dorbie
08-25-2008, 11:14 AM
It's probably tricky to get a cubemap Mars image to apply. In addition things suggested like spheremap texgen happen in eyespace and you want an object space mapping so the texture moves with the planet. You could do this with a cubemap, but you'd be as well just drawing a sphere conventionally with polar coordinates mapping a lat/long image from NASA, unless you're concerned about extreme anisotropy at the poles.

So I suggest you make your own sphere and map your own coordinate, read the following tutorial:

http://www.swiftless.com/tutorials/opengl/sphere.html

dorbie
08-25-2008, 11:30 AM
P.S. I think a glut sphere may map polar coords anyway in which case you need only bind a lat/long texture image.