Here's the code,
Code: Select all
#include <irrlicht.h>
#include <iostream>
using namespace irr;
int main()
{
IrrlichtDevice* device = 0;
device = createDevice( video::EDT_OPENGL, core::dimension2d<u32>(1280, 960));
if (device == 0)
return 1;
video::IVideoDriver* driver = device->getVideoDriver();
scene::ISceneManager* smgr = device->getSceneManager();
driver->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, true);
scene::ICameraSceneNode* cam = smgr->addCameraSceneNodeFPS( 0, 50.0f, 0.01f, -1, 0, 0, false, 0.0f, false, true);
cam->setPosition(core::vector3df(0,0,-10));
cam->setTarget(core::vector3df(100,100,0));
device->getCursorControl()->setVisible(false);
irr::video::SMaterial cube_material;
irr::video::S3DVertex *Vertices = (irr::video::S3DVertex*) malloc(sizeof(irr::video::S3DVertex) * 65535);
irr::u16 indices[310000];
int x, y, z, l;//this initializes the positions
x = y = z = 0;
l = 1;
//Bottom
int R, G, B;//used for coloring vertices
R = rand()%255;
G = rand()%255;
B = rand()%255;
x = rand()%200;
y = rand()%200;
z = rand()%200;
int vertex_count = 0;//the counter for the vertices, 4 per face/plane
int vertex_limit = 65500;//the total number of vertices
while(vertex_count < vertex_limit)
{
Vertices[vertex_count] = irr::video::S3DVertex(
x, y, z, 1,1,0,
irr::video::SColor(255, R, G, B), 0, 1);
vertex_count++;
Vertices[vertex_count] = irr::video::S3DVertex(
x+l, y, z, 1,0,0,
irr::video::SColor(255, R, G, B), 1, 1);
vertex_count++;
Vertices[vertex_count] = irr::video::S3DVertex(
x+l, y, z+l, 0,1,1,
irr::video::SColor(255, R, G, B), 1, 0);
vertex_count++;
Vertices[vertex_count] = irr::video::S3DVertex(
x, y, z+l, 0,0,1,
irr::video::SColor(255, R, G, B), 0, 0);
vertex_count++;
x = rand()%200;//this reinitializes the positions (within a box of 200 irrlicht units of distance) and colors
y = rand()%200;
z = rand()%200;
R = rand()%255;
G = rand()%255;
B = rand()%255;
//std::cout<<x<<","<<y<<","<<z<<" vertex_count: "<<vertex_count<<std::endl;
};
std::cout<<" vertex_count: "<<vertex_count<<std::endl;
int index_count = 0;//the counter for the indices
int index_offset = 0;//this is the offset used to keep the indices separate in the array when rendering
while(index_offset < vertex_limit)
{
indices[index_count] = 0 + index_offset;
index_count++;
indices[index_count] = 1 + index_offset;
index_count++;
indices[index_count] = 2 + index_offset;
index_count++;
indices[index_count] = 0 + index_offset;
index_count++;
indices[index_count] = 2 + index_offset;
index_count++;
indices[index_count] = 3 + index_offset;
index_count++;
index_offset+=4;
}
std::cout<<"index_offset" <<index_offset<<" vertex_count: "<<vertex_count<<std::endl;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
smgr->drawAll();
cube_material.BackfaceCulling = false;
cube_material.Wireframe = false;
cube_material.Lighting = false;
driver->setMaterial(cube_material);
driver->setTransform(irr::video::ETS_WORLD, irr::core::matrix4());
driver->drawVertexPrimitiveList( &Vertices[0], vertex_limit, &indices[0], index_offset/2, irr::video::EVT_STANDARD, scene::EPT_TRIANGLES, video::EIT_16BIT);
driver->endScene();
device->sleep(50);
}
device->drop();
return 0;
}