0

我已经使用 Cinder 大约几周了,但我遇到了一些问题。我在我的程序中使用“拖放”方法:

void TutorialApp::fileDrop(FileDropEvent drop){               ///        drop are images
for(size_t i=0; i<drop.getNumFiles();++i){
     Vertex imageVertex = Vertex((Vec2i(drop.getPos().x, drop.getPos().y+200)));
     imageVertex.path = drop.getFiles()[i];

接下来我的步骤是使用关联图像绘制顶点。所以这是一个问题:在这种情况下如何添加资源,或者可能有更简单的解决方案?感谢

4

1 回答 1

1

Straight to the point: First of all,you want to keep images (i.e gl::Texture) in your objects, that you want to draw. So in your class Vertex, add this gl::Texture as member. And then I suggest to use this function to load image and edit constructor, to take gl::Texture as parameter.

So you end up with something like this:

class testVertex
{
public:
testVertex(Vec2i _pos, gl::Texture image);

void draw(){

    gl::draw(texture, pos);
}
private:
    gl::Texture texture;
    Vec2i pos;
};
///constructor
testVertex::testVertex(Vec2i _pos, gl::Texture image)
{
    pos = _pos;
    texture = image;
}


class BasicApp : public AppNative {
public:
    void setup();
    void mouseMove( MouseEvent event ); 
    void mouseUp( MouseEvent event );   
    void keyUp(KeyEvent event);
void fileDrop(FileDropEvent event);
void update();
void draw();

//// create container for testVertex
vector <testVertex> mVertices;
}


/// To load images via drop...
void BasicApp::fileDrop(FileDropEvent event){
    gl::Texture fileTexture = loadImage(event.getFile(0));
    mVertices.push_back(testVertex(Vec2i(event.getX(), event.getY()), fileTexture));
}
/// To draw images...
void BasicApp::draw(){
    for (int i = 0; i < mVertices.size(); i++)
    {
        mVertices[i].draw();
    }
}
/// 
于 2014-04-15T12:10:08.850 回答