Results 1 to 3 of 3

Thread: Not able to use updateGL()

  1. #1
    Join Date
    Jan 2011
    Posts
    8
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Not able to use updateGL()

    I am giving the whole code of this small program which I have written. It is very necessary to use the loop as my data is supposed to kept in the loops.
    I do not want to use the qTimer() function ....
    There is no output of the program. I do not know where do I keep the updateGL().
    The program is only supposed to draw some squares in two different colors ....
    I am using Netbeans IDE.
    The GUI is shown but only with a black screen with the code.
    Give me some advise on where I should make changes ......

    Please help .....
    ;( ;( ;( ;(

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QtOpenGL/QGLWidget>
    3. #include <QtGui/QColor>
    4. #include <QtOpenGL/qgl.h>
    5. #include <iostream>
    6. #include <time.h>
    7. #include "Quad.h"
    8.  
    9. int main(int argc, char *argv[]) {
    10. // initialize resources, if needed
    11. // Q_INIT_RESOURCE(resfile);
    12.  
    13. QApplication app(argc, argv);
    14.  
    15. // create and show your widgets here
    16. Quad *w = new Quad();
    17. w->show();
    18. return app.exec();
    19. }
    20.  
    21. // =================================================================================================
    22.  
    23. #include "Point.h"
    24. class Quad : public QGLWidget {
    25. Q_OBJECT
    26.  
    27. private:
    28. Point *Pt;
    29. int total_objects;
    30. protected:
    31.  
    32. void InitializeGL() {
    33. // Set the way we want things to look
    34. glShadeModel(GL_FLAT);
    35. glEnable(GL_DEPTH_TEST);
    36. glEnable(GL_CULL_FACE);
    37. };
    38.  
    39. void resizeGL(int Height, int Width) {
    40. glViewport(Width, Height, 0, 0);
    41. glMatrixMode(GL_PROJECTION);
    42. glLoadIdentity();
    43. glMatrixMode(GL_MODELVIEW);
    44. };
    45.  
    46. void paintGL() {
    47. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    48. glLoadIdentity();
    49. int counter;
    50. for(counter=0;counter<100;counter+=4){
    51. if(Pt[counter].getcol()==true){
    52. qglColor(Qt::red);
    53. glBegin(GL_QUADS);
    54. glVertex2f(Pt[counter].getsx(),Pt[counter].getsy());
    55. glVertex2f(Pt[counter+1].getsx(),Pt[counter].getsy());
    56. glVertex2f(Pt[counter+2].getsx(),Pt[counter].getsy());
    57. glVertex2f(Pt[counter+3].getsx(),Pt[counter].getsy());
    58. glEnd();
    59. }else{
    60. qglColor(Qt::white);
    61. glBegin(GL_QUADS);
    62. glVertex2f(Pt[counter].getsx(),Pt[counter].getsy());
    63. glVertex2f(Pt[counter+1].getsx(),Pt[counter].getsy());
    64. glVertex2f(Pt[counter+2].getsx(),Pt[counter].getsy());
    65. glVertex2f(Pt[counter+3].getsx(),Pt[counter].getsy());
    66. glEnd();
    67. }
    68. }
    69. // updateGL();
    70. };
    71.  
    72. public:
    73.  
    74. Quad(QWidget *parent = 0) {
    75. srand(time(NULL));
    76. int counter;
    77. total_objects = 100;
    78. Pt = new Point[total_objects]();
    79. for (counter = 0; counter < 100; counter++) {
    80. Pt[counter].init((float) (rand() % 100), (float) (rand() % 100), ((rand() % 2) == 0 ? true : false));
    81. }
    82. };
    83. };
    84.  
    85. //===============================================================================================================================
    86.  
    87. class Point {
    88. private:
    89. float s_x;
    90. float s_y;
    91. bool col;
    92. public:
    93.  
    94. Point(float sx, float sy, bool co) {
    95. s_x = sx;
    96. s_y = sy;
    97. col = co;
    98. };
    99.  
    100. Point() {};
    101.  
    102. void init(float sx, float sy, bool co) {
    103. s_x = sx;
    104. s_y = sy;
    105. col = co;
    106. };
    107.  
    108. float getsx() {
    109. return s_x;
    110. };
    111.  
    112. float getsy() {
    113. return s_y;
    114. };
    115.  
    116. bool getcol() {
    117. return col;
    118. };
    119. };
    To copy to clipboard, switch view to plain text mode 

    Thanks in advance for the help .....

  2. #2
    Join Date
    Dec 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Not able to use updateGL()

    try this in InitializeGL():
    Qt Code:
    1. QTimer *timer = new QTimer();
    2. timer->start(1); //time in ms, here 1 ms
    3. connect(timer ,SIGNAL(timeout()),this,SLOT(updateGL()));
    To copy to clipboard, switch view to plain text mode 

  3. #3
    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: Not able to use updateGL()

    The method should be called initializeGL and not InitializeGL. Furthermore resizeGL() has width and height variables swapped. Call to glViewport() also seems invalid. And calling updateGL() with a timer is not required.
    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. update() & updateGL()
    By rick_st3 in forum Newbie
    Replies: 7
    Last Post: 23rd June 2008, 13:57
  2. QGLWidget::updateGL( )
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 2nd November 2006, 19:21
  3. QGLWidget updateGL()
    By Lele in forum Qt Programming
    Replies: 7
    Last Post: 30th May 2006, 15:08

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.