Drawing a grid

Started by
11 comments, last by stevo86 18 years, 9 months ago
Help, my brain is fried. My buddy needs some code to draw a bounded 3D grid (no poking end lines) with different colored major and minor ticks in OpenGL, but not sure what is best way to do it using floats or ints.
Advertisement
Sounds like a homework assignment to me...
personal choice if you dont need the percision of floating points dont use them the ints will operate faster but then again i cant rember if opengl uses floats for its api or not you should use whatever the api uses for storing numerical data for your grid :)
0))))))>|FritzMar>
I can't believe I can't find any decent 3D grid drawing code on Google. Been searching for hours.
It's not that difficult a task, just requires you to think about it for a couple minutes... Which is why there aren't any tutorials on it.


glBegin(GL_LINES);
for (int x=-MAX_MAP_SIZE;x

That's basically it.. may not be 100% correct there, I just wrote that up off the top of my head but I'm running on 1 hour of sleep for the past 2 days so the top of my head may not be quite clear.
Sorry, wasn't logged in in my last post.

It's not that difficult a task, just requires you to think about it for a couple minutes... Which is why there aren't any tutorials on it.


glBegin(GL_LINES);
for (int x=-MAX_MAP_SIZE;x<MAX_MAP_SIZE;x+=GridSize)
{
glVertex3f(x, 0, -4096);
glVertex3f(x, 0, 4096);
}

for (int z=-MAX_MAP_SIZE;z<MAX_MAP_SIZE;z+=GridSize)
{
glVertex3f(-4096, 0, z);
glVertex3f(4096, 0, z);
}

glEnd();

That's basically it.. may not be 100% correct there, I just wrote that up off the top of my head but I'm running on 1 hour of sleep for the past 2 days so the top of my head may not be quite clear.
I'm just looking for grid drawing examples that are better written than mine given these parameters:
adjustable floating-point precision x,z stepping
adjustable floating-point precision x,z bounds
colored origin, major, minor lines

You have the idea, but it's too simple.
Quote:colored origin, major, minor lines

google glcolor , glLineWidth

Quote:
adjustable floating-point precision x,z stepping
adjustable floating-point precision x,z bounds

basic arithmatic?
Somebody please move my thread to the Beginner's Forum, because no one here seems to take my question
seriously.
Is this grid to be aligned with a certain plane (e.g. xy-axis) or span around the scene? Perhaps rendering a grid-box around the viewpoint is a good alternative, disable z-buffering when rendering to make it look like the grid is behind everything.

www.marklightforunity.com | MarkLight: Markup Extension Framework for Unity

This topic is closed to new replies.

Advertisement