Skip to content

Instantly share code, notes, and snippets.

@PathogenDavid
Last active August 25, 2018 11:30
Show Gist options
  • Save PathogenDavid/36aa551e1e0f925706792b9a89d5686f to your computer and use it in GitHub Desktop.
Save PathogenDavid/36aa551e1e0f925706792b9a89d5686f to your computer and use it in GitHub Desktop.
Some example code I wrote for /u/reebs12 on Reddit - https://www.reddit.com/r/gamedev/comments/99y7bb/_/e4raz6j/
#include <Irrlicht.h>
#include <iostream>
using namespace irr;
using namespace irr::core;
using namespace irr::scene;
using namespace irr::video;
using namespace std;
int main()
{
// Create device
IrrlichtDevice* device = createDevice(EDT_OPENGL);
if (device == nullptr)
{
cerr << "Could not initialize graphics device." << endl;
return 1;
}
device->setWindowCaption(L"Plane rendering demo for /u/reebs12");
IVideoDriver* video = device->getVideoDriver();
ISceneManager* sceneManager = device->getSceneManager();
// Add camera to scene
ICameraSceneNode* camera = sceneManager->addCameraSceneNode(nullptr, vector3df(0.f, 0.f, -10.f), vector3df(0.f, 0.f, 0.f));
// Create the plane mesh
SMesh* plane = new SMesh();
SMeshBuffer* planeMeshBuffer = new SMeshBuffer();
planeMeshBuffer->Vertices.push_back(S3DVertex(/* position */ 1.f, 1.f, 0.f, /* normal */ 0.f, 0.f, 1.f, /* color */ SColor(255, 255, 0, 0), /* uv */ 1.f, 1.f));
planeMeshBuffer->Vertices.push_back(S3DVertex(/* position */ 0.f, 1.f, 0.f, /* normal */ 0.f, 0.f, 1.f, /* color */ SColor(255, 255, 0, 0), /* uv */ 0.f, 1.f));
planeMeshBuffer->Vertices.push_back(S3DVertex(/* position */ 1.f, 0.f, 0.f, /* normal */ 0.f, 0.f, 1.f, /* color */ SColor(255, 255, 0, 0), /* uv */ 1.f, 0.f));
planeMeshBuffer->Vertices.push_back(S3DVertex(/* position */ 0.f, 0.f, 0.f, /* normal */ 0.f, 0.f, 1.f, /* color */ SColor(255, 255, 0, 0), /* uv */ 0.f, 0.f));
planeMeshBuffer->Indices.push_back(3);
planeMeshBuffer->Indices.push_back(1);
planeMeshBuffer->Indices.push_back(0);
planeMeshBuffer->Indices.push_back(3);
planeMeshBuffer->Indices.push_back(0);
planeMeshBuffer->Indices.push_back(2);
plane->recalculateBoundingBox();
plane->addMeshBuffer(planeMeshBuffer);
// Add the plane mesh node
IMeshSceneNode* planeNode = sceneManager->addMeshSceneNode(plane);
planeNode->setMaterialFlag(EMF_LIGHTING, false); // There's no lights in this scene, so disable lighting.
// Don't need the mesh anymore, so we can drop the references to it
plane->drop();
planeMeshBuffer->drop();
plane = nullptr;
planeMeshBuffer = nullptr;
// Hint: Adding an animator would've revealed that your plane was just invisible from the angle you were looking
#if false
ISceneNodeAnimator* animator = sceneManager->createRotationAnimator(vector3df(1.f, 0.f, 1.f));
planeNode->addAnimator(animator);
animator->drop();
animator = nullptr;
#endif
// Render the scene
while (device->run())
{
video->beginScene(true, true, SColor(255, 255, 0, 255));
sceneManager->drawAll();
video->endScene();
}
// Cleanup
device->drop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment