Make OpenGL examples work on retina displays.

glViewport expects device pixels, but the various
geometry accessors returns values in device-independent
pixels.

Change-Id: I8004692de82251e4f1f25bf8f2698895f222ede3
Reviewed-by: Gunnar Sletta <gunnar.sletta@digia.com>
This commit is contained in:
Morten Johan Sørvig 2013-11-28 23:45:36 +01:00 committed by The Qt Project
parent d55db6dd53
commit af1dbfd223
4 changed files with 5 additions and 5 deletions

View File

@ -142,7 +142,7 @@ void Renderer::render()
m_initialized = true;
}
glViewport(0, 0, viewSize.width(), viewSize.height());
glViewport(0, 0, viewSize.width() * surface->devicePixelRatio(), viewSize.height() * surface->devicePixelRatio());
glClearColor(0.1f, 0.1f, 0.2f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

View File

@ -175,9 +175,9 @@ void PaintedWindow::paint()
{
m_context->makeCurrent(this);
QRect rect(0, 0, width(), height());
QRect rect(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio());
QOpenGLPaintDevice device(size());
QOpenGLPaintDevice device(size() * devicePixelRatio());
QPainter painter(&device);
QPainterPath path;

View File

@ -198,7 +198,7 @@ void GLWidget::orthographicProjection()
void GLWidget::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);
glViewport(0, 0, width * devicePixelRatio(), height * devicePixelRatio());
aspect = (qreal)width / (qreal)(height ? height : 1);
perspectiveProjection();
}

View File

@ -156,7 +156,7 @@ void GLWidget::draw()
glTranslatef(0.0f, 0.0f, -15.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glViewport(0, 0, width(), height());
glViewport(0, 0, width() * devicePixelRatio(), height() * devicePixelRatio());
glBindTexture(GL_TEXTURE_2D, dynamicTexture);
glEnable(GL_TEXTURE_2D);