Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


glu tessellation not working


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Zotoaster   Members   -  Reputation: 148

Like
0Likes
Like

Posted 02 November 2013 - 02:53 PM

I'm trying to render a 2D polygon using glu's tessellation facilities. However I'm not seeing anything.

 

Here's my code:

        GLUtesselator * tess = gluNewTess();
        
        gluTessCallback(tess, GLU_TESS_VERTEX,  (GLvoid (*) ()) &poly_vert_callvack);
        gluTessCallback(tess, GLU_TESS_BEGIN,   (GLvoid (*) ()) &poly_begin_callback);
        gluTessCallback(tess, GLU_TESS_END,     (GLvoid (*) ()) &poly_end_callback);
        gluTessCallback(tess, GLU_TESS_ERROR,   (GLvoid (*) ()) &poly_error_callback);
        gluTessCallback(tess, GLU_TESS_COMBINE, (GLvoid (*) ()) &poly_combine_callback);
        
        gluTessBeginPolygon(tess, NULL);
        gluTessBeginContour(tess);

        for (size_t v = 0; v < _vert.size(); v++)
        {
            GLdouble vert[3] = {(double)_vert[v].X, (double)_vert[v].Y, 0.0};
            gluTessVertex(tess, vert, vert);
        }

        gluTessEndContour(tess);
        gluTessEndPolygon(tess);
        
        gluDeleteTess(tess);

[Edit]

 

Also here are the callback functions:

void poly_begin_callback(GLenum wh)
    {
        glBegin(wh);
    }
    void poly_vert_callvack(GLvoid *vertex)
    {
        const GLdouble *pointer;
        
        pointer = (GLdouble *) vertex;
        glVertex3dv(pointer);
    }
    void poly_end_callback(void)
    {
        glEnd();
    }
    void poly_error_callback(GLenum errorCode)
    {
        const GLubyte *estring;
        
        estring = gluErrorString(errorCode);
        fprintf (stderr, "Tessellation Error: %s\n", estring);
        exit (0);
    }
    void poly_combine_callback(GLdouble coords[3], 
                               GLdouble *vertex_data[4],
                               GLfloat weight[4], GLdouble **dataOut )
    {
        GLdouble *vertex;
        int i;
        
        vertex = (GLdouble *) malloc(6 * sizeof(GLdouble));
        vertex[0] = coords[0];
        vertex[1] = coords[1];
        vertex[2] = coords[2];
        for (i = 3; i < 7; i++)
            vertex[i] = weight[0] * vertex_data[0][i] 
            + weight[1] * vertex_data[1][i]
            + weight[2] * vertex_data[2][i] 
            + weight[3] * vertex_data[3][i];
        *dataOut = vertex;
    }

The colour is set at some point before. Anyone see any problems here? Thanks


Edited by Zotoaster, 02 November 2013 - 02:54 PM.


Sponsor:

#2 Zotoaster   Members   -  Reputation: 148

Like
0Likes
Like

Posted 03 November 2013 - 04:07 PM

Okay I got it fixed. Turns out it stores references to vertices before actually creating them in the 'gluTessEndPolygon()' function. So it was assuming all vertices were the last vertex I gave it. It also wanted 3D vertices which means by polygon class has to have two versions of the vertex list (it could just use the 3d one but then it wouldn't interface well with the rest of the program).






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS