Results 1 to 9 of 9

Thread: Example Q, FLTKt and OpenGL without using QOpenGL

  1. #1
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Example Q, FLTKt and OpenGL without using QOpenGL

    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 ?

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    you havent linked it properly. This is qt programming forum. Where is your qt programming question?

    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:
    What?
    "fails to compile in mingw fine"
    doesn't make sense.

    but if I try to do it in the ide QtCreator 2.6.0 fails as it finds defined 2 functions
    qt creator will be using mingw. The problem is the the linker DOESNT find symbols, not that "it finds defined 2 functions".
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  3. #3
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    sorry it was a mistake in translation from Italian to English.
    Using MinGW with MSYS: OK, compiled
    Using MinGW with QtCreator: KO all, not compiled

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    So why don't you continue using MinGW with MSYS if it works fine?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    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 ?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    If you mean that you want to change direct invokation of the compiler into managing your project by qmake then if you want to link an external library to your project, you have to inform qmake about it by modifying the LIBS variable. You can see the compiler invokation qmake does and you can compare it to yours to see the difference. I'm assuming this will be that you are using a static version of the Fltk library in your direct invokation which is not reflected in your qmake project.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    Yes, Fltk libraries are static and therefore should be linked to main.o I was hoping you'd tell me how is the corresponding write sphere.pro known command from the command line with MinGW ...
    I'll have to experiment and go trial

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    It's exactly the same as your direct call. You need to add the same directive you have in your direct invokation to the LIBS variable in the project file (e.g. "LIBS+=C:/MinGW/lib/libfltk_gl.a", etc.)
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Apr 2010
    Location
    Italia
    Posts
    149
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Example Q, FLTKt and OpenGL without using QOpenGL

    Yes,
    Qt Code:
    1. #------------------------------------------------
    2. #
    3. # Uso librerie FLTK 1.3.1
    4. #
    5. #------------------------------------------------
    6. INCLUDEPATH += C:/MinGW/include \
    7. C:/MinGW/include/FL/images
    8.  
    9. LIBS += -mwindows
    10.  
    11. DEFINES += WIN32 USE_OPENGL32 LARGEFILE_SOURCE LARGEFILE64_SOURCE
    12.  
    13. LIBS += -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 

    I have another question for you, but it is part of another topic "create in Qt command script fltk-config". Please give us a look ?

Similar Threads

  1. QOpenGL in threads
    By wydesenej in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2013, 15:11
  2. converting GLUT/OpenGL to Qt/OpenGL - displaying issue
    By yoti13 in forum Qt Programming
    Replies: 1
    Last Post: 25th November 2012, 00:45
  3. [Qt 4.6.3/OpenGL 4.1] : Unrecognized OpenGL
    By didier in forum Qt Programming
    Replies: 3
    Last Post: 5th August 2011, 23:33
  4. Replies: 0
    Last Post: 6th December 2009, 00:41
  5. Qt with OpenGL ES for ARM9 - All OpenGL ES tests have failed!
    By vinpa in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 3rd December 2009, 10:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.