nurbs表面不会出现在openGL中

时间:2011-11-10 23:49:27

标签: opengl glu

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();
}

上述代码不起作用。 drawNurbs()函数有问题。但我不知道我错在哪里。 ctrPoint[]的大小为225 * 3.

1 个答案:

答案 0 :(得分:0)

我发现了问题。

(1)第一个4结元素为0!

(2)结的数量应为15 + 4 = 19而不是229 !!

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

然后

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