Results 1 to 10 of 10

Thread: How to update a OpenGL GLWidget embedded within QT?

  1. #1
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Question Re: How to update a OpenGL GLWidget embedded within QT?

    Hi everyone!
    I am developing a really simple application using QT and OpenGL. The application contains a few buttons for interaction and a widget tab containing 3 pages, the first two for analysing and processing some data and the third contains a GLWidget which should draw the result points in a 3d space.
    At the beginning the 3d space doesn't contain any points and after all the data are processed it should draw the 3 points.
    So far I have tried to call an external function to paintGL() to draw a solid cube at the centre of the scene. The method is correctly called but the widget does not display any cube.
    If you want I can post part of the code and if you have any questions then please do not hesitate to ask me.
    I hope someone of you can help me with this.
    Last edited by sonda; 19th March 2013 at 01:36.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    Just call update() on the widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    sonda (19th March 2013)

  4. #3
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    I have tried but it doesn't work, so I decided to post my code.

    glwidget.cpp
    Qt Code:
    1. GLWidget::GLWidget(QWidget *parent) :
    2. QGLWidget(parent)
    3. {
    4. connect(&timer, SIGNAL(timeout()), this, SLOT(updateGL()));
    5. timer.start(1000);
    6. }
    7.  
    8. void GLWidget::initializeGL(int w, int h) {
    9. glClearColor(0.2f, 0.2f, 0.2f, 1);
    10. glViewport(0, 0, w, h);
    11. // Setup light
    12. const GLfloat light_ambient[] = { 0.0f, 0.0f, 0.0f, 1.0f };
    13. const GLfloat light_diffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    14. const GLfloat light_specular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
    15. const GLfloat light_position[] = {2.0f, 5.0f, 5.0f, 0.0f };
    16. glEnable(GL_DEPTH_TEST);
    17. glEnable(GL_CULL_FACE);
    18. glEnable(GL_DOUBLE);
    19. glShadeModel(GL_SMOOTH);
    20. glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
    21. glEnable(GL_DEPTH_TEST);
    22. glEnable(GL_LIGHT0);
    23. glEnable(GL_LIGHTING);
    24. glEnable(GL_COLOR_MATERIAL);
    25. glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
    26. glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
    27. glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
    28. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
    29. glEnable(GL_CULL_FACE);
    30. glCullFace(GL_BACK);
    31. glDepthFunc(GL_LESS);
    32. glEnable(GL_COLOR_MATERIAL);
    33. glMatrixMode(GL_PROJECTION);
    34. glLoadIdentity();
    35. gluPerspective(60.0, 1.0, 0.0001, 1000.0);
    36. glMatrixMode(GL_MODELVIEW);
    37. current_view= TOP_VIEW;
    38.  
    39. }
    40.  
    41. / Display
    42. void GLWidget::paintGL() {
    43. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    44. glEnable(GL_DEPTH_TEST);
    45. glLoadIdentity();
    46. setView();
    47. if (current_view == EXPLORING_VIEW)
    48. calculate_lookpoint();
    49. gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz);
    50. // Draw axis and add points
    51. drawAxis();
    52. int ind;
    53. Skyline s;
    54. if (s.skylineGenerated()) {
    55. drawCube();
    56. cout << "Generated" << endl;
    57. }
    58. swapBuffers();
    59. }
    60.  
    61. void GLWidget::drawCube(void){
    62. cout << "Drawn\n";
    63. glTranslatef(0.0,0.0,0.0);
    64. glColor3f(1.0,0.0,0.0);
    65. glutSolidCube(2.0);
    66. update();
    67. }
    68.  
    69. // Reshape
    70. void GLWidget::resizeGL(int w, int h) {
    71. glViewport(0, 0, (GLsizei) w, (GLsizei) h);
    72. glMatrixMode(GL_PROJECTION);
    73. glLoadIdentity();
    74. gluPerspective (48.0, (GLfloat) w/(GLfloat) h, 10.0, 800.0);
    75. glMatrixMode (GL_MODELVIEW);
    76. }
    To copy to clipboard, switch view to plain text mode 

    Despite the fact I call update(), when I click on the tab containing this widget no cube is shown. Furthermore the light is not working. Can you please help me? Ah I have the entire Opengl program in a class and everything is working but I don't understand why the GLWidget is not working like the original program.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    Your drawCube() doesn't make sense. If you want to draw something, you are supposed to call update() and draw what needs to be drawn in paintGL().
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #5
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    I have modified the code for paintGL() but this time everything (axis and cube) is rotating:
    Qt Code:
    1. void GLWidget::paintGL() {
    2. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    3. glEnable(GL_DEPTH_TEST);
    4. glLoadIdentity();
    5. setView();
    6. if (current_view == EXPLORING_VIEW)
    7. calculate_lookpoint();
    8. gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz);
    9. // Draw axis and add points
    10. drawAxis();
    11. int ind;
    12. Skyline s;
    13. if (s.skylineGenerated()) {
    14. glPushMatrix();
    15. glTranslatef(0.0,0.0,0.0);
    16. glColor3f(1.0,0.0,0.0);
    17. glRotatef(0.5,1,0,1);
    18. glSolidCube(2.0);
    19. glPopMatrix();
    20. update();
    21. }
    22. swapBuffers();
    23. }
    To copy to clipboard, switch view to plain text mode 

    And why the light is not working?

  7. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    You are not supposed to be calling update() from within paintGL(). The latter will be called by Qt as a result of the call to the former. Have you gone through at least one Qt OpenGL example?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. #7
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    Yes I have seen lots of examples. Anyway I have decided to use my original program and execute it within the GLWidget. So I added this line
    Qt Code:
    1. void Sk::on_pushButton_clicked()
    2. {
    3.  
    4. process.start("/home/user/Desktop/Test");
    5.  
    6. }
    To copy to clipboard, switch view to plain text mode 

    How can I display the external program within the GLWidget?

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    Quote Originally Posted by sonda View Post
    How can I display the external program within the GLWidget?
    You can't.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #9
    Join Date
    Mar 2013
    Posts
    5
    Thanks
    1
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    But I have read about QX11embedContainer, I have tried to include the library but it gives me an error. So the only way to run that executable is to use an external window???

  11. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: How to update a OpenGL GLWidget embedded within QT?

    Quote Originally Posted by sonda View Post
    But I have read about QX11embedContainer, I have tried to include the library but it gives me an error.
    QX11EmbedContainer requires "the other application" to know how to embed itself into a given X window.

    So the only way to run that executable is to use an external window???
    Basically yes.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 3
    Last Post: 13th February 2013, 17:53
  2. GUI doesn't update in QThreaded opengl application
    By bingofuel in forum Qt Programming
    Replies: 1
    Last Post: 9th November 2012, 08:04
  3. Replies: 0
    Last Post: 30th September 2010, 13:22
  4. Embedded Qt OpenGL Backend
    By ebranson in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 15th March 2010, 17:53
  5. Qt Embedded + OpenGL problem
    By EeroS in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 7th October 2008, 14:32

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.