アットウィキロゴ

4. 2Dグラフィック表示

*概要                      

 irrlichtで2Dグラフィックを表示します。表示しているのは、irrlichtのロゴと背景マップ、そしてインプ二匹です。インプは二枚が交互に切り替わりアニメーションしています。片方のインプには指定色の加減合成も行っています。irrlichtの2Dグラフィック機能は、色の加算合成?とクリッピング機能がありますが、回転ができないのでノベルゲームなどの静的なゲームに向いています。

 
 

サンプルで使用されている画像

2ddemo.png
 


 

*ソースコード                  

#include <tchar.h>
#include <irrlicht.h>

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

using namespace irr;
using namespace core;
using namespace video;

#ifdef WIN32
int WINAPI _tWinMain( HINSTANCE,HINSTANCE,LPTSTR,int )
#else
int main( int,TCHAR* )
#endif
{
    // irrlichtを初期化。
    IrrlichtDevice *device = createDevice(EDT_OPENGL,
            dimension2d<u32>(480,360));
    IVideoDriver* driver = device->getVideoDriver();
    device->setWindowCaption(_T("2D Texture Draw Sample!"));

   // テクスチャ読み込み
    ITexture* images = driver->getTexture( _T("2ddemo.png") );
    driver->makeColorKeyTexture( images , position2d<s32>(0,0) );

    // 画像のインプ部分の領域設定
    rect<s32> imp1(349,15,385,78);
    rect<s32> imp2(387,15,423,78);


    // 描画ループ
    while(device->run() && driver)
    {
        // 時間を取得。
        u32 timecount = device->getTimer()->getTime();

        driver->beginScene(true, true, SColor(255,0,0,255));
        
        // テクスチャを描画
        // draw fire & dragons background world
        driver->draw2DImage(images, position2d<s32>(50,50),
                rect<s32>(0,0,342,224), 0,
                SColor(255,255,255,255), true);

        // インプを描画。
        driver->draw2DImage(images, position2d<s32>(164,125),
                (timecount/500 % 2) ? imp1 : imp2, 0,
                SColor(255,255,255,255), true);


        // 変化していく色が加算されたインプを描画。
        driver->draw2DImage(images, position2d<s32>(270,105),
                (timecount/500 % 2) ? imp1 : imp2, 0,
                SColor(255,( timecount) % 255,255,255), true);

        // irrlichtのロゴを描画。
        driver->draw2DImage(images, rect<s32>(10,10,108,48),
                rect<s32>(354,87,442,118));


        driver->endScene();
    }

    // デバイスの削除
    device->drop();
    return 0;
}

 

最終更新:2011年06月17日 12:47