PDA

View Full Version : problem with Qt and OpenGL



giorgik
13th February 2013, 16:09
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.

wysota
13th February 2013, 16:18
Please provide a debugger backtrace.

giorgik
13th February 2013, 18:40
Yes wysota: Segmentation Fault SIGSEGV in
Tessellator_class::Polygon_type_enum Tessellator_class::tessellate(...) :


for (unsigned int i = 0u;
(!s_is_self_intersecting_polygon) || (i < (vertex_count * 3u)); i += 3u) // * 3u gives coords count
{
gluTessVertex (s_tess_obj_ptr, & (vertex_ptr [i]), & (vertex_ptr [i]));
}

I rewrote the project file tesselation.pro using the freeglut libraries for MinGW:


DEFINES += FREEGLUT_STATIC
INCLUDEPATH += C:/MinGW/freeglut/include
LIBS += -lglu32 -lopengl32 -lwinmm \
-LC:/MinGW/freeglut/lib -lfreeglut_static -lopengl32 -lwinmm -lgdi32

d_stranz
13th February 2013, 18:45
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).

giorgik
13th February 2013, 18:54
thanks d_stranz, but as a result I get a window with a black background and no figure

d_stranz
13th February 2013, 19:11
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.

giorgik
14th February 2013, 10:07
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:


#define FOR_EACH(I,C) for(VAR(I, (C).begin()), ite = (C).end(); (I) != ite; ++(I))
...
gluTessBeginPolygon(tobj, NULL);

FOR_EACH( contour, contours )
{
gluTessBeginContour(tobj);

for( size_t v = 0; v < contour->size(); v += 3 )
gluTessVertex(tobj, &(*contour)[v], &(*contour)[v]);

gluTessEndContour(tobj);
}

//GG-d: start
if (DEBUG)
printf("\nGG-d (1) BlockGroup::BuildDisplayList()\n");
//GG: end

gluTessEndPolygon(tobj);
...

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

wysota
14th February 2013, 12:33
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.

giorgik
14th February 2013, 17:26
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.

wysota
14th February 2013, 20:24
We are more experienced at Qt, not at OpenGL and your issue is related to OpenGL and not Qt.

d_stranz
14th February 2013, 22:58
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:


// Callback function for beginning a contour.
void CALLBACK Tessellator_class::begin_callback (GLenum which)
{
glBegin( which );
}

// Callback function for defining new vertex of contour.
void CALLBACK Tessellator_class::vertex_callback (GLvoid * vertex_ptr)
{
glVertex3dv( (const GLdouble *)vertex_ptr );
}

// Callback function for ending a contour.
void CALLBACK Tessellator_class::end_callback (void)
{
glEnd();
}


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. (http://www.songho.ca/opengl/gl_tessellation.html) 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".

giorgik
15th February 2013, 10:06
thanks d_stranz, I will follow your advice and thanks for the example that you provided me