Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Not sure whether this is an LWJGL or math question. I want to check whether a shape is on-screen, so that I don't have to render it if it isn't. First of all, is there any simple way to do this that I am overlooking? Like some method or something that I haven't found? I'm going to assume there isn't.

I tried using my trigonometry skills, but it is hard to do this because of how glRotate also distorts the image a little for perspective and realism. Or, is there any way to easily determine if a ray starting from the camera, and going outward in a straight line intersects a shape? (I can probably do it with my math skillz, but is there an easier way?)

By the way, I can easily determine the angle at which the camera is facing around the x and y axis.

EDIT: Or, possibly, I could get the angles of a vector from the camera to the object, and compare those angles to my camera angles. But I have a feeling that the distorts from glRotate and glTranslate would be an issue. I'll try it though.

share|improve this question
up vote 1 down vote accepted

You could research frustum culling. Ideally done as coarsely as possible (say on a whole object - with maybe a bounding sphere), from this you know if it's completely inside (and all visible), part-in, or completely outside and therefore no rendering needed. Depending on what you're trying to achieve, it's possibly faster for the GPU to render some of these primitives than to try and determine their visibility first. The GPU is very good at discarding triangles that are completely outside the screen. So it might be good enough to just throw away objects that are definitely not visible and render the rest. You could cull individual polygons against the frustum too, but I'd profile this to see if it's actually faster or slowing you down.

share|improve this answer

You can use Occlusion Query for this very efficiently. It is simple thing saying how many fragments were rasterized. So first you draw all the renders to set z-buffer and than you ran occlusion query to know how big portion of the object is visible. If you need exact portion you first run query before rendering (you get number for fully visible object) and one after rendering (you get visible portion). Then divide the first value with second one(this is useful when size of object on screen changes every frame)

As this thread says, occlusion queries are supported by lwjgl.

And GPU Gems article for more details

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.