Best way to draw infinite size grid?

I have a 2D space setup for a plot. I want the user to be able to ‘pan’ through the plot by holding down a mouse button and dragging. So the plot may exist over some insane range like 1 to 1 million in both directions, but the user is only seeing a 500x500 chunk at a time, and by dragging the mouse they’re changing the chunk they’re looking at (think of staring through a cylinder on top of a map laid out on a desk). There should always appear to be a grid in the background as the user pans.

Information known at runtime:
-(x,y) coordinate primary vertical line and horizontal line should go through (origin)
-amount of space between lines

Not known at runtime:
-How far out into space the user will pan.

The whole time, the user should have the illusion of panning over one contiguous grid. Since I won’t know how far out they’ll go at runtime, and it could be big, just drawing lots of lines over the total available space isn’t feasible (the range they could pan over might be x=(0, 65535) y=(0, 65535) with spacing expected to be 10 in both directions, meaning 2*65535.5 lines to draw @_@

So I know I should only be drawing a small number of lines viewable where the user is currently panning over. I’m not sure how to do this avoiding immediate mode. Ideas?

it’s hard to avoid immediate mode, but you could set up a VBO with a grid of lines in it, and then move it around set distances using glTranslate.

another way is to use a texture with the grid on it and just have it repeat infinitly

having a texture repeat that much would require more precision than is currently available. That said, you’ll probably get very noticable texture swimming. That said, just moving a slightly oversized grid by set amounts is probably your best option.

Kevin B

When you have a lot of geometry, but you view only portion of it then using algorithms such as BSP is what you need.
You have a rectangular (or quad) space with geometry - if there is too much geometry then divide this space into 4 euqal parts. If some of them have too much geometry, then divide them again, and so on.
This way you build a tree of quads - each one contains up to 4 smaller quads and quads at the lower level contain geometry information.

that would be a quad tree, not a binary space partition, which deals with half spaces.
the grid should be a single quad stretching slighting beyond the limits of your frustum, locked to the viewers position on the ground plane (x,z). Then use the texture matrix to scroll a wrapping texture based on the same x,z.

If you’re displaying just a grid, don’t you think it would be a bit much to build the entire thing (which btw would have no variation) and then try to partition that? Not only that, but what about the precision loss? What about the memory required? What about the tree traversal? Just using integers to store a fixed point camera position and simply moving the grid as the camera moves would easily do the trick.

Kevin B