/* NURB curve (1-dimension) Testing whether we really get a quarter circle with the NURBS given in Rogers and also in Hill, and whether the curve goes outside the convex hull. Written by Caroline Geiersbach and Scott D. Anderson scott.anderson@acm.org Summer 2003 */ #include #include #include #include const int order=3; const int numPoints = 3; GLfloat W = sqrt(2)/2; GLfloat knots[6] = {0,0,0,1,1,1}; GLfloat points[numPoints][4] = { {1,0,0,1}, {W,W,0,W}, {0,1,0,1}}; GLfloat pointsWeights[numPoints][4] = { {1,0,0,1}, {1,1,0,W}, {0,1,0,1} }; void twErrorCheck(char* context) { glutReportErrors(); /* do { int glError = glGetError(); if(glError == GL_NO_ERROR) return; printf("GL Error: %d (%s)\n",glError,context); } while (true); */ } void curve1() { GLUnurbs* NURBS1=gluNewNurbsRenderer(); if(NURBS1==0) printf("no memory for NURBS"); gluNurbsProperty(NURBS1,GLU_DISPLAY_MODE,GLU_FILL); glColor3f(1,0.5,0); // orange gluBeginCurve(NURBS1); // this definitely works. gluNurbsCurve(NURBS1,numPoints+order,knots,4,&points[0][0],order, GL_MAP1_VERTEX_4); gluEndCurve(NURBS1); gluDeleteNurbsRenderer(NURBS1); } void curve2() { twErrorCheck("starting curve2"); GLUnurbs* NURBS2=gluNewNurbsRenderer(); if(NURBS2==0) printf("no memory for NURBS"); twErrorCheck("after getting renderer"); gluNurbsProperty(NURBS2,GLU_DISPLAY_MODE,GLU_FILL); twErrorCheck("after setting display mode"); twErrorCheck("after enabling map1 vertex4"); glColor3f(1,0,0); // red gluBeginCurve(NURBS2); twErrorCheck("after beginning curve"); // this definitely works. gluNurbsCurve(NURBS2,numPoints+order,knots,4,&pointsWeights[0][0],order, GL_MAP1_VERTEX_3); twErrorCheck("after drawing curve"); gluEndCurve(NURBS2); twErrorCheck("after ending curve"); gluDeleteNurbsRenderer(NURBS2); twErrorCheck("after deleting renderer"); } int whatToDisplay = 0; void display(void) { glClearColor(0.7,0.7,0.7,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // since the figure is in the unit square, this should work. float margin = 0.2; glOrtho(0-margin,1+margin, 0-margin,1+margin, 0,1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); pointsWeights[1][3] = W; points[1][0] = points[1][1] = points[1][3] = W; glLineWidth(3); glColor3f(0,0,1); glBegin(GL_LINE_STRIP); for(int i=0; i= '0' && k <= '9') tmp = tmp*10 + k-'0'; if(k == '\r') { whatToDisplay=tmp; tmp=0; printf("what to display = %d\n",whatToDisplay); glutPostRedisplay(); } } int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(650, 650); glutCreateWindow("NURBS!"); glutDisplayFunc(display); glutKeyboardFunc(keys); //glEnable(GL_MAP1_VERTEX_4); glutMainLoop(); return 0; }