My target is to use QtCreator as IDE and compiler MinGW. Below I command (command line) to successfully compile the file sphere.cpp
Qt Code:
  1. C:\Qt\progetti\FLTK\OpenGLSphere>g++ -I C:/MinGW/include -I C:/MinGW/include/FL/images -mwindows -DWIN32 -DUSE_OPENGL32 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -o 'sphere' 'sphere.cpp' -mwindows C:/MinGW/lib/libfltk_gl.a -lglu32 -lopengl32 C:/MinGW/lib/libfltk.a -lole32 -luuid -lcomctl32
To copy to clipboard, switch view to plain text mode 
sphere.cpp:
Qt Code:
  1. #include <FL/Fl.H>
  2. #include <FL/Fl_Window.H>
  3. #include <FL/glut.H>
  4. #include <FL/gl.h>
  5. #define WIDTH 640
  6. #define HEIGHT 480
  7. //
  8. // Render a simple opengl shaded sphere with a single side light -- erco 11/28/08
  9. //
  10. // 1.1 Mods to use pure glut calls for subwindow -- erco 03/15/11
  11. //
  12. // You can build this example with: fltk-config --use-glut --compile sphere.cxx
  13. //
  14.  
  15. // GLUT: RESHAPE THE VIEWPORT
  16. void Reshape(int W, int H) {
  17. // (REFERENCE: SGI light.c DEMO)
  18. GLfloat ratio = (float)W / (float)H;
  19. glViewport(0, 0, (GLsizei)W, (GLsizei)H);
  20. glMatrixMode(GL_PROJECTION);
  21. glLoadIdentity();
  22. glOrtho(-1.5*ratio, 1.5*ratio, -1.5, 1.5, -10.0, 10.0);
  23. glMatrixMode(GL_MODELVIEW);
  24. glLoadIdentity();
  25. }
  26. // GLUT: REDRAW THE SCENE
  27. void Redraw() {
  28. static int valid = 0;
  29. if (!valid) {
  30. valid = 1;
  31. Reshape(WIDTH, HEIGHT);
  32. // (REFERENCE: SGI 'light.c' EXAMPLE)
  33. GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
  34. GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
  35. GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
  36. GLfloat light_position[] = { 5.0, 5.0, 0.0, 0.0 }; // XYZ
  37. glClearColor(0.0, 0.0, 0.4, 0.0); // bg color
  38. glShadeModel(GL_SMOOTH);
  39. //
  40. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  41. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  42. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  43. glMaterialf(GL_FRONT, GL_SHININESS, 20.0);
  44. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  45. //
  46. glEnable(GL_LIGHTING);
  47. glEnable(GL_LIGHT0);
  48. glEnable(GL_DEPTH_TEST);
  49. }
  50. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  51. glPushMatrix();
  52. glColor3f(0.5, 0.5, 0.5);
  53. glutSolidSphere(0.5, 30, 30);
  54. glPopMatrix();
  55. }
  56. int main(int argc, char *argv[]) {
  57. Fl_Window win(WIDTH, HEIGHT, "sphere");
  58. win.resizable(win);
  59. win.show(argc, argv);
  60. // Docs say to add glut subwindow /after/ calling win.show()
  61. win.begin();
  62. // glutInit(&argc, argv); // docs say not to call this if a subwindow
  63. glutInitWindowSize(WIDTH-20, HEIGHT-20);
  64. glutInitWindowPosition(10,10); // place inside parent window
  65. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
  66. glutCreateWindow("sphere");
  67. glutReshapeFunc(Reshape);
  68. glutDisplayFunc(Redraw);
  69. win.end();
  70. return(Fl::run());
  71. }
To copy to clipboard, switch view to plain text mode 
In the file sphere.pro as I set to get a successful compilation ?