Results 1 to 12 of 12

Thread: problem with Qt and OpenGL

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

    Default problem with Qt and OpenGL

    Hello everyone, I can not understand what's wrong with this project that uses gluTesselation in Qt. I put in attachment the whole Qt project (version 4.8.2, QtCreator 2.5.2, MinGW 4.6.2).
    The compilation is OK, but when I start the executable (in Windows XP) I get a crash on glu32.dll.
    Can you help me, I do not know what to do.
    Attached Files Attached Files

  2. #2
    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: problem with Qt and OpenGL

    Please provide a debugger backtrace.
    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
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: problem with Qt and OpenGL

    Yes wysota: Segmentation Fault SIGSEGV in
    Tessellator_class::Polygon_type_enum Tessellator_class::tessellate(...) :
    Qt Code:
    1. for (unsigned int i = 0u;
    2. (!s_is_self_intersecting_polygon) || (i < (vertex_count * 3u)); i += 3u) // * 3u gives coords count
    3. {
    4. gluTessVertex (s_tess_obj_ptr, & (vertex_ptr [i]), & (vertex_ptr [i]));
    5. }
    To copy to clipboard, switch view to plain text mode 
    I rewrote the project file tesselation.pro using the freeglut libraries for MinGW:
    Qt Code:
    1. DEFINES += FREEGLUT_STATIC
    2. INCLUDEPATH += C:/MinGW/freeglut/include
    3. LIBS += -lglu32 -lopengl32 -lwinmm \
    4. -LC:/MinGW/freeglut/lib -lfreeglut_static -lopengl32 -lwinmm -lgdi32
    To copy to clipboard, switch view to plain text mode 
    Last edited by giorgik; 13th February 2013 at 18:46.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: problem with Qt and OpenGL

    On my Windows box, the loop beginning at line 118 in Tesselator.cpp causes an access violation on the call to gluTessVertex(). The loop index i has the value 1389 at that point, which is way more than the maximum limit of 30.

    The problem is in your loop termination check in line 119: the "||" should be "&&". As it now stands, if you have no self-intersecting polygons, the loop will merrily keep incrementing forever (or until you get an access violation).

  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: problem with Qt and OpenGL

    thanks d_stranz, but as a result I get a window with a black background and no figure

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: problem with Qt and OpenGL

    Don't know how GLUtesselator works, but I don't see where you are actually issuing any calls to draw something on screen. You clear it in initializeGL(), but where is the drawing code? Seems to me you need to implement paintGL() and retrieve the polygons from the GLUtesselator instance for display. Don't forget to set the color to something other than black.

  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: problem with Qt and OpenGL

    thanks d_stranz :-) I've been very helpful.
    Also for tesselation, I have another piece of code that I found in a project called Stage (player-stage, gazebo), in which we have:
    Qt Code:
    1. #define FOR_EACH(I,C) for(VAR(I, (C).begin()), ite = (C).end(); (I) != ite; ++(I))
    2. ...
    3. gluTessBeginPolygon(tobj, NULL);
    4.  
    5. FOR_EACH( contour, contours )
    6. {
    7. gluTessBeginContour(tobj);
    8.  
    9. for( size_t v = 0; v < contour->size(); v += 3 )
    10. gluTessVertex(tobj, &(*contour)[v], &(*contour)[v]);
    11.  
    12. gluTessEndContour(tobj);
    13. }
    14.  
    15. //GG-d: start
    16. if (DEBUG)
    17. printf("\nGG-d (1) BlockGroup::BuildDisplayList()\n");
    18. //GG: end
    19.  
    20. gluTessEndPolygon(tobj);
    21. ...
    To copy to clipboard, switch view to plain text mode 
    when it comes to perform "gluTessEndPolygon(tobj);" I have a segmentation fault error.
    I tried to debug as you did in the previous example, but it seems perfectly proper, not exceeding in size any variable.
    Do you think there is some error in the code that I have reported. If you can help put attached the whole project (always done with QtCreator and MinGW)... I'm literally going crazy

  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: problem with Qt and OpenGL

    I suggest you don't use any code without proper understanding what it does first. Blindly copying code from one project to another will take you where you are now -- wondering why it doesn't work.
    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: problem with Qt and OpenGL

    Wysota You're right, but it's a long time that I analyze and are now at a standstill. For this I turned to you who are more experienced than me.
    The problem is that I'm trying to make a porting from Linux to Windows using MinGW (which has libraries that are similar to Linux GCC) and Qt. For the moment, the other project Stage (also for Linux that I brought in Windows) now appears in part work.

  10. #10
    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: problem with Qt and OpenGL

    We are more experienced at Qt, not at OpenGL and your issue is related to OpenGL and not Qt.
    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.


  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: problem with Qt and OpenGL

    I'm literally going crazy
    So are we.

    As I said in my previous response, you are creating the tesselated polygons, but you aren't issuing any OpenGL calls to render them. The code you have written in the constructor of your Tesselation class does not render anything which is why you are getting a black window with nothing in it.

    Your tesselation callback methods must contain the OpenGL drawing commands you need:

    Qt Code:
    1. // Callback function for beginning a contour.
    2. void CALLBACK Tessellator_class::begin_callback (GLenum which)
    3. {
    4. glBegin( which );
    5. }
    6.  
    7. // Callback function for defining new vertex of contour.
    8. void CALLBACK Tessellator_class::vertex_callback (GLvoid * vertex_ptr)
    9. {
    10. glVertex3dv( (const GLdouble *)vertex_ptr );
    11. }
    12.  
    13. // Callback function for ending a contour.
    14. void CALLBACK Tessellator_class::end_callback (void)
    15. {
    16. glEnd();
    17. }
    To copy to clipboard, switch view to plain text mode 

    But the problem with your code is that the tesselation is performed in the constructor, before the QGLWidget:: initializeGL() method has been invoked to set up the OpenGL environment. So all of these callback are issuing OpenGL commands that simply disappear because OpenGL hasn't been initialized yet. Prove it yourself - set breakpoints on initializeGL() and on the begin_callback() methods and see which one gets called first

    Look at this example. Download the zip file and look to see what is happening there. If you don't understand it, then you need to sit down with an OpenGL book and study it. As wysota says, simply cutting and pasting code without understanding what it is doing or why will get you nowhere.

    Google is your friend. There are many other OpenGL tesselation examples out there. Just google for "OpenGL tesselation".

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

    Default Re: problem with Qt and OpenGL

    thanks d_stranz, I will follow your advice and thanks for the example that you provided me

Similar Threads

  1. Problem with opengl
    By rajg in forum Newbie
    Replies: 13
    Last Post: 31st July 2012, 07:37
  2. Problem from OpenGL to QT OpenGL
    By nuts_fever_007 in forum Newbie
    Replies: 5
    Last Post: 15th May 2009, 09:37
  3. opengl problem
    By drinu21 in forum Qt Programming
    Replies: 3
    Last Post: 28th December 2007, 11:30
  4. Qt 4.2.0 OpenGL problem
    By mbjerkne in forum Qt Programming
    Replies: 1
    Last Post: 14th October 2006, 18:39

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.