Results 1 to 9 of 9

Thread: Example Q, FLTKt and OpenGL without using QOpenGL

Hybrid View

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

    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 ?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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

    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

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    3
    Thanked 5,019 Times in 4,795 Posts
    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.


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
  •  
Qt is a trademark of The Qt Company.