PDA

View Full Version : QGLWidget is empty on Mac, cannot draw



rybka007
28th June 2013, 11:41
I have a problem with using QGLWidget on mac. My code works correctly on Windows and Linux. On mac I can only change the background fill color of OpenGL, but nothing is being drawn. I am using Qt 4.8.4.

Here is the most crucial part of the code:



void OpenGLWidget::initializeGL()
{
qglClearColor(Qt::white);
glShadeModel( GL_FLAT );
glClearDepth(1.0f);
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LEQUAL);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);

if (m_lines) {
glPolygonMode(GL_BACK, GL_LINE);
glPolygonMode(GL_FRONT, GL_LINE);
} else {
glPolygonMode(GL_BACK, GL_FILL);
glPolygonMode(GL_FRONT, GL_FILL);
}
}

void OpenGLWidget::resizeGL(int width, int height)
{
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective( 10.0f, (GLfloat)width / (GLfloat)height, 0.25, 100*m_zoom );
glMatrixMode(GL_MODELVIEW);
}

void OpenGLWidget::paintGL()
{
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glFlush();
draw();
}

void OpenGLWidget::draw()
{
if (!m_data)
return;

glLoadIdentity();
glTranslatef( m_panX, m_panY, m_zoom );
glRotatef( m_rotationX, 1.0, 0.0, 0.0 );
glRotatef( m_rotationY, 0.0, 1.0, 0.0 );
glRotatef( m_rotationZ, 0.0, 0.0, 1.0 );

glBegin(GL_QUADS);

const int maxX = m_width-1;
const int maxY = m_height-1;

int value;

for (int x=0; x < maxX; ++x) {
for (int y=0; y < maxY; ++y) {
value = (int)((((m_map[x][y][2]+1)/2)*0xff));
qglColor( m_faceColors[ value ] );

glVertex3f( m_map[x][y][0], m_map[x][y][1], m_map[x][y][2] );
glVertex3f( m_map[x][y+1][0], m_map[x][y+1][1], m_map[x][y+1][2] );
glVertex3f( m_map[x+1][y+1][0], m_map[x+1][y+1][1], m_map[x+1][y+1][2] );
glVertex3f( m_map[x+1][y][0], m_map[x+1][y][1], m_map[x+1][y][2] );
}
}

glEnd();
}

void OpenGLWidget::setBackgroundColor(const QColor &color)
{
qglClearColor(color);
updateGL();
}


Does anybody know what is wrong?

saman_artorious
29th June 2013, 14:39
if you are facing the same issue under Mac, try to link the GL implementation under /System/Library/Frameworks/AGL.framework/ . See this post for detail: Why glOrtho() works under Mac but gluOrtho2D() doesn't?
http://stackoverflow.com/questions/12315126/why-glortho-works-under-mac-but-gluortho2d-doesnt/


check out this bug as well:
https://codereview.qt-project.org/#change,55593