? Clipping Planes and Depth Buffers with gluPerspective() ?

I’m trying to draw a space scene where I can be very close to one object and yet see another object far away. I’ve been developing my application in JOGL (Java OpenGL bindings) and upto now I was using version 1.1.1, which is fairly old. That version seemed to allow me to have a very, very large ratio of near/far clipping planes and everything was working well. I was likely breaking the rule that requires the ratio to be reasonably small, but now I’m paying the price and with my update to JOGL 2.0+ I am having problems.

Basically, the picture below is what I am trying to achieve visually. I want to be able to have a camera located on a vehicle that approaches the International Space Station, and I want to be able to see parts of the vehicle from that camera view, while also seeing the station when it is far away.

So, currently I am unable to move too far away from the space station before it disappears, basically it falls outside of my clipping region. I tried to expand the clipping region to the same values I used under version 1.1.1 and it was broken - it wouldn’t render either when it got too far away, although under the old version is used to be fine.

My question is NOT about JOGL versions - that’s not important. I obviously need to keep those clipping plane ratio small, my question is what other options I have. I realize I could do a dual pass rendering where I render the far away scene to a texture and then project that texture, but my current setup would require too much code change to accomodate that so I was looking for another solution.

Specifically I read the following posts that mention a possible solution

https://www.opengl.org/discussion_boards/showthread.php/184983-glfrustum-near-and-far-values

I believe visually this means I am doing the following with my opengl gluPerspective() calls…ie left image is the old style where you have close near and distant far clipping planes, while the right image shows (what I imagine is being discussed above), that you have two (2) calls to gluPerspective() in the same pass with one call with one set of near/far clipping planes and the other call with a second set of clipping planes.

Effectively, I tried this kind of code:


    glClear(GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fov, ar, nearBACK, farBACK);
    glMatrixMode(GL_MODELVIEW);  

    DRAWBACKGROUND();

    glClear(GL_DEPTH_BUFFER_BIT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    gluPerspective(fov, ar, nearFWD, farFWD);
    glMatrixMode(GL_MODELVIEW); 

    DRAWFOREGROUND();

But this doesn’t seem to be working for me. It seems like the second gluPerspective() is what the DRAWBACKGROUND() is using, because if I change the farFWD clipping distance to something closer than the BACKGROUND, then the BACKGROUND disappears.

Am I doing this correctly?

btw, why can’t I upload any images…keeping getting “not a valid image error” /rant

Out of curiosity, what happens if you don’t call glClear the second time?

I would look into using stencil planes.
Draw the foreground first using nearFWD and farFWD.
Use the same foreground routines to write to stencil planes such that the pixels used to draw the foreground are disabled for writing.
Then draw the space station using nearBACK and farBACK.

This is a 3 pass approach: 1) foreground, 2) stencil, 3) background.
Should not require major re-coding on your part.

You don’t need to render to a texture. Just render the far objects followed by the near objects, with different near/far values for the projection matrix used in each pass. Either clear the depth buffer between passes or use glDepthRange() to allocate a portion of the range to each pass.

Yes, that’s exactly what’s being discussed.

Yes.

Image upload is broken. For now, you’ll need to use an external hosting site.

ok, I think it was working after all. When the station was very far away I was drawing a large wireframe sphere around it so I could still see it in the distance…and that sphere was disappearing. It turns out I wasn’t applying the same near/far clipping planes to that sphere as I was to the station itself - I was using the close in clipping distances and that was cutting it off. I’ll double check it, but I think that was it. Thanks.