{
makeCurrent();
qglClearColor(Qt::black);
setupViewport(width(), height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw rectangles using native OpenGL code
// normalized coordinates
stopwatch.start();
glColor4f(0.0f,0.0f,1.0f,1.0f);
foreach
(const QPointF * pt, testpos
) {
glBegin(GL_LINE_LOOP);
glVertex2f(pt->x(), pt->y());
glVertex2f(pt->x()+0.03, pt->y());
glVertex2f(pt->x()+0.03, pt->y()+0.03);
glVertex2f(pt->x(), pt->y()+0.03);
glEnd();
}
qDebug() << "elapsed msec native gl: " << stopwatch.elapsed();
// draw rectangles using QPainter
// screen space coordinates
stopwatch.start();
p.setPen(Qt::blue);
foreach
(const QPointF * pt, testpos
) {
p.drawRect(pt->x()*500, pt->y()*500, 20, 20);
}
p.end();
qDebug() << "elapsed msec painter: " << stopwatch.elapsed();
}
void GLWidget::paintEvent(QPaintEvent *event)
{
makeCurrent();
qglClearColor(Qt::black);
setupViewport(width(), height());
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// draw rectangles using native OpenGL code
// normalized coordinates
QTime stopwatch;
stopwatch.start();
glColor4f(0.0f,0.0f,1.0f,1.0f);
foreach(const QPointF * pt, testpos)
{
glBegin(GL_LINE_LOOP);
glVertex2f(pt->x(), pt->y());
glVertex2f(pt->x()+0.03, pt->y());
glVertex2f(pt->x()+0.03, pt->y()+0.03);
glVertex2f(pt->x(), pt->y()+0.03);
glEnd();
}
qDebug() << "elapsed msec native gl: " << stopwatch.elapsed();
// draw rectangles using QPainter
// screen space coordinates
stopwatch.start();
QPainter p(this);
p.setPen(Qt::blue);
foreach(const QPointF * pt, testpos)
{
p.drawRect(pt->x()*500, pt->y()*500, 20, 20);
}
p.end();
qDebug() << "elapsed msec painter: " << stopwatch.elapsed();
}
To copy to clipboard, switch view to plain text mode
Bookmarks