我正在使用GLUTess来测试多边形。经过几次测试,我意识到链接到glu32.dll的glu32.lib,偶尔会崩溃一次。而我从opengl sdk获得的GLU,是坚如磐石的。不幸的是,由于没有链接到windows dll,这意味着我需要使用我的应用程序拖动GLU.dll,而不是依赖于Windows的GLU32.dll。是否有可以静态链接的GLU版本?我真的不希望他的小项目有任何dll依赖。
由于
我的tesselator代码:
#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();
}
这里有什么问题吗?
答案 0 :(得分:0)
我建议你在这里只使用C ++的东西而不是混合使用C malloc / free。
而是使用向量&lt;&gt;对于所有您的数组
答案 1 :(得分:0)
SGI将其测试人员送到Mesa3D.org,所以只需从台面下载glu,编译和链接。但是您必须将项目设置从DLL更改为LIB。