// Generates a display list based on the data in the patch// and the number of divisionsGLuint genBezier(BEZIER_PATCH patch, int divs) { int u = 0, v; float py, px, pyold; GLuint drawlist = glGenLists(1); POINT_3D temp[4]; POINT_3D *last = (POINT_3D*)malloc(sizeof(POINT_3D)*(divs+1)); // array of points to mark the first line of polys if (patch.dlBPatch != 0) glDeleteLists(patch.dlBPatch, 1); temp[0] = patch.anchors[0][3]; temp[1] = patch.anchors[1][3]; temp[2] = patch.anchors[2][3]; temp[3] = patch.anchors[3][3]; for (v=0;v<=divs;v++) { px = ((float)v)/((float)divs); last[v] = Bernstein(px, temp); } glNewList(drawlist, GL_COMPILE); glBindTexture(GL_TEXTURE_2D, patch.texture); for (u=1;u<=divs;u++) { py = ((float)u)/((float)divs); pyold = ((float)u-1.0f)/((float)divs); temp[0] = Bernstein(py, patch.anchors[0]); temp[1] = Bernstein(py, patch.anchors[1]); temp[2] = Bernstein(py, patch.anchors[2]); temp[3] = Bernstein(py, patch.anchors[3]); glBegin(GL_TRIANGLE_STRIP); for (v=0;v<=divs;v++) { px = ((float)v)/((float)divs); glTexCoord2f(pyold, px); glVertex3d(last[v].x, last[v].y, last[v].z); last[v] = Bernstein(px, temp); glTexCoord2f(py, px); glVertex3d(last[v].x, last[v].y, last[v].z); } glEnd(); } glEndList(); free(last); return drawlist; }
The "last" array keeps the previous line of points
for (v=0;v<=divs;v++) { px = ((float)v)/((float)divs); glTexCoord2f(pyold, px); glVertex3d(last[v].x, last[v].y, last[v].z); last[v] = Bernstein(px, temp); glTexCoord2f(py, px); glVertex3d(last[v].x, last[v].y, last[v].z);
so i need to save last[0] and last[1] in some temporary points and then take last[0] from second loop (for v=1)?
EDIT: put code in [ source lang="cpp"] [ /source] tags (without the space after [).
[Edited by - Caste on December 29, 2010 4:05:20 AM]