Cinderで画像をパーティクルよろしく描画位置やサイズを変更する方法
FFFTPが開発終了のお知らせが出ましたね。
お世話になったソフトでした。
開発者のSotaさん大変お疲れ様でした。
こんばんはムーチョです。
と、そんな出だしとはうってかわってちょっとハマったのでメモ。
Cinderで画像を読み込んで描画というやつですが、
それをパーティクルのように描画位置やサイズを変更する方法
[code lang="cpp"]
Resources.h
#define RES_IMAGE CINDER_RESOURCE( ../resources/, image_name.png, 128, IMAGE )
App.cpp
#include "cinder/app/AppBasic.h"
#include "cinder/ImageIo.h"
#include "cinder/gl/gl.h"
#include "cinder/gl/Texture.h"
#include "Resources.h"
class App : public AppBasic {
public:
void setup();
void draw();
void renderImage( Vec3f, float, Color, float );
gl::Texture texImage;
};
void DotImageCameraApp::setup()
{
texImage = gl::Texture( loadImage( loadResource( RES_IMAGE ) ) ); //テクスチャーとして画像読み込み
}
void App::draw()
{
texImage.bind(); //テクスチャー指定
Vec3f pos = Vec3f(0,0,0); //座標
float size = 1.0f; //スケール(のはずがピクセル数を指定)
Color col = Color(1,1,1); //描画色(基本は1,1,1)
float a = 1.0f; //透明度
renderImage(pos, size, col, a);
}
void App::renderImage( Vec3f _loc, float _diam, Color _col, float _alpha )
{
glPushMatrix();
glTranslatef( _loc.x, _loc.y, _loc.z );
glScalef( _diam, _diam, _diam );
glColor4f( _col.r, _col.g, _col.b, _alpha );
glEnable(GL_TEXTURE_2D);
glBegin( GL_QUADS );
glTexCoord2f(0, 0); glVertex2f(-.5, -.5);
glTexCoord2f(1, 0); glVertex2f( .5, -.5);
glTexCoord2f(1, 1); glVertex2f( .5, .5);
glTexCoord2f(0, 1); glVertex2f(-.5, .5);
glEnd();
glDisable(GL_TEXTURE_2D);
glPopMatrix();
}
[/code]
glEnable(GL_TEXTURE_2D);とか
texImage.bind();とか
ActionScriptとの作法が違いすぎてどうもピンとこない。
しかもキモな部分はCinder独自ではなくOpenGLだったりと
いろいろ残念な気もしますが、想定通り描画はされた。
ぼちぼち使いそうですしメモっておきましょ。そうしましょ。