View Full Version : Generalised Subdivision of surfaces - where am I going wrong?

05-04-2015, 05:57 AM
/* Rename the file and save as gendiv.c */


main() {
/* Generalized Subdivision */

void subdivide(float u1[2], float u2[2], float u3[2],
float cutoff, long depth)
GLfloat v1[3], v2[3], v3[3], n1[3], n2[3], n3[3];
GLfloat u12[2], u23[2], u32[2];
GLint i;

if (depth == maxdepth || (curv(u1) < cutoff &&
curv(u2) < cutoff && curv(u3) < cutoff)) {
surf(u1, v1, n1); surf(u2, v2, n2); surf(u3, v3, n3);
glNormal3fv(n1); glVertex3fv(v1);
glNormal3fv(n2); glVertex3fv(v2);
glNormal3fv(n3); glVertex3fv(v3);
for (i = 0; i < 2; i++) {
u12[i] = (u1[i] + u2[i])/2.0;
u23[i] = (u2[i] + u3[i])/2.0;
u31[i] = (u3[i] + u1[i])/2.0;
subdivide(u1, u12, u31, cutoff, depth+1);
subdivide(u2, u23, u12, cutoff, depth+1);
subdivide(u3, u31, u23, cutoff, depth+1);
subdivide(u12, u23, u31, cutoff, depth+1);

return 0;

05-04-2015, 06:46 AM
What do you expect this code to do?
surf() is undefined, subdivide() is never called, moreover it`s defined inside main() while C / C++ explicitly prohibit nested functions.
OpenGL is left uninitialized, no window is created… this code is just utterly incapable of working.

05-04-2015, 08:45 AM
Okay, please feel free to remove the main and return nest, and make it draw what it is supposed to draw, sudivide faces, in a window.