金子邦彦研究室人工知能,実世界DBC/C++ でキーボード,マウス,テキスト描画,2次元グラフィックス,画像描画(C/C++, Irrlicht 5 を使用)Irrlicht で線分や正多角形を描画する(2次元グラフィックスの例)

Irrlicht で線分や正多角形を描画する(2次元グラフィックスの例)

IRRLICHT は,C 言語ベースの3次元エンジンです. IRRLICHT は,画像(カラー,モノクロ)の描画、2次元グラフィックス3次元グラフィックスイベント処理(マウス,キーボード等)の機能をもったゲームエンジンの決定版です. 文字の描画 (unicodeも可), 画像ファイル読み書きの機能もありますし,スライダやボタンなどのGUI部品もあるので,困ることはありません.

関連する外部ページ】: http://lesson.ifdef.jp/index.html ・・・ Irrlicht プログラム集

関連する外部ページhttp://www.zgock-lab.net/irrlicht/tut01.htm

関連する外部ページhttps://irrlichtstg.ifdef.jp/

関連する外部ページhttp://www.realintegrity.net/~irr/index.php?FrontPage

前準備

Irrlicht で文字列を描画するプログラム例

driver->draw2DPolygon の vertexCount の値を大きくすると円に近くなる

#ifdef WIN32
#include<windows.h>
#endif
#include<irrlicht.h>

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

#pragma comment(lib, "Irrlicht.lib")

#ifdef WIN32
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
#else
int main()
#endif
{
  const int width = 640;
  const int height = 480;

  // start up an engine
  video::E_DRIVER_TYPE driverType;
#ifdef WIN32
  driverType = video::EDT_DIRECT3D9;
#else
  /* driverType = video::EDT_OPENGL; */
  driverType = video::EDT_SOFTWARE;
  /* driverType = video::EDT_SOFTWARE2; */
#endif
  static IrrlichtDevice *device = createDevice( driverType, 
                         /* windowSize */ core::dimension2d<u32>(width, height), 
                         /* bits */ 16, 
                         /* fullscreen */ false, 
                         /* stencilbuffer */ false, 
                         /* vsync */ false, 
                         /* IEventReceiver */ 0 
                       );

  if (device == 0)
    return 1;
  video::IVideoDriver* driver = device->getVideoDriver();                         
  scene::ISceneManager* scenemgr = device->getSceneManager();  
  gui::IGUIEnvironment* guienv = device->getGUIEnvironment();
  gui::IGUIFont* font = guienv->getBuiltInFont();  
  device->setWindowCaption(L"simple test");

  // draw everything                                                              
  while(device->run() && driver) {
    driver->beginScene(true, true, video::SColor(255,0,0,255)); 
    driver->draw2DLine(/* start */ position2d(100,100), /* end */ position2d(300,300), /* color */ SColor(255,255,0,100) );  
    driver->draw2DPolygon(/* center */ position2d(200,200), /* radius */ 40, /* color */ SColor(255,255,0,100), /* vertexCount */ 50 ); 
    /* scenemgr->drawAll(); */
    driver->endScene();
  }                                                                               

  // delete device                                                                
  device->drop();                                                                 
  return 0;
}

Ubuntu でのコンパイル操作の手順例

g++ -I/usr/include/irrlicht hoge.cc -lIrrlicht

[image]