Results 1 to 6 of 6

Thread: Moving Texture and Stack Order

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    USA
    Posts
    17

    Moving Texture and Stack Order

    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.

    Code :
    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!

  2. #2
    Member Contributor
    Join Date
    Sep 2009
    Posts
    55

    Re: Moving Texture and Stack 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?
    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.

  3. #3
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Moving Texture and Stack Order

    Quote Originally Posted by VASIMR
    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 ?

  4. #4
    Junior Member Newbie
    Join Date
    Apr 2011
    Location
    USA
    Posts
    17

    Re: Moving Texture and Stack Order

    Quote Originally Posted by BionicBytes
    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.
    Code :
    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.

  5. #5
    Senior Member Regular Contributor
    Join Date
    Oct 2009
    Posts
    463

    Re: Moving Texture and Stack Order

    this line:
    Code :
    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.

  6. #6
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,161

    Re: Moving Texture and Stack Order

    Code :
    gluQuadricTexture(sphere, ......
    This is generating the texture coordinates for your sphere.

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

Similar Threads

  1. rotate 2D texture/stack of 2D textures
    By ananananda in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-14-2014, 05:19 PM
  2. Using matrix stack - my code seems to modify the whole stack
    By chromosom in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 06-04-2014, 03:12 AM
  3. 3D Texture or stack of 2D Textures
    By iris_raj in forum OpenGL: Advanced Coding
    Replies: 4
    Last Post: 05-02-2007, 05:21 AM
  4. texture order
    By hwj_just in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-23-2005, 10:45 PM
  5. Texture Matrix - one stack for each unit?
    By Robbo in forum OpenGL: Advanced Coding
    Replies: 2
    Last Post: 07-31-2002, 04:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean