How To Display 100 Floating Cubes Using DirectX OR OpenGL? *

Question

I'd like to display ~100 floating cubes using DirectX or OpenGL.

I'm looking for either some sample source code, or a description of the technique. I know this kind of thing is easy for you accomplished '3D' gurus out there but I have enough trouble getting even one cube to display correctly.

I've combed the net for a good series of tutorials and although they talk about how to do 3D primitives, what I can't find is information on how to do large numbers of 3D primitives - cubes, spheres, pyramids, and so forth.

Answer

You say you have enough trouble getting one cube to display... so I am not sure if you have got one to display or not.

Basically... put your code for writing a cube in one function, then just call that function 100 times.

void DrawCube()
{
//code to draw the cube
}

void DisplayCubes()
{
for(int i = 0; i < 10; ++i)
{
for(int j = 0; j < 10; ++j)
{
glPushMatrix();
//alter these values depending on the size of your cubes.
//This call makes sure that your cubes aren't drawn overtop of each other
glTranslatef(i*5.0, j*5.0, 0);
DrawCube();
glPopMatrix();
}
}
}

That is the basic outline for how you could go about doing this. If you want something more efficient take a look into Display Lists sometime once you have the basics figured out :)

< br > via < a class="StackLink" href=" http://stackoverflow.com/questions/1064/" >How To Display 100 Floating Cubes Using DirectX OR OpenGL?< /a>
Share on Google Plus

About Cinema Guy

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Blogger Comment
    Facebook Comment

0 comments:

Post a Comment