gpt4 book ai didi

c++ - 静态链接 GLU?

转载 作者:太空宇宙 更新时间:2023-11-04 04:57:49 27 4
gpt4 key购买 nike

我正在使用 GLUTess 来 segmentation 多边形。经过几次测试,我意识到链接到 glu32.dll 的 glu32.lib 偶尔会崩溃。而我从 opengl sdk 获得的 GLU 是坚如磐石的。不幸的是,由于没有链接到 Windows dll,这意味着我需要在我的应用程序中拖动 GLU.dll,而不是依赖 Windows 的 GLU32.dll。是否有可静态链接的 GLU 版本?我真的不希望他的小项目有任何 dll 依赖。

谢谢

我的 segmentation 器代码:

#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();

}

这里有什么问题吗?

最佳答案

我建议你在这里只使用 C++ 的东西,不要混入 C malloc/free。

而是为所有您的数组使用 vector <>

关于c++ - 静态链接 GLU?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3384344/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com