简体   繁体   中英

libQGLViewer how to draw withouth clearing buffer

I'm using libQGLViewer in my project to draw the trajectory of a robot. To this end, I started from the code of the simpleViewer provided in the examples.

To do my stuff, I put these lines of code in the draw function:

void Viewer::draw()
{

  glPushMatrix();
  for (auto pose : poses)
  {
    std::vector<float> m;
    poseToVector(pose, m);

    glPushMatrix();
    multMatrix(m);
    drawReferenceSystem();
    glPopMatrix();
  }
  glPopMatrix();
}

where the poseToVector , multMatrix and drawReferenceSystem functions are OpenGL wrappers to implement the desired functionalities.

Now, my problem is that the poses vector is filled at each iteration of my code with a new pose. Thus, what I'm doing now is that at iteration 1 I'm drawing pose 1, at iteration 2 I'm drawing pose 1 and 2, at iteration 3 I'm drawing pose 1,2 and 3, and so on.

For this reason, I was wondering if there was a more efficient way to perform this operation. However, if I just get the back of the vector I will see at each time instant only the last pose. I guess that this is because every time the draw function is called the frame buffer is cleared.

Therefore, my question is: is it possible to avoid clearing the buffer or I'm just saying bullshit?

preDraw clears the screen and resets matrices. You could subclass QGLViewer and override it to drop the clearing behavior.

The default implementation is:

void QGLViewer::preDraw() {
  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // this line should be removed here or in a sublass.

  // GL_PROJECTION matrix
  camera()->loadProjectionMatrix();
  // GL_MODELVIEW matrix
  camera()->loadModelViewMatrix();

  Q_EMIT drawNeeded();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM