I am working on converting a pure GLUT/OpenGL/OpenCL code into Qt/OpenGL/OpenCL. For this, I use QGLWidget subclass named "GLWidget" for displaying the animation. My issue is that I would like to keep the GLUT displayfunc working of the first code : in main GLUT loop, I used `glutDisplayFunc(displayfunc);`

So, in the Qt/OpenGL, I tried to do this :

Qt Code:
  1. void GLWidget::initializeGL()
  2. {
  3. LoadGLTextures(); // load the textures.
  4. glClearColor(0.0 ,0.0, 0.0, 0.0);
  5. glMatrixMode(GL_PROJECTION);
  6. glLoadIdentity();
  7.  
  8. m_program = _compileProgram(vertexShader);
  9.  
  10. glClampColor(GL_CLAMP_VERTEX_COLOR, GL_FALSE);
  11.  
  12. // memsize of GPU data
  13. unsigned int memSize = sizeof(cl_double4) * 4 * Galaxy->getNumParticles();
  14.  
  15. createVBO(memSize);
  16.  
  17. m_timer = new QTimer(this);
  18. connect(m_timer, SIGNAL(timeout()), this, SLOT(displayfunc()));
  19. m_timer->start(30);
  20. }
To copy to clipboard, switch view to plain text mode 
with displayfunc :



Qt Code:
  1. void GLWidget::displayfunc()
  2. {
  3. if (Galaxy->isFirstLaunch)
  4. {
  5. gluLookAt (0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  6. glScalef(0.03f, 0.03f, 0.03f);
  7. drawPoints();
  8. //Calling kernel for calculatig subsequent positions
  9. Galaxy->runCLKernels();
  10. Galaxy->isFirstLaunch = false;
  11. glFlush();
  12. swapBuffers();
  13. return;
  14. }
  15. else {
  16. clWaitForEvents(1, &Galaxy->glEvent);
  17. drawPoints();
  18. //Calling kernel for calculatig subsequent positions
  19. Galaxy->runCLKernels();
  20. glFlush();
  21. swapBuffers();
  22. }
  23. update();
  24. }
To copy to clipboard, switch view to plain text mode 

and drawPoints :

Qt Code:
  1. void GLWidget::drawPoints()
  2. {
  3. glClear(GL_COLOR_BUFFER_BIT);
  4. glClear(GL_DEPTH_BUFFER_BIT);
  5. glEnable(GL_POINT_SPRITE);
  6. glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE);
  7. glEnable(GL_VERTEX_PROGRAM_POINT_SIZE_NV);
  8.  
  9. glEnable(GL_BLEND);
  10. glBlendFunc (GL_SRC_ALPHA, GL_ONE);
  11.  
  12. glUseProgram(m_program);
  13. glUniform1f( glGetUniformLocation(m_program, "pointRadius"), m_particleRadius );
  14. glUniform1f( glGetUniformLocation(m_program, "pointScale"),m_pointScale);
  15.  
  16. GLuint vbo_disk;
  17.  
  18. glBindBuffer(GL_ARRAY_BUFFER, vbo_disk);
  19. glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), Galaxy->pos);
  20. glEnableClientState(GL_VERTEX_ARRAY);
  21.  
  22. glColor4f(1.0f, 1.0f, 1.0f, 0.1f);
  23. glDrawArrays(GL_POINTS, 0, Galaxy->getNumParticles_disk());
  24.  
  25. glBindBuffer(GL_ARRAY_BUFFER, 0);
  26. glDisableClientState(GL_VERTEX_ARRAY);
  27.  
  28. GLuint vbo_halo;
  29.  
  30. glBindBuffer(GL_ARRAY_BUFFER, vbo_halo);
  31. glVertexPointer(4, GL_DOUBLE, 4*sizeof(double), &Galaxy->pos[Galaxy->getNumParticles_disk()]);
  32. glEnableClientState(GL_VERTEX_ARRAY);
  33.  
  34. glColor4f(0.0f, 0.0f, 1.0f, 0.1f);
  35. glDrawArrays(GL_POINTS, 0, Galaxy->getNumParticles_halo());
  36.  
  37. glBindBuffer(GL_ARRAY_BUFFER, 0);
  38. glDisableClientState(GL_VERTEX_ARRAY);
  39.  
  40. glDisable(GL_BLEND);
  41. glDisable(GL_POINT_SPRITE);
  42. }
To copy to clipboard, switch view to plain text mode 

Can I do without paintGL() function ?

I tried to add makeCurrent() into all the functions containing OpenGL functions but nothing displays in GLWidget, just black screen because of `glClearColor(0.0 ,0.0, 0.0, 0.0)`

Could you see what's wrong ?