PDA

View Full Version : Not able to use updateGL()



chintu
21st January 2011, 06:29
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 .....
;( ;( ;( ;(




#include <QtGui/QApplication>
#include <QtOpenGL/QGLWidget>
#include <QtGui/QColor>
#include <QtOpenGL/qgl.h>
#include <iostream>
#include <time.h>
#include "Quad.h"

int main(int argc, char *argv[]) {
// initialize resources, if needed
// Q_INIT_RESOURCE(resfile);

QApplication app(argc, argv);

// create and show your widgets here
Quad *w = new Quad();
w->show();
return app.exec();
}

// ================================================== ===============================================

#include "Point.h"
class Quad : public QGLWidget {
Q_OBJECT

private:
Point *Pt;
int total_objects;
protected:

void InitializeGL() {
// Set the way we want things to look
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
};

void resizeGL(int Height, int Width) {
glViewport(Width, Height, 0, 0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
};

void paintGL() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
int counter;
for(counter=0;counter<100;counter+=4){
if(Pt[counter].getcol()==true){
qglColor(Qt::red);
glBegin(GL_QUADS);
glVertex2f(Pt[counter].getsx(),Pt[counter].getsy());
glVertex2f(Pt[counter+1].getsx(),Pt[counter].getsy());
glVertex2f(Pt[counter+2].getsx(),Pt[counter].getsy());
glVertex2f(Pt[counter+3].getsx(),Pt[counter].getsy());
glEnd();
}else{
qglColor(Qt::white);
glBegin(GL_QUADS);
glVertex2f(Pt[counter].getsx(),Pt[counter].getsy());
glVertex2f(Pt[counter+1].getsx(),Pt[counter].getsy());
glVertex2f(Pt[counter+2].getsx(),Pt[counter].getsy());
glVertex2f(Pt[counter+3].getsx(),Pt[counter].getsy());
glEnd();
}
}
// updateGL();
};

public:

Quad(QWidget *parent = 0) {
srand(time(NULL));
int counter;
total_objects = 100;
Pt = new Point[total_objects]();
for (counter = 0; counter < 100; counter++) {
Pt[counter].init((float) (rand() % 100), (float) (rand() % 100), ((rand() % 2) == 0 ? true : false));
}
};
};

//================================================== ================================================== ===========================

class Point {
private:
float s_x;
float s_y;
bool col;
public:

Point(float sx, float sy, bool co) {
s_x = sx;
s_y = sy;
col = co;
};

Point() {};

void init(float sx, float sy, bool co) {
s_x = sx;
s_y = sy;
col = co;
};

float getsx() {
return s_x;
};

float getsy() {
return s_y;
};

bool getcol() {
return col;
};
};



Thanks in advance for the help .....
:)

bahbah30
24th January 2011, 10:04
try this in InitializeGL():


QTimer *timer = new QTimer();
timer->start(1); //time in ms, here 1 ms
connect(timer ,SIGNAL(timeout()),this,SLOT(updateGL()));

wysota
24th January 2011, 18:57
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.