(Help please) How to show drawing in QGLWidget on mainwindow?
-
Hello,
I'm new to QT and OpenGL and need your help for my question. I have created a QT+OpenGL application. I have a mainwindow UI and have place a Widget inherited from QGLWidget on the mainwindow.I have write a simple OpenGL code to show points on the screen. The function is called (I had placed a messagebox there) but the app does not display the points I pained on screen. Please help what I should do to have the points display on screen.
Here is my code in .h file.
@#include <QGLWidget>
class MyPanelOpenGL : public QGLWidget
{
Q_OBJECT
public:
explicit MyPanelOpenGL(QWidget *parent = 0);protected:
void initializeGL();
void resizeGL(int width, int height);
void paintGL();
void draw();signals:
public slots:
};@
and here is my implementation .cpp file - in which I draw points in draw()
@MyPanelOpenGL::MyPanelOpenGL(QWidget *parent) :
QGLWidget(parent)
{
setFormat(QGLFormat(QGL::DoubleBuffer | QGL::DepthBuffer));
}void MyPanelOpenGL::initializeGL()
{
qglClearColor(Qt::white);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_CULL_FACE);
}void MyPanelOpenGL::resizeGL(int width, int height)
{
glViewport(0,0,width,height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLfloat x = GLfloat(width)/height;
glFrustum(-x, +x, -1.0, +1.0, 4.0, 15.0);
glMatrixMode(GL_MODELVIEW);}
void MyPanelOpenGL::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
draw();
}void MyPanelOpenGL::draw()
{
glColor3f(1.0, 0.0, 0.0);
glBegin(GL_POINTS);
glVertex2i(50,100);
glVertex2i(75,150);
glVertex2i(100,200);
glEnd();glFlush(); //updateGL();
}
@Really thanks for your help ^^