Sphere texturing problem

Im having a problem using the lwjgl library (opengl).
Whem im trying to texture a sphere i get some strange behaviour.

The texture seems to move backwards around the sphere sometimes.
This happens when the rotation angle < 90 or > 270, but i cant find any reason why.
The texture is 1024 x 512 pixels.

The left part of the sphere is rotating to the right like it should, but the right part seems to wrap around it, moving to the left.

Drawing:

        GL11.glClear( GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT );
        
        if(text != null){ text.Bind(); }
        
        GL11.glPushMatrix();
            GL11.glTranslatef(231,223,-300);
            GL11.glRotatef(90,1,0,0);
            GL11.glRotatef(rotate, 0,0,1);
            

            GL11.glColor4f(1,1,1,1);
            Sphere s = new Sphere();
            s.setDrawStyle(GLU.GLU_FILL);
            s.setNormals(GLU.GLU_SMOOTH);
            s.setOrientation(GLU.GLU_OUTSIDE);
            if(text != null){ s.setTextureFlag(true); }
            s.draw(200, 50, 50);
        GL11.glPopMatrix();

Init:

    protected void initGL() 
    {
        GL11.glViewport(0, 0, 463, 446);                       // Reset The Current Viewport And Perspective Transformation
        GL11.glMatrixMode(GL11.GL_PROJECTION);                           // Select The Projection Matrix
        GL11.glLoadIdentity();                                      // Reset The Projection Matrix
        GLU.gluPerspective(45, 463 / 446, -1000, 1000);  // Calculate The Aspect Ratio Of The Window

        
        GL11.glClearColor( 0.0f, 0.0f, 0.0f, 1.0f );
        GL11.glClearDepth( 1.0f );
        GL11.glDepthFunc( GL11.GL_ALWAYS );
        GL11.glHint( GL11.GL_PERSPECTIVE_CORRECTION_HINT,GL11.GL_NICEST );
        GL11.glHint( GL11.GL_LINE_SMOOTH_HINT, GL11.GL_DONT_CARE );
        GL11.glEnable( GL11.GL_TEXTURE_2D );

        
        GL11.glLoadIdentity(); 
        GL11.glOrtho(0, 463, 446, 0, -1000, 0); 
        GL11.glDisable(GL11.GL_DEPTH_TEST); 
        GL11.glMatrixMode(GL11.GL_MODELVIEW); 
        GL11.glLoadIdentity();
    }

Fixed it after serveral hours of cursing ;D ;D ;D

For fellow programmers coming here, the following line inside the initialisation of opengl, add this line:

GL11.glEnable(GL11.GL_CULL_FACE); 

The problem was the sphere was drawing the front and back face at the same layer (because of 2D mode i guess).

Hehe :slight_smile:

Consider doing import static org.lwjgl.opengl.GL11.* to get rid of all that crappy GL11.* prefixing.

Cas :slight_smile:

This should have fixed it:

glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);

Leave the Cull face code there. It’s a good optimization :slight_smile:
But you will get more problems with object not drawing in the right order, when not enabling depth test…

Depth testing kinda messes up 2d view.
This was all i was trying to archive, so depth testing is not needed here :slight_smile:

Thanks for the replies anyways.

Wow! That is impressive…

Okey I know that you archieved what you wanted… but it isn’t really solving the problem :smiley: (It’s somehow a side-effect of the Culling…)

I think you have to change the near and far planes from the glOrtho matrix setup…

so you don’t use -1 and 1 for near and far plane, but -20 and 20 or something like that (I think… I haven’t tested that…)

Haha thanks, its just some sphere-mapping and simplex noise, not hard to do really.
Takes alot of trys to create something just right, thats why i made this simple animation app.
The game where im going to use the algorithms is 3d and will be optimized (need to write some engine to zoom into planets / stars without rendering the rest of the globe).

I could position the glow and stuff right, but why waste processing power with extra transformations and depth testing, the app will stay 2D since its just for testing the algorithms.
The globe is drawn using GLUT with a simple 400x400x400 sphere.
So anything under -200 / 200 will be cut of like this image (-100 / 100):