irrlicht引擎示例代码研究(1)

来源:互联网 发布:浙江网络干部学院 编辑:程序博客网 时间:2024/04/29 07:33

//刚刚接触irrlicht引擎,感觉挺简单,上手快,在这里晒一晒简单的代码及注释

//不懂的函数和类信息看官方文档,那里什么都有


#include <irrlicht/irrlicht.h>      //本人将irr中的文件都放在irrlicht文件夹中,和系统include放在一起
#pragma comment(lib,"irrlicht.lib")

 

using namespace irr;                            
 
using namespace core;
using namespace scene;
using namespace video;
using namespace io;
using namespace gui;

int main()
{
 IrrlichtDevice *device =                    //创建一个irr设备,可理解为创建一个窗体createwindow,个人感觉更像是OpenGL
               //在windows环境下的初始化工作,GDI设备
#ifdef _IRR_OSX_PLATFORM_
  createDevice( video::EDT_OPENGL, dimension2d<s32>(640, 480), 16,
  false, false, false, 0);
#else
  createDevice( video::EDT_SOFTWARE, dimension2d<s32>(640, 480), 16,
  false, false, false, 0);
#endif

 if (!device)
  return 1;

 

 device->setWindowCaption(L"Hello World! - Irrlicht Engine Demo"); //设置窗口名字

 IVideoDriver* driver = device->getVideoDriver();                        //创建一个录像驱动,不知道是干什么的
                         //由后面的run循环可知,这个东西还真是个驱动,
                         //是前提

 ISceneManager* smgr = device->getSceneManager();                //创建一个场景管理器,用于设置镜头等

 IGUIEnvironment* guienv = device->getGUIEnvironment();         //创建一个gui环境,可以理解为一个添加控件的接口

 guienv->addStaticText(L"Hello World! This is the Irrlicht Software renderer!",
  rect<s32>(100,100,300,130), true);                                                           //gui环境中添加一个静态文本“控件”

 smgr->addCameraSceneNode(0, vector3df(0,30,-40), vector3df(0,5,0));  //场景管理器——设置摄像头

 

 while(device->run())                                                                  //主循环呗,整个程序的交互部分就在这了
 {
  driver->beginScene(true, true, SColor(255,100,101,140));      //Applications must call this method
                         //before performing any rendering.                        
  smgr->drawAll();
  guienv->drawAll();
  driver->endScene();
 }

 

 device->drop();                  //于前面的createDevice()对应
 return 0;
}

原创粉丝点击