views:

111

answers:

2

I'm using GLUTess to tesselate polygons. After several tests, I realized glu32.lib which links to glu32.dll, crashes every once in a while. Whereas GLU which I got from the opengl sdk, is solid as a rock. Unfortunately though, by not linking to the windows dll, this means I need to drag around GLU.dll with my app instead of relying on Windows's GLU32.dll. Is there a version of GLU which is static linkable? I really do not want to have any dll dependencies for his small project.

Thanks

My tesselator code:

#include "StdAfx.h"
#include "CGlTesselator.h"
std::vector<GLdouble*> gluptrvec;
std::vector<GLfloat> tempvct;
std::vector<GLfloat> tempvcttex;
POINTFLOAT CurrentDimensions;
POINTFLOAT CurrentMinima;

void CALLBACK combineCallback(GLdouble coords[3], GLdouble *vertex_data[4],
                              GLdouble weight[4], GLdouble **dataOut)
{
    GLdouble *vertex;

    vertex = (GLdouble *) malloc(6 * sizeof(GLdouble));
    if(vertex == NULL)
    {

        MessageBox(0,0,0,0);
    }
    vertex[0] = coords[0];
    vertex[1] = coords[1];
    //vertex[2] = coords[2];




    *dataOut = vertex;
    gluptrvec.push_back(vertex);

}


void CALLBACK vertexCallback(GLvoid *vertex)
{

    GLdouble *ptr;

    ptr = (GLdouble *) vertex;

    if(ptr == NULL)
    {
        MessageBox(0,0,0,0);
    }
    double x = ptr[0];
    double y = ptr[1];

    double s = (x - CurrentMinima.x) / CurrentDimensions.x;
    double t = (y - CurrentMinima.y) / CurrentDimensions.y;
    tempvct.push_back((GLfloat)x);
    tempvct.push_back((GLfloat)y);
    tempvcttex.push_back((GLfloat)s);
    tempvcttex.push_back((GLfloat)t);
    //glTexCoord2d(s,t);

    //glVertex2dv((GLdouble *) ptr);



}

void CALLBACK edgeflags(int flag)
{

}

CGlTesselator::CGlTesselator(void)
{
    Init();
}
int CGlTesselator::Init(GLvoid)
{
    // Create a new tessellation object 
    tobj = gluNewTess(); 

    // Set callback functions
    gluTessCallback(tobj, GLU_TESS_VERTEX, (GLvoid (_stdcall *)(void) ) &vertexCallback);
    gluTessCallback(tobj, GLU_TESS_BEGIN,  (GLvoid (_stdcall *)(void) ) &glBegin);
    gluTessCallback(tobj, GLU_TESS_END,  (GLvoid (_stdcall *)(void) ) &glEnd);
    gluTessCallback(tobj, GLU_TESS_COMBINE,  (GLvoid (_stdcall *)(void) )&combineCallback);
    gluTessCallback(tobj, GLU_EDGE_FLAG,  (GLvoid (_stdcall *)(void) )&edgeflags);

    return(1);
}

int CGlTesselator::Set_Winding_Rule(GLenum winding_rule)
{
    // Set the winding rule
    gluTessProperty(tobj, GLU_TESS_WINDING_RULE, winding_rule); 

    return(1);
}


int CGlTesselator::Render_Contour(GLdouble obj_data[][6], int num_vertices)

{

    for (int x = 0; x < num_vertices; ++x) //loop through the vertices
    {

        gluTessVertex(tobj, obj_data[x], obj_data[x]); //store the vertex


    }


    return(1);
}


int CGlTesselator::Begin_Polygon(GLvoid)
{
    gluTessBeginPolygon(tobj, NULL);

    return(1);
}

int CGlTesselator::End_Polygon(GLvoid)
{
    try
    {
        gluTessEndPolygon(tobj);
    }
    catch (int ix)
    {

    }



    if(gluptrvec.size() > 0)
    {
        for(unsigned int i = 0; i < gluptrvec.size(); i++)
        {

            free(gluptrvec[i]);
        }
    }
        gluptrvec.clear();

    return(1);
}


int CGlTesselator::Begin_Contour(GLvoid)
{
    gluTessBeginContour(tobj);

    return(1);
}


int CGlTesselator::End_Contour(GLvoid)
{   
    try
    {
        if(tobj == NULL)
        {
            MessageBox(0,0,0,0);
        }
        gluTessEndContour(tobj);
    }
    catch (...)
    {

    }


    return(1);
}


int CGlTesselator::End(GLvoid)
{
    gluDeleteTess(tobj);

    return(1);
}

void CGlTesselator::SetDimensions(POINTFLOAT dims, POINTFLOAT min)
{
    CurrentDimensions = dims;
    CurrentMinima = min;
}

CGlTesselator::~CGlTesselator(void)
{
    End();
}

void CGlTesselator::TransferVerticies(GLuint &polyvbo, GLuint &texvbo,UINT &vbocount, UINT &texcount)
{

    if (tempvct.size() > 0)
    {
        glBindBufferARB(GL_ARRAY_BUFFER_ARB,polyvbo);
        glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(GLfloat) * tempvct.size(),&tempvct[0],GL_STATIC_COPY);

        glBindBufferARB(GL_ARRAY_BUFFER_ARB,texvbo);

        glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(GLfloat) * 
            tempvcttex.size(),&tempvcttex[0],GL_STATIC_COPY);
    }


    vbocount = tempvct.size();
    texcount = tempvcttex.size();

    tempvct.clear();
    tempvcttex.clear();

}

Is there something wrong here?

A: 

I would propose you use only C++ stuff here and not mix in C malloc/free.

Instead use a vector<> for all your arrays

Anders K.
? I'm sorry but I really can't see the connection between the question and your answer ?
Calvin1602
my guess was that the reason why he was experiencing issues was that he was referencing malloced memory blocks ('vertex') from a stl container. there is no real reason why one would use malloc/free here in this context anyway when a vector could do the job
Anders K.
A: 

SGI gave away its tesselator to Mesa3D.org, so just download glu from mesa, compile and link. But you'll have to change the project settings from DLL to LIB.

Calvin1602