Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Sphere texturing problem  (Read 1608 times)
0 Members and 1 Guest are viewing this topic.
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Posted 2012-09-21 21:47:40 »

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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
        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:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
    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();
    }
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #1 - Posted 2012-09-22 17:52:47 »

Fixed it  after serveral hours of cursing Grin Grin Grin

For fellow programmers coming here, the following line inside the initialisation of opengl, add this line:
1  
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).
Offline princec

JGO Kernel


Medals: 386
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #2 - Posted 2012-09-22 21:26:08 »

Hehe Smiley

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

Cas Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #3 - Posted 2012-09-23 11:50:34 »

This should have fixed it:

1  
2  
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);


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

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #4 - Posted 2012-09-24 18:50:08 »

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



Thanks for the replies anyways.
Offline matheus23

JGO Kernel


Medals: 108
Projects: 3


You think about my Avatar right now!


« Reply #5 - Posted 2012-09-24 20:12:26 »

Wow! That is impressive...

Okey I know that you archieved what you wanted... but it isn't really solving the problem Cheesy (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...)

See my:
    My development Blog:     | Or look at my RPG | Or simply my coding
http://matheusdev.tumblr.comRuins of Revenge  |      On Github
Offline RobinB

JGO Ninja


Medals: 44
Projects: 1
Exp: 3 years


Spacegame in progress


« Reply #6 - Posted 2012-09-24 20:32:45 »

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):
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!