Advertisement Jump to content
Sign in to follow this  

OpenGL Question about Tesselator,need help.

This topic is 4482 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've write some test code for learning OpenGL tesselator,but i can not get the right result.The real polygon is a simple concave polygon: //vertex array,simple 2D convave polygon const int NUM_POINTS = 5; Gldouble vPoly[NUM_POINTS][2]= { {100,100}, {300,100}, {200,200}, {300,300}, {100,300} }; GLUTesselator m_tessObj; m_=gluNewTess(); // CALLBACK functions gluTessCallback(m_tessObj,GLU_TESS_BEGIN,(void (CALLBACK*)())&BeginCallback); gluTessCallback(m_tessObj,GLU_TESS_VERTEX,(void (CALLBACK*)())&VertexCallback); gluTessCallback(m_tessObj,GLU_TESS_END,(void (CALLBACK*)())&EndCallback); gluTessCallback(m_tessObj,GLU_TESS_COMBINE,(void (CALLBACK*)())CombineCallback); gluTessCallback(m_tessObj,GLU_TESS_ERROR,(void (CALLBACK*)())&ErrorCallback); //tesselating gluTessBeginPolygon(m_tessObj,NULL); gluTessBeginContour(m_tessObj); for(i = 0; i < NUM_POINTS; i++) { gluTessVertex(m_tessObj,vPoly,vPoly); } gluTessEndContour(m_tessObj); gluTessEndPolygon(m_tessObj); glFinish(); gluDeleteTess(m_tessObj); //callback functions void CALLBACK ErrorCallback(GLenum errorCode) { const GLubyte *estring; CString mexstr; estring = gluErrorString(errorCode); mexstr.Format("Tessellation/Quadric Error: %s\n", estring); AfxMessageBox(mexstr,MB_OK | MB_ICONEXCLAMATION); TRACE("Tessellation Error: %s\n", estring); TRACE("\n\n\n\n----------------error callback\n\n\n\n"); } void CALLBACK BeginCallback(GLenum which) { glBegin(which); }; void CALLBACK EndCallback(void) { glEnd(); }; void CALLBACK VertexCallback(GLvoid* vertex) { glVertex2dv((const double *)vertex); TRACE("----------------glVertex called\n"); }; void CALLBACK CombineCallback(GLdouble coords[3], GLdouble *data[4], GLfloat weight[4], GLdouble **dataOut ) { GLdouble *vertex; vertex = new GLdouble[3]; vertex[0] = coords[0]; vertex[1] = coords[1]; vertex[2] = coords[2]; *dataOut = vertex; }; But the tesselatiing result is wrong,unexpected new vertex created near (180,140) in tesselating. "*" is the result, "-" is the real polygon: ---------------------- -***************- ---***********- ----********- -----******- ------****- -------***--- --------**----- ---------*------- ------------------- if move the real polygon to left bottom: GLdouble vPoly[NUM_POINTS][2] = { {0,0}, {200,0}, {100,100}, {200,200}, {0,200} }; the result polygon changed,but is still wrong. Changing the order of the vertex: GLdouble vPoly[NUM_POINTS][2] = { {200,0}, {100,100}, {200,200}, {0,200}, {0,0} }; the result polygon is also wrong. After working on it for many hours,i stil don't know why,anyone could help me?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!