当我的程序启动时,它必须在背景上显示一个圆圈。我也必须控制所有显示圈子。为此,我使用class VertexControllerclass Vertex。在Vertex中,我有构造函数:

Vertex::Vertex(const ci::Vec2f & CurrentLoc){

    vColor = Color(Rand::randFloat(123.0f),Rand::randFloat(123.0f),Rand::randFloat(123.0f));
    vRadius = Rand::randFloat(23.0f);
    vLoc = CurrentLoc;
}


VertexController中,我有

VertexController::VertexController()
{
    Vertex CenterVertex = Vertex(getWindowCenter());
    CenterVertex.draw();  // function-member draw solid circle with random color
}


在我写的setup{}方法中

void TutorialApp::setup(){
    gl::clear(Color(255,204,0));
    mVertexController=VertexController();
}


不幸的是,我的方法没有用。我只能看到背景。
因此,主要问题-在CINDER_APP_BASIC绘图中,是否可能仅直接在draw {},update {},setup {}中?如果是,请提出解决方案,否则请说我失败了。

最佳答案

这行代码对我来说没有任何意义:

mVertexController=VertexController();


无论如何,您应该只将draw()函数用于将圆画到窗口上。这就是为什么默认情况下使用gl::clear(Color(0,0,0));清除背景并开始从头开始绘制新帧的原因(这是OpenGL在Cinder中默认使用的绘制方式)。

我建议使用Vector容器存储所有圆(这样您就可以快速地添加和删除圆),在VertexController构造函数中添加第一个圆,并使用单独的函数VertexController::draw()绘制所有圆使用for循环。

关于c++ - CINDER_APP_BASIC中的Lib Cinder方法设置{},我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22763457/

10-14 23:33