Search code examples
openglglu

the nurbs surface does not show up in openGL


GLUnurbsObj *theNurb;

theNurb = gluNewNurbsRenderer();
gluNurbsProperty(theNurb, GLU_SAMPLING_TOLERANCE, 5.0);
gluNurbsProperty(theNurb, GLU_DISPLAY_MODE, GLU_FILL);

//ctrPoint[] is an array containing the coordinate x,y,z of a grid size of 15*15. 
// therefore, the # of control points is 15*15=225. The degree is 3 and
// the order is 4.The size of knot vector is 4+225 = 229.   

void drawNurbs(){
    float knots[229];
    for (int i=0;i<114;i++)
    {
        knots[i] = 0;
    }
    for (int i=114;i<229;i++)
    {
        knots[i] = 1;
    }

    gluBeginSurface(theNurb);
    gluNurbsSurface(theNurb, 229, knots, 229, knots, 15*3 , 3, &ctrPoint[0], 
        4, 4, GL_MAP2_VERTEX_3);
    gluEndSurface(theNurb);

}

void display(){
    drawNurbs();
}

The above code does not work. There is something wrong in the drawNurbs() function. But I do not know where I am wrong. Size of ctrPoint[] is 225*3.


Solution

  • I found the problems.

    (1) the first 4 knot element are 0 !

    (2) the number of knots should be 15+4 =19 instead of 229!!

    GLfloat ctrlpoints[s_count][t_count][type]; //ctrlPoints[15][15][3]
    GLfloat sknot[sknot_count];                 
    GLfloat tknot[tknot_count];
    

    Then

    sknot_count = s_count + sorder; // 19 = 15+4
    tknot_count = t_count + torder; // 19=15+4