Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Drawing a grid in 3D space (C++ OpenGL)

This topic is 2709 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


I've recently decided that I'm going to attempt to make a Minecraft clone (without a lot of features - this is just to test myself and for nothing else) in C++ and OpenGL.
The first thing I'm going to need to do is create a grid in 3D space and be able to track where different squares are and where the player is - I've done a lot of C++ programming, but not a whole lot of OpenGL (I can draw 2D and 3D shapes in OpenGL but that's really my limit).

Can I ask how I'd accomplish a task like this?
I'd imagine that the data for grid would be stored in a multidimensional array or something, but I'm just not quite sure how the drawing & storing would be done.

Thanks In Advance,


Share this post

Link to post
Share on other sites
This problem doesn't really have anything specifically to do with OpenGL (the issues involved will be basically the same regardless of what API is used).

Regarding the grid, a simple multidimensional array will probably only be suitable for a fairly small environment, but it'd probably be a good place to start.

You can use (e.g.) a built-in array (if the size of the environment is fixed), a simple wrapper around std::vector, or boost::multi_array for the storage. The element type can be a built-in type or custom struct or class that holds whatever info is needed about each cell in the grid (at minimum, probably an integer indicating in one way or another whether the cell is occupied, and if so, what type of block occupies it).

At the very simplest, you could simply iterate over the array and render an appropriately textured cube for every cell that was occupied. This ignores many issues though, such as alpha sorting, batching, culling, etc.

A fully developed system will likely address all those issues (and others as well) and be much more complex, but a simply multi-dimensional array might still be a suitable starting point.

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!