Qt-interest Archive, April 2007
help me with QtOpenGL
Message 1 in thread
hi, everyone
i have programe a small application using Qt and OpenGL,but it seems have
some errors which i can't solve, that is , the triangle and quads don't
rotate at all. some codes are as follows:
GLWidget::GLWidget(QWidget *parent,)
: QGLWidget(parent)
{
rTri = 0.0;
rQuad = 0.0;
...
}
void GLWidget::paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-1.5, 0.0, -6.0);
glRotatef(rTri, 0.0, 1.0, 0.0);
glBegin(GL_TRIANGLES);
glColor3f(1.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
glColor3f(0.0, 1.0, 0.0);
glVertex3f(-1.0, -1.0, 0.0);
glColor3f(0.0, 0.0, 1.0);
glVertex3f(1.0, -1.0, 0.0);
glEnd();
glLoadIdentity();
glTranslatef(1.5, 0.0, -6.0);
glRotatef(rQuad, 1.0, 0.0, 0.0);
glColor3f(0.5, 0.5, 1.0);
glBegin(GL_QUADS);
glColor3f( 0.0, 1.0, 0.0 );
glVertex3f( 1.0, 1.0, -1.0 );
glVertex3f( -1.0, 1.0, -1.0 );
glVertex3f( -1.0, 1.0, 1.0 );
glVertex3f( 1.0, 1.0, 1.0 );
glEnd()
rTri += (GLfloat)0.2;
rQuad -= (GLfloat)0.15;
}
Message 2 in thread
Are you sure the update for the GLWidget is called on a regular basis?
to get a full 360 degree rotation for your quad it needs to be called
2400 times.
regards
johannes
ååä schrieb:
> hi, everyone
> i have programe a small application using Qt and OpenGL,but it seems have
> some errors which i can't solve, that is , the triangle and quads don't
> rotate at all. some codes are as follows:
>
> GLWidget::GLWidget(QWidget *parent,)
> : QGLWidget(parent)
> {
> rTri = 0.0;
> rQuad = 0.0;
>
> ...
>
> }
>
> void GLWidget::paintGL()
> {
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>
> glLoadIdentity();
> glTranslatef(-1.5, 0.0, -6.0);
> glRotatef(rTri, 0.0, 1.0, 0.0);
>
> glBegin(GL_TRIANGLES);
> glColor3f(1.0, 0.0, 0.0);
> glVertex3f(0.0, 1.0, 0.0);
> glColor3f(0.0, 1.0, 0.0);
> glVertex3f(-1.0, -1.0, 0.0);
> glColor3f(0.0, 0.0, 1.0);
> glVertex3f(1.0, -1.0, 0.0);
> glEnd();
>
> glLoadIdentity();
> glTranslatef(1.5, 0.0, -6.0);
> glRotatef(rQuad, 1.0, 0.0, 0.0);
> glColor3f(0.5, 0.5, 1.0);
>
> glBegin(GL_QUADS);
> glColor3f( 0.0, 1.0, 0.0 );
> glVertex3f( 1.0, 1.0, -1.0 );
> glVertex3f( -1.0, 1.0, -1.0 );
> glVertex3f( -1.0, 1.0, 1.0 );
> glVertex3f( 1.0, 1.0, 1.0 );
>
> glEnd()
>
> rTri += (GLfloat)0.2;
> rQuad -= (GLfloat)0.15;
> }
>
--
[ signature omitted ]
Message 3 in thread
Perhaps you can try these lessons:
http://www.qiliang.net/nehe_qt/index.html
http://www.digitalfanatics.org/projects/qt_tutorial/chapter14.html
But they are for Qt 3. You need do a little more about Qt 4.
Regards,
Liang Qi
--
[ signature omitted ]
Message 4 in thread
could it be that you're using rotation and drawing in the wrong order? or, alternatively, missing
glPushMatrix()/glPopMatrix() statements?
additionally, have you thought of using a QTimer for the rotation change instead of putting it
directly into the paintGL-method?
Have a look at the QtOpenGL Grabber example [1], it rotates the objects using QTimer (see glwidget.cpp).
You might also want to look at other GL examples provided [2].
manu
[1] http://doc.trolltech.com/4.2/opengl-grabber.html
[2] http://doc.trolltech.com/4.2/examples.html#opengl-examples
ååä wrote:
> hi, everyone
> i have programe a small application using Qt and OpenGL,but it seems
> have some errors which i can't solve, that is , the triangle and quads
> don't rotate at all. some codes are as follows:
>
> GLWidget::GLWidget(QWidget *parent,)
> : QGLWidget(parent)
> {
> rTri = 0.0;
> rQuad = 0.0;
>
> ...
>
> }
>
> void GLWidget::paintGL()
> {
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
>
> glLoadIdentity();
> glTranslatef(-1.5, 0.0, -6.0);
> glRotatef(rTri, 0.0, 1.0, 0.0);
>
> glBegin(GL_TRIANGLES);
> glColor3f(1.0, 0.0, 0.0);
> glVertex3f(0.0, 1.0, 0.0);
> glColor3f(0.0, 1.0, 0.0);
> glVertex3f(-1.0, -1.0, 0.0);
> glColor3f(0.0, 0.0, 1.0);
> glVertex3f(1.0, -1.0, 0.0);
> glEnd();
>
> glLoadIdentity();
> glTranslatef(1.5, 0.0, -6.0);
> glRotatef(rQuad, 1.0, 0.0, 0.0);
> glColor3f(0.5, 0.5, 1.0);
>
> glBegin(GL_QUADS);
> glColor3f( 0.0, 1.0, 0.0 );
> glVertex3f( 1.0, 1.0, -1.0 );
> glVertex3f( -1.0, 1.0, -1.0 );
> glVertex3f( -1.0, 1.0, 1.0 );
> glVertex3f( 1.0, 1.0, 1.0 );
>
> glEnd()
>
> rTri += (GLfloat)0.2;
> rQuad -= (GLfloat)0.15;
> }
>
--
[ signature omitted ]
Message 5 in thread
On Wednesday 2007 April 04 10:25, ååä wrote:
> i have programe a small application using Qt and OpenGL,but it seems have
> some errors which i can't solve, that is , the triangle and quads don't
> rotate at all. some codes are as follows:
This is just a guess - I don't really know anything about OpenGL.
In that code, paintGL() is called which updates the rotation variables - fine.
What triggers the next paintGL() call?
In a normal widget, when you change variables that affect the paintEvent(),
you need to call update(). The same is probably true of openGL.
So - you either need a QTimer() calling (quick look at docs) updateGL(), or
perhaps a call to updateGL() in the paintGL() function would just make it run
as fast as it can.
Andy
--
[ signature omitted ]
Message 6 in thread
Andy Parkins wrote:
> On Wednesday 2007 April 04 10:25, ååä wrote:
>
>> i have programe a small application using Qt and OpenGL,but it seems have
>> some errors which i can't solve, that is , the triangle and quads don't
>> rotate at all. some codes are as follows:
>
> This is just a guess - I don't really know anything about OpenGL.
>
> In that code, paintGL() is called which updates the rotation variables - fine.
> What triggers the next paintGL() call?
>
> In a normal widget, when you change variables that affect the paintEvent(),
> you need to call update(). The same is probably true of openGL.
>
> So - you either need a QTimer() calling (quick look at docs) updateGL(), or
> perhaps a call to updateGL() in the paintGL() function would just make it run
> as fast as it can.
If you call updateGL() in the paintGL() function, it will run as fast as
it can but the event loop will be blocked. If you need to do this, call
update() in the paintGL() function.
>
>
> Andy
--
[ signature omitted ]