The code below compiles but crashes in the loop where DrawAll is called. Basically I create two polygons separated by 10 units along x,y,z,
Code: Select all
#include <irrlicht.h>
using namespace irr;
class MyEventReceiver : public IEventReceiver
{
public:
// This is the one method that we have to implement
virtual bool OnEvent(const SEvent& event)
{
// Remember whether each key is down or up
if (event.EventType == irr::EET_KEY_INPUT_EVENT)
KeyIsDown[event.KeyInput.Key] = event.KeyInput.PressedDown;
return false;
}
// This is used to check whether a key is being held down
virtual bool IsKeyDown(EKEY_CODE keyCode) const
{
return KeyIsDown[keyCode];
}
MyEventReceiver()
{
for (u32 i=0; i<KEY_KEY_CODES_COUNT; ++i)
KeyIsDown[i] = false;
}
private:
// We use this array to store the current state of each key
bool KeyIsDown[KEY_KEY_CODES_COUNT];
};
MyEventReceiver receiver;
int main()
{
IrrlichtDevice* device = 0;
device = createDevice( video::EDT_OPENGL, core::dimension2d<u32>(640, 480), 16, false, false, false, &receiver);
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( 13, 18, 11));
cam->setTarget(core::vector3df( -3, 7,- 4));
device->getCursorControl()->setVisible(false);
//////////////////////////////////////////////////////////////////////////////////////////////////////////
scene::SMesh *mesh = new scene::SMesh();
scene::SMeshBuffer * meshbuf = new scene::SMeshBuffer();
video::S3DVertex a(0,0,10, 1,1,0, video::SColor(255,0,255,255), 0, 1);
video::S3DVertex b(10,0,-10, 1,0,0, video::SColor(255,255,0,255), 1, 1);
video::S3DVertex c(0,20,0, 0,1,1, video::SColor(255,255,255,0), 1, 0);
video::S3DVertex d(-10,0,-10, 0,0,1, video::SColor(255,0,255,0), 0, 0);
video::S3DVertex ver2[] = {a,b,c,d};
u16 indices[] = { 0,2,3, 2,1,3, 1,0,3, 2,0,1 };
mesh->addMeshBuffer(meshbuf);
meshbuf->drop();
meshbuf->append((const void*)&ver2, 4, (u16*)&indices, 12);
meshbuf->Vertices.reallocate(4);
meshbuf->Vertices.set_used(4);
meshbuf->Indices.set_used(12);
meshbuf->recalculateBoundingBox();
scene::IMeshSceneNode* Node = smgr->addMeshSceneNode(mesh);
Node->setMaterialFlag(video::EMF_LIGHTING, false);
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
video::S3DVertex a1(0+10,0+10,10+10, 1,1,0, video::SColor(255,0,255,255), 0, 1);
video::S3DVertex b1(10+10,0+10,-10+10, 1,0,0, video::SColor(255,255,0,255), 1, 1);
video::S3DVertex c1(0+10,20+10,0+10, 0,1,1, video::SColor(255,255,255,0), 1, 0);
video::S3DVertex d1(-10+10,0+10,-10+10, 0,0,1, video::SColor(255,0,255,0), 0, 0);
ver2[0] = a1;
ver2[1] = b1;
ver2[2] = c1;
ver2[3] = d1;
mesh->addMeshBuffer(meshbuf);
meshbuf->drop();
meshbuf->append((const void*)&ver2, 4, (u16*)&indices, 12);
meshbuf->Vertices.reallocate(8);
meshbuf->Vertices.set_used(8);
meshbuf->Indices.set_used(24);
meshbuf->recalculateBoundingBox();
Node = smgr->addMeshSceneNode(mesh);
Node->setMaterialFlag(video::EMF_LIGHTING, false);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int lastFPS = -1;
while(device->run())
{
driver->beginScene(true, true, video::SColor(255,0,0,0));
smgr->drawAll();
driver->endScene();
int fps = driver->getFPS();
if (lastFPS != fps)
{
core::stringw str = L"[";
str += " FPS: ";
str += fps;
str += "]";
device->setWindowCaption(str.c_str());
lastFPS = fps;
}
}
device->drop();
return 0;
}