Jump to content
  • Advertisement
Sign in to follow this  
raydog

OpenGL Drawing a grid

This topic is 4766 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Sounds like a homework assignment to me...

Share this post


Link to post
Share on other sites
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 :)

Share this post


Link to post
Share on other sites
I can't believe I can't find any decent 3D grid drawing code on Google. Been searching for hours.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
Somebody please move my thread to the Beginner's Forum, because no one here seems to take my question
seriously.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!