PDA

View Full Version : Moving Texture and Stack Order



VASIMR
04-28-2011, 04:27 PM
Hi,

I am having two issues with some OpenGL code.

One is moving textures on a gluSphere. What I mean by this is, as the camera or object moves around, the texture seems to rotate on the surface so that one point is always looking at the camera. My code is as follows.



GLUquadricObj *sphere = gluNewQuadric();
gluQuadricDrawStyle(sphere, GLU_FILL);
gluQuadricTexture(sphere, TRUE);
gluQuadricNormals(sphere, GLU_SMOOTH);
glBindTexture(GL_TEXTURE_2D, SystemTexture[SROCKY] );
gluSphere(sphere, SMALL_PLANET_RADIUS, STAR_SEGMENTS, STAR_SEGMENTS);
gluDeleteQuadric(sphere);


The other problem that I am having is with the render order. Is there a function or an algorithm to make objects that are further away from the camera render behind closer objects, given that the camera can move?

I apologize if the questions have already been answered, if that is the case, please point me in the right direction.
Thanks!

Kelvin
04-28-2011, 09:07 PM
Is there a function or an algorithm to make objects that are further away from the camera render behind closer objects, given that the camera can move?

You have two basic options:

1. Sort the objects yourself so that you always draw them in order from far to near (or near to far, depending on your blending mode).
2. Use the depth buffer to automatically perform per-pixel depth testing (only closest pixel is shown). The depth test works well for for most situations.

BionicBytes
04-29-2011, 01:32 PM
One is moving textures on a gluSphere. What I mean by this is, as the camera or object moves around, the texture seems to rotate on the surface so that one point is always looking at the camera. My code is as follows.

How are you texturing the sphere?
GlTexGen ? Shaders ?

VASIMR
04-30-2011, 11:19 AM
How are you texturing the sphere?
GlTexGen ? Shaders ?

I am not exactly sure... I added code that was in several examples that contained texture mapping. I think this may be what you are asking though, I call these function before loading the textures.


glEnable ( GL_COLOR_MATERIAL );
glColorMaterial ( GL_FRONT, GL_AMBIENT_AND_DIFFUSE );
glEnable ( GL_TEXTURE_2D );
glPixelStorei ( GL_UNPACK_ALIGNMENT, NUM_SYSTEM_TEXTURES );
glGenTextures (NUM_SYSTEM_TEXTURES, SystemTexture);


Using the Depth test seems to make the textures stay stationary on the spheres (I did not have this problem with just quads), however they now do this strange looping thing, where it seems like when the spheres rotate 180 degrees, the textures sort of fragments and then reappears.

Dan Bartlett
04-30-2011, 12:50 PM
this line:

glPixelStorei ( GL_UNPACK_ALIGNMENT, NUM_SYSTEM_TEXTURES );
is wrong, look up in the spec what effect setting GL_UNPACK_ALIGNMENT has, but it's likely that you would want to be setting it to 1 or 4, rather than to NUM_SYSTEM_TEXTURES.

BionicBytes
04-30-2011, 01:03 PM
gluQuadricTexture(sphere, ......

This is generating the texture coordinates for your sphere.

Check your pixel unpack alignment code as it has been pointed out.