Hello to all. I found an example of a program that uses the libraries FLTK and OpenGL. These same examples can be used very well in Qt. Below I report the sample project.
OpenGLSphere.pro:
Qt Code:
  1. QT += core
  2. QT -= gui
  3.  
  4. TARGET = OpenGLSphere
  5. #CONFIG += console così non appare la finestra dos
  6. CONFIG -= app_bundle
  7.  
  8. TEMPLATE = app
  9.  
  10. #------------------------------------------------
  11. #
  12. # Uso librerie FLTK 1.3.1
  13. #
  14. #------------------------------------------------
  15. INCLUDEPATH += C:/MinGW/include \
  16. C:/MinGW/include/FL/images
  17.  
  18. DEFINES += WIN32 USE_OPENGL32="1" LARGEFILE_SOURCE="1" LARGEFILE64_SOURCE="1"
  19.  
  20. LIBS += -mwindows \
  21. -L C:/MinGW/lib \
  22. -lfltk \
  23. -lfltk_forms \
  24. -lfltk_gl \
  25. -lfltk_images \
  26. -lfltk_jpeg \
  27. -lfltk_png \
  28. -lfltk_z \
  29. -lole32 -luuid -lcomctl32
  30.  
  31. #------------------------------------------------
  32. #
  33. # Uso librerie Gl (OpenGL)
  34. #
  35. #------------------------------------------------
  36. LIBS += -L C:/MinGW/lib \
  37. #-lglaux \
  38. -lopenglut \
  39. -lglu32 \
  40. -lopengl32 \
  41. -lwinmm -lgdi32
  42.  
  43.  
  44. SOURCES += main.cpp
  45.  
  46. HEADERS += \
  47. simple.h
To copy to clipboard, switch view to plain text mode 
simple.h:
Qt Code:
  1. #ifndef SIMPLE_H
  2. #define SIMPLE_H
  3.  
  4. #include <FL/Fl.H>
  5. #include <FL/Fl_Window.H>
  6. #include <FL/glut.H>
  7. #include <FL/gl.h>
  8.  
  9. #define WIDTH 640
  10. #define HEIGHT 480
  11.  
  12. //
  13. // Render a simple opengl shaded sphere with a single side light -- erco 11/28/08
  14. //
  15. // 1.1 Mods to use pure glut calls for subwindow -- erco 03/15/11
  16. //
  17. // You can build this example with: fltk-config --use-glut --compile sphere.cxx
  18. //
  19.  
  20. // GLUT: RESHAPE THE VIEWPORT
  21. void Reshape(int W, int H)
  22. {
  23. // (REFERENCE: SGI light.c DEMO)
  24. GLfloat ratio = (float)W / (float)H;
  25. glViewport(0, 0, (GLsizei)W, (GLsizei)H);
  26. glMatrixMode(GL_PROJECTION);
  27. glLoadIdentity();
  28. glOrtho(-1.5 * ratio, 1.5 * ratio, -1.5, 1.5, -10.0, 10.0);
  29. glMatrixMode(GL_MODELVIEW);
  30. glLoadIdentity();
  31. }
  32. // GLUT: REDRAW THE SCENE
  33. void Redraw()
  34. {
  35. static int valid = 0;
  36.  
  37. if (!valid)
  38. {
  39. valid = 1;
  40. Reshape(WIDTH, HEIGHT);
  41.  
  42. // (REFERENCE: SGI 'light.c' EXAMPLE)
  43. GLfloat mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
  44. GLfloat mat_diffuse[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
  45. GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 }; // RGBA
  46. GLfloat light_position[] = { 5.0, 5.0, 0.0, 0.0 }; // XYZ
  47. glClearColor(0.0, 0.0, 0.4, 0.0); // bg color
  48. glShadeModel(GL_SMOOTH);
  49.  
  50. //
  51. glMaterialfv(GL_FRONT, GL_AMBIENT, mat_ambient);
  52. glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_diffuse);
  53. glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
  54. glMaterialf(GL_FRONT, GL_SHININESS, 20.0);
  55. glLightfv(GL_LIGHT0, GL_POSITION, light_position);
  56.  
  57. //
  58. glEnable(GL_LIGHTING);
  59. glEnable(GL_LIGHT0);
  60. glEnable(GL_DEPTH_TEST);
  61. }
  62.  
  63. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  64. glPushMatrix();
  65. glColor3f(0.5, 0.5, 0.5);
  66. glutSolidSphere(0.5, 30, 30);
  67. glPopMatrix();
  68. }
  69.  
  70. #endif // SIMPLE_H
To copy to clipboard, switch view to plain text mode 
main.cpp:
Qt Code:
  1. #include "simple.h"
  2.  
  3. int main(int argc, char *argv[])
  4. {
  5. Fl_Window win(WIDTH, HEIGHT, "sphere");
  6. win.resizable(win);
  7. win.show(argc, argv);
  8.  
  9. // Docs say to add glut subwindow /after/ calling win.show()
  10. win.begin();
  11.  
  12. // glutInit(&argc, argv); // docs say not to call this if a subwindow
  13. glutInitWindowSize(WIDTH - 20, HEIGHT - 20);
  14. glutInitWindowPosition(10, 10); // place inside parent window
  15. glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH | GLUT_MULTISAMPLE);
  16. glutCreateWindow("sphere");
  17. glutReshapeFunc(Reshape);
  18. glutDisplayFunc(Redraw);
  19. win.end();
  20. return(Fl::run());
  21. }
To copy to clipboard, switch view to plain text mode 
This code fails to compile in MinGW fine, but if I try to do it in the ide QtCreator 2.6.0 fails as it finds defined 2 functions:
Qt Code:
  1. glut_compatability.cxx:-1: error: undefined reference to `Fl::remove_idle(void (*)(void*), void*)'
  2. glut_compatability.cxx:-1: error: undefined reference to `Fl::add_idle(void (*)(void*), void*)'
To copy to clipboard, switch view to plain text mode 
Can you help me solve this problem ?