Вопрос

When my programm start, it must display a circle on a background. Also i must controll all displaying circles. I use class VertexController and class Vertex for that purpose. In Vertex i have constructor:

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;
}

and in VertexController i have

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

and in setup{} method i wrote

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

Unfrtunatelly, my way didnt work.I see only background. So the main question - in CINDER_APP_BASIC drawing possible only in draw{},update{},setup{} directly? If yes, advise a solution, else say where is my fail.

Это было полезно?

Решение

this line of code does not make any sense to me:

mVertexController=VertexController();

Anyways, you should use draw() function just for drawing circles to window. This it why by default there is gl::clear(Color(0,0,0)); to clear background and start drawing new frame from scratch (this is the way drawing in OpenGL, used by default in Cinder, works).

I suggest to use Vector container for storing all circles (this way you can add and remove circles on the fly with some effort), add the first one in VertexController constructor, and make separate function VertexController::draw() to draw all circles using for loop.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top