Reputation: 510
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?
Upvotes: 0
Views: 70
Reputation: 31080
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();
}
Upvotes: 1