PDA

View Full Version : Qt and openGl



miivers
31st August 2010, 15:27
Hello new user on the forum here. :)

So we started with openGL on my school this week and instead of using glut I am giving Qt a shot. :rolleyes:

The thing I can seem to get a good answer on is how should I use openGL in Qt if I want to make a basic gameEngine out of it? So fare what I have seen of code examples is the use of QGLWidgets.

Basically what I have is:


#ifndef WINDOWWIDGET_H
#define WINDOWWIDGET_H
#include "player.h"
#include <QtOpenGl/QGLWidget>

class WindowWidget : public QGLWidget
{
public:
WindowWidget(QWidget *parent = NULL);
~WindowWidget();

protected:
Player mPLayer;
void initializeGL();
void resizeGL(int w, int h);
void paintGL();
void mousePressEvent(QMouseEvent *event);
void mouseMoveEvent(QMouseEvent *event);
void keyPressEvent(QKeyEvent *event);
};

#endif


There is one problem with this code. The paintGL() function is only called when the window gets focus again.

So my questions are:
- Is QGLWidgets what I should use? :confused:
- What do I have to do to make a update function that runs all the time? :confused:

Michael

robertson1
31st August 2010, 16:56
You can use a QTimer to control updates.

I found the follwing helpful when trying to learn openGL with Qt:

http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html (http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html)

Alernatively you might also want to have a look at Qt/3D (http://doc.qt.nokia.com/qt3d-snapshot/)