Tessellation - saving data

180 Views Asked by At

I am using tessellation in order to transfer non triangled polygons to triangle polygons. I am trying to save the data in variable and run the tessellation code once while saving the data. The code use the saved data in order to draw it in draw function.

I am trying the draw a star polygon, The problem is that I can see some triangles but not a star. Why when I save the data the drawing go wrong?

Here is the initialize code:

#define callback void(CALLBACK*)()
void Init()
{
    GLdouble star[5][6] = /* star data, The data is 100% perfect */


    glColor3f(0.0f, 1.0f, 0.0f);

    GLUtesselator *pTess = gluNewTess();

    indexNum = 0;
    gluTessCallback(pTess, GLU_TESS_BEGIN,      (callback)glDrowMode);
    gluTessCallback(pTess, GLU_TESS_VERTEX,     (callback)saveData);
    gluTessCallback(pTess, GLU_TESS_ERROR,      (callback)tessError);
    gluTessCallback(pTess, GLU_TESS_COMBINE,    (callback) scbCombine);


    gluTessProperty(pTess, GLU_TESS_WINDING_RULE, GLU_TESS_WINDING_NONZERO);
    gluTessBeginPolygon(pTess, NULL); 

    gluTessBeginContour(pTess);
    for(int i = 0; i < 5; i++)
        gluTessVertex(pTess, star[i], star[i]);
    gluTessEndContour(pTess);

    gluTessEndPolygon(pTess);
    gluDeleteTess(pTess);
}

The saving data code and saving the drawing mode:

struct vecStruct
{
    GLdouble *vertex, *color;
};
vecStruct vec[16];


int indexNum = 0;
void CALLBACK saveData(const GLvoid *ptr)
{
    const GLdouble *data = (const GLdouble*)ptr;

    vec[indexNum].vertex = new GLdouble[3];
    vec[indexNum].color = new GLdouble[3];
    vec[indexNum].vertex[0] = data[0];
    vec[indexNum].vertex[1] = data[1];
    vec[indexNum].vertex[2] = data[2];
    vec[indexNum].color[0] = data[3];
    vec[indexNum].color[1] = data[4];
    vec[indexNum].color[2] = data[5];

    indexNum++;
}


GLenum drawMode;
void CALLBACK glDrowMode(GLenum where)
{
    drawMode = where;
}

And last the drow function:

void vboDraw()
{
    glBegin(drawMode);
    for (int i = 0; i < indexNum; i++)
    {
        glColor3dv(vec[i].color);
        glVertex3dv(vec[i].vertex); 
    }
    glEnd();

}

As I have said I should see star:

enter image description here

But what I can see is some triangles:

enter image description here

What is wrong with the code? Why can not I save the data for doing the tessellation code only once?

0

There are 0 best solutions below