Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (481)
Games in Android Showcase (110)
games submitted by our members
Games in WIP (547)
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  
  Culling or Geometry Problems  (Read 1366 times)
0 Members and 1 Guest are viewing this topic.
Offline nickdotjava

Junior Member




I have fallen to the dark side.  I'm using DX9


« Posted 2003-06-24 02:00:25 »

My understanding of Culling is that if something opaque is in front of something else, whatever is in the back will not be drawn.  If this is correct, I'm having problems with the triangle fan.  It can be seen through some shapes, but not through others.  I've shown the drawing code below, and linked to the full code (which includes rotation via the arrow keys, and reset with the space bar) here:  http://www.theouterrim.net/Test1.java  Would someone please tell me what I'm missing in the geometry here?  Thanks.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
    protected boolean drawGLScene(float frameTime)
    {
        /* Clear The Screen And The Depth Buffer */
        gl.clear(GL.COLOR_BUFFER_BIT | GL.DEPTH_BUFFER_BIT);
        /* Reset The Current Modelview Matrix */
        gl.loadIdentity();
        
        gl.rotatef(angleRotateX, 1.0f, 0.0f, 0.0f);
        gl.rotatef(angleRotateY, 0.0f, 1.0f, 0.0f);
        gl.polygonMode(GL.FRONT_AND_BACK, GL.LINE);
        gl.enable(GL.CULL_FACE);
        gl.frontFace(GL.CW);
        gl.color3f(0.0f, 0.0f, 1.0f);
        gl.begin(GL.TRIANGLE_FAN);
            gl.vertex3f(20.0f, 30.0f, 200.0f);
            gl.vertex3f(20.0f, 40.0f, 0.0f);
            gl.vertex3f(60.0f, 30.0f, -20.0f);
            gl.vertex3f(40.0f, -20.0f, -10.0f);
            gl.vertex3f(20.0f, 40.0f, 0.0f);
        gl.end();
        
        gl.begin(GL.TRIANGLE_FAN);
            gl.vertex3f(-20.0f, 30.0f, 200.0f);
            gl.vertex3f(-40.0f, -20.0f, -10.0f);
            gl.vertex3f(-60.0f, 30.0f, -20.0f);
            gl.vertex3f(-20.0f, 40.0f, 0.0f);
            gl.vertex3f(-40.0f, -20.0f, -10.0f);
        gl.end();
        
        gl.begin(GL.POLYGON);
            gl.vertex3f(-20.0f, 40.0f, 0.0f);
            gl.vertex3f(-60.0f, 30.0f, -20.0f);
            gl.vertex3f(0.0f, 40.0f, -70.0f);
            gl.vertex3f(60.0f, 30.0f, -20.0f);
            gl.vertex3f(20.0f, 40.0f, 0.0f);
        gl.end();
        
        gl.begin(GL.POLYGON);
            gl.vertex3f(40.0f, -20.0f, -10.0f);
            gl.vertex3f(20.0f, -20.0f, -60.0f);
            gl.vertex3f(-20.0f, -20.0f, -60.0f);
            gl.vertex3f(-40.0f, -20.0f, -10.0f);
            gl.vertex3f(40.0f, -20.0f, -10.0f);
        gl.end();
        
        gl.begin(GL.TRIANGLE_STRIP);
            gl.vertex3f(40.0f, -20.0f, -10.0f);
            gl.vertex3f(60.0f, 30.0f, -20.0f);
            gl.vertex3f(20.0f, -20.0f, -60.0f);
            gl.vertex3f(0.0f, 40.0f, -70.0f);
            gl.vertex3f(-20.0f, -20.0f, -60.0f);
            gl.vertex3f(-60.0f, 30.0f, -20.0f);
            gl.vertex3f(-40.0f, -20.0f, -10.0f);
        gl.end();
        
        gl.begin(GL.POLYGON);
            gl.vertex3f(-20.0f, 40.0f, 0.0f);
            gl.vertex3f(20.0f, 40.0f, 0.0f);
            gl.vertex3f(40.0f, -20.0f, -10.0f);
            gl.vertex3f(-40.0f, -20.0f, -10.0f);
        gl.end();
        
        return true;
    }

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #1 - Posted 2003-06-24 09:42:45 »

Not drawing objects that are obscured by other objects is sometimes called "z-buffering" or "occlusion culling", but in OpenGL it is called "depth testing".

The "face culling" methods in OpenGL are a fast way of eliminating polygons that can't be seen - if a polygon is facing away from the camera it can just be ignored.


As to why the triangle fan isn't being depth tested correctly, you're clearing the depth buffer to 1.0f, not the more usual 0.0f and you're specifying a 0 bit depth buffer (in the GL constructor).  If you fix those two, the depth-buffering should work correctly.


Just as a warning, you're pushing more matrices than you're popping! Wink  Your resizeGLScene method pushes both the projection and modelling matrices, but nothing in the program pops them again.  As the projection matrix stack may only be two deep, calling resizeGLScene twice may cause OpenGL to error.  You're not storing the matrixes for any reason, and just loadIdentity straight after, so it's probably worth just deleting those lines.

Hellomynameis Charlie Dobbie.
Offline nickdotjava

Junior Member




I have fallen to the dark side.  I'm using DX9


« Reply #2 - Posted 2003-06-24 14:23:44 »

So you're saying that I should change the line:
gl.clearDepth(1.0f);
to:
gl.clearDepth(0.0f);

What should I change the bit depth buffer, specified in the constructor, to?

If I just change gl.clearDepth(1.0f); to gl.clearDepth(0.0f);, then nothing is drawn.

For the resizeGLScene, could you please give me specific line numbers?  When I start changing things, nothing gets drawn.  However, if you mean just removing the push statement, I've removed those and my program still draws.

Thanks.

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #3 - Posted 2003-06-24 15:21:51 »

Quote
So you're saying that I should change the line:
gl.clearDepth(1.0f);
to:
gl.clearDepth(0.0f);

Sorry, hang on, I'm going mad...  No, 1.0f is the default, you're quite right.  Where did I get that from? Roll Eyes  I've got my buffers inside out... Lips Sealed

Quote
What should I change the bit depth buffer, specified in the constructor, to?

Anything non-zero really.  8 bits would probably suffice.

Quote
For the resizeGLScene, could you please give me specific line numbers?  When I start changing things, nothing gets drawn.  However, if you mean just removing the push statement, I've removed those and my program still draws.

Whenever you have a pushMatrix statement, there should be a corresponding popMatrix at some point.  The matrix stacks aren't infinitely large, and the projection matrix in particular need only be two deep by the OpenGL spec.  You'd usually need to pushMatrix if you were about to do something destructive to the current matrix but want to get the current one back later.

So yep, just remove the pushMatrix calls in the resizeGLScene method.  The program will still work as expected, but you save yourself a nasty bug further down the line! Wink

Hellomynameis Charlie Dobbie.
Offline nickdotjava

Junior Member




I have fallen to the dark side.  I'm using DX9


« Reply #4 - Posted 2003-06-24 16:56:01 »

hmmm...  That didn't solve it.  I can still see some of it.  Since that is about 1/3rd the polygons, this will have some performance issues.  Would you advise switching to plain triangles instead of strips?  Because the regular polygons aren't giving me any trouble.

Now I'm onto curves.  Everything draws more or less correctly, except if you run the code I've provided, on the right side, the top and the side do not meet.  This is strange, since they should be the exact same locations.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
gl.translatef(15.0f, 36.5f, -20.0f);
        //gl.polygonMode(GL.FRONT_AND_BACK, GL.FILL);
       gl.begin(GL.POLYGON);
            for(int i=90; i>=0; i--)
            {
                  gl.vertex3f(0.0f, (float)(org.lwjgl.Math.sin(i)*15.0f), (float)(org.lwjgl.Math.cos(i)*(-37.5f)));
            }
            gl.translatef(0.0f, -1.5f, 0.0f);
            for(int i=0; i<=90; i++)
            {
                  gl.vertex3f(0.0f, (float)(org.lwjgl.Math.sin(i)*10.0f), (float)(org.lwjgl.Math.cos(i)*(-30.0f)));
            }
        gl.end();
        
        gl.translatef(-30.0f, 1.5f, 0.0f);
        
        gl.begin(GL.POLYGON);
            for(int i=0; i<=90; i++)
            {
                  gl.vertex3f(0.0f, (float)(org.lwjgl.Math.sin(i)*15.0f), (float)(org.lwjgl.Math.cos(i)*(-37.5f)));
            }
            gl.translatef(0.0f, -1.5f, 0.0f);
            for(int i=90; i>=0; i--)
            {
                  gl.vertex3f(0.0f, (float)(org.lwjgl.Math.sin(i)*10.0f), (float)(org.lwjgl.Math.cos(i)*(-30.0f)));
            }
            
        gl.end();
            
            gl.begin(GL.POLYGON);
                  for(int i=0; i<=90; i++)
                 {
                       gl.vertex3f(0.0f, (float)(org.lwjgl.Math.sin(i)*10.0f), (float)(org.lwjgl.Math.cos(i)*(-30.0f)));
                 }
              //gl.translatef(0.0f, 0.0f, 0.0f);    
                for(int i=90; i>=0; i--)
                 {
                       gl.vertex3f(30.0f, (float)(org.lwjgl.Math.sin(i)*10.0f), (float)(org.lwjgl.Math.cos(i)*(-30.0f)));
                 }
            gl.end();
            
            gl.translatef(0.0f, 1.5f, 0.0f);
            gl.begin(GL.POLYGON);
                  for(int i=90; i>=0; i--)
                 {
                       gl.vertex3f(0.0f, (float)(org.lwjgl.Math.sin(i)*15.0f), (float)(org.lwjgl.Math.cos(i)*(-37.5f)));
                 }
                 for(int i=0; i<=90; i++)
                 {
                       gl.vertex3f(31.0f, (float)(org.lwjgl.Math.sin(i)*15.0f), (float)(org.lwjgl.Math.cos(i)*(-37.5f)));
                 }
            gl.end();


Edit: Sorry for the wierd tabbing.  I can't get this thing to display it perfectly.

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Offline nickdotjava

Junior Member




I have fallen to the dark side. &nbsp;I'm using DX9


« Reply #5 - Posted 2003-06-24 18:03:28 »

Nevermind, I fixed it.  It has something to do with my translate calls.  Not sure what, but I removed to translate calls within the gl.begin and gl.end and edited the values.  For some reason, that fixed it.  Can't translate calls be put within a gl.begin/gl.end?

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
Offline cfmdobbie

Senior Member


Medals: 1


Who, me?


« Reply #6 - Posted 2003-06-25 22:48:52 »

Quote
Can't translate calls be put within a gl.begin/gl.end?


Ah, no.  The only commands valid between a glBegin and a glEnd are as follows:


  • glVertex*
  • glColor*
  • glIndex*
  • glNormal*
  • glEvalCoord*
  • glTexCoord*
  • glEdgeFlag*
  • glMaterial*
  • glCallList(s)


While within a begin/end pair you're supposed to be defining vertices to make up an OpenGL primitive of some kind.  Anything that isn't directly concerned with this process or changes the context in which those vertex calls are made is disallowed.

Hellomynameis Charlie Dobbie.
Offline nickdotjava

Junior Member




I have fallen to the dark side. &nbsp;I'm using DX9


« Reply #7 - Posted 2003-06-25 23:04:24 »

grr...  argh...  How do I make requests for the next OpenGL specification?  j/k   Grin

-Nick

"Oh ya, that's trivial.  I should have it done in an hour."
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.

atombrot (26 views)
2014-08-19 09:29:53

Tekkerue (24 views)
2014-08-16 06:45:27

Tekkerue (23 views)
2014-08-16 06:22:17

Tekkerue (13 views)
2014-08-16 06:20:21

Tekkerue (20 views)
2014-08-16 06:12:11

Rayexar (59 views)
2014-08-11 02:49:23

BurntPizza (38 views)
2014-08-09 21:09:32

BurntPizza (30 views)
2014-08-08 02:01:56

Norakomi (37 views)
2014-08-06 19:49:38

BurntPizza (67 views)
2014-08-03 02:57:17
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!