Results 1 to 2 of 2

Thread: QGLWidget is empty on Mac, cannot draw

  1. #1

    Default QGLWidget is empty on Mac, cannot draw

    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:

    Qt Code:
    1. void OpenGLWidget::initializeGL()
    2. {
    3. qglClearColor(Qt::white);
    4. glShadeModel( GL_FLAT );
    5. glClearDepth(1.0f);
    6. glEnable(GL_DEPTH_TEST);
    7. glDepthFunc(GL_LEQUAL);
    8. glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    9.  
    10. if (m_lines) {
    11. glPolygonMode(GL_BACK, GL_LINE);
    12. glPolygonMode(GL_FRONT, GL_LINE);
    13. } else {
    14. glPolygonMode(GL_BACK, GL_FILL);
    15. glPolygonMode(GL_FRONT, GL_FILL);
    16. }
    17. }
    18.  
    19. void OpenGLWidget::resizeGL(int width, int height)
    20. {
    21. glViewport(0, 0, width, height);
    22. glMatrixMode(GL_PROJECTION);
    23. glLoadIdentity();
    24. gluPerspective( 10.0f, (GLfloat)width / (GLfloat)height, 0.25, 100*m_zoom );
    25. glMatrixMode(GL_MODELVIEW);
    26. }
    27.  
    28. void OpenGLWidget::paintGL()
    29. {
    30. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
    31. glFlush();
    32. draw();
    33. }
    34.  
    35. void OpenGLWidget::draw()
    36. {
    37. if (!m_data)
    38. return;
    39.  
    40. glLoadIdentity();
    41. glTranslatef( m_panX, m_panY, m_zoom );
    42. glRotatef( m_rotationX, 1.0, 0.0, 0.0 );
    43. glRotatef( m_rotationY, 0.0, 1.0, 0.0 );
    44. glRotatef( m_rotationZ, 0.0, 0.0, 1.0 );
    45.  
    46. glBegin(GL_QUADS);
    47.  
    48. const int maxX = m_width-1;
    49. const int maxY = m_height-1;
    50.  
    51. int value;
    52.  
    53. for (int x=0; x < maxX; ++x) {
    54. for (int y=0; y < maxY; ++y) {
    55. value = (int)((((m_map[x][y][2]+1)/2)*0xff));
    56. qglColor( m_faceColors[ value ] );
    57.  
    58. glVertex3f( m_map[x][y][0], m_map[x][y][1], m_map[x][y][2] );
    59. glVertex3f( m_map[x][y+1][0], m_map[x][y+1][1], m_map[x][y+1][2] );
    60. glVertex3f( m_map[x+1][y+1][0], m_map[x+1][y+1][1], m_map[x+1][y+1][2] );
    61. glVertex3f( m_map[x+1][y][0], m_map[x+1][y][1], m_map[x+1][y][2] );
    62. }
    63. }
    64.  
    65. glEnd();
    66. }
    67.  
    68. void OpenGLWidget::setBackgroundColor(const QColor &color)
    69. {
    70. qglClearColor(color);
    71. updateGL();
    72. }
    To copy to clipboard, switch view to plain text mode 

    Does anybody know what is wrong?

  2. #2
    Join Date
    Feb 2012
    Location
    Armenia/Yerevan
    Posts
    400
    Thanks
    15
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QGLWidget is empty on Mac, cannot draw

    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/1...rtho2d-doesnt/


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

Similar Threads

  1. QGLWidget: Draw 100% of image (even when hidden)
    By JohnnyRep in forum Qt Programming
    Replies: 5
    Last Post: 28th January 2016, 14:46
  2. QGLWidget and draw string
    By giorgik in forum Qt Programming
    Replies: 2
    Last Post: 25th April 2013, 18:30
  3. QGLWidget don't draw in its place in the layout
    By entee in forum Qt Programming
    Replies: 1
    Last Post: 15th October 2011, 19:01
  4. Replies: 10
    Last Post: 10th February 2011, 23:31
  5. Replies: 1
    Last Post: 10th December 2009, 21:31

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.