More texture problems: here we go....again!

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_WRAP_S,GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_T,GL_REPEAT);
glTexParameteri(GL_TEXTURE_CUBE_MAP,GL_TEXTURE_WRAP_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:

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

…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!

try with this instead :
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);

Same thing. :frowning:

I just want to texture a torus or a sphere. Is this the correct way to do using automatic texture generation?

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.

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

P.S. I think a glut sphere may map polar coords anyway in which case you need only bind a lat/long texture image.