Sign in to follow this  
Joesavage1

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

Recommended Posts

Hi,

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,

Joe

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this