anon789
14th September 2010, 03:01
Hi,
I am trying to create a really simple application but I can't seem to understand what is going wrong or if what I am trying to do is possible at all (the way I want it, maybe there is a better way).
Basically I want to make an application that draws vectors on the screen. I started by reading the hellogl example provided by trolltech and then started coding. I Created a class GLWidget, which inherits from QGLWidget, redefined painGL, resizeGL, initializeGL, etc.
Everything works fine as long as I use paintGL for the OpenGL API calls, this is a big problem because I wanted to use a class Vector that would contain a method draw() which would draw the vector on the GLWidget. Is this possible? In the Qt4.6 doc it says :
Your widget's OpenGL rendering context is made current when paintGL(), resizeGL(), or initializeGL() is called. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor or in your own paint functions), you must call makeCurrent() first.
void QGLWidget::makeCurrent ()
Makes this widget the current widget for OpenGL operations, i.e. makes the widget's rendering context the current OpenGL rendering context.
Where I am supposed to call makeCurrent? Inside the GLWidget? Outside right before calling vector.draw()? Nothing seems to works.
I read somewhere else that you have to call swapBuffers, but that does not work either. So what I am doing wrong?
I have not been able to find much info concerning Qt + OpenGL on internet. Any help would be greatly appreciated. Thanks in advance.
I am trying to create a really simple application but I can't seem to understand what is going wrong or if what I am trying to do is possible at all (the way I want it, maybe there is a better way).
Basically I want to make an application that draws vectors on the screen. I started by reading the hellogl example provided by trolltech and then started coding. I Created a class GLWidget, which inherits from QGLWidget, redefined painGL, resizeGL, initializeGL, etc.
Everything works fine as long as I use paintGL for the OpenGL API calls, this is a big problem because I wanted to use a class Vector that would contain a method draw() which would draw the vector on the GLWidget. Is this possible? In the Qt4.6 doc it says :
Your widget's OpenGL rendering context is made current when paintGL(), resizeGL(), or initializeGL() is called. If you need to call the standard OpenGL API functions from other places (e.g. in your widget's constructor or in your own paint functions), you must call makeCurrent() first.
void QGLWidget::makeCurrent ()
Makes this widget the current widget for OpenGL operations, i.e. makes the widget's rendering context the current OpenGL rendering context.
Where I am supposed to call makeCurrent? Inside the GLWidget? Outside right before calling vector.draw()? Nothing seems to works.
I read somewhere else that you have to call swapBuffers, but that does not work either. So what I am doing wrong?
I have not been able to find much info concerning Qt + OpenGL on internet. Any help would be greatly appreciated. Thanks in advance.