我使用 GL_LINE_STRIP 使用贝塞尔曲线算法绘制了 2 个形状。我的形状喜欢月亮,我想为两条曲线之间的空间着色。我使用了 GL_POLYGON 但它没有产生我想要的结果。
这是我的代码:
float Points[4][3] = {
{275,356,0},
{ 395,353,0 },
{ 435,325,0 },
{ 476,232,0 }
};
float SecendPoints[4][3] = {
{ 476,232,0},
{441,331,0},
{369,372,0},
{283,388,0}
};
void init()
{
glClearColor(0.0,0.0,0.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,640,0.0,480.0);
}
void Display(void)
{
int segment = 20;
// clear the screen & depth buffer
glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT);
glColor3f(1,1,1);
glColor3f(1,0,1);
// we will draw lots of little lines to make our curve
glBegin(GL_LINE_STRIP);
for(int i=0;i!=segment;++i) {
// use the parametric time value 0 to 1
float t = (float)i/(segment-1);
// nice to pre-calculate 1.0f-t because we will need it frequently
float it = 1.0f-t;
// calculate blending functions
float b0 = t*t*t;
float b1 = 3*t*t*it;
float b2 = 3*t*it*it;
float b3 = it*it*it;
// calculate the x,y and z of the curve point by summing
// the Control vertices weighted by their respective blending
// functions
//
float x = b0*Points[0][0] +
b1*Points[1][0] +
b2*Points[2][0] +
b3*Points[3][0] ;
float y = b0*Points[0][1] +
b1*Points[1][1] +
b2*Points[2][1] +
b3*Points[3][1] ;
float z = b0*Points[0][2] +
b1*Points[1][2] +
b2*Points[2][2] +
b3*Points[3][2] ;
// specify the point
glVertex3f( x,y,z );
}
for(int i=0;i!=segment;++i) {
// use the parametric time value 0 to 1
float t = (float)i/(segment-1);
// nice to pre-calculate 1.0f-t because we will need it frequently
float it = 1.0f-t;
// calculate blending functions
float b0 = t*t*t;
float b1 = 3*t*t*it;
float b2 = 3*t*it*it;
float b3 = it*it*it;
// calculate the x,y and z of the curve point by summing
// the Control vertices weighted by their respective blending
// functions
//
float x = b0*SecendPoints[0][0] +
b1*SecendPoints[1][0] +
b2*SecendPoints[2][0] +
b3*SecendPoints[3][0] ;
float y = b0*SecendPoints[0][1] +
b1*SecendPoints[1][1] +
b2*SecendPoints[2][1] +
b3*SecendPoints[3][1] ;
float z = b0*SecendPoints[0][2] +
b1*SecendPoints[1][2] +
b2*SecendPoints[2][2] +
b3*SecendPoints[3][2] ;
// specify the point
glVertex3f( x,y,z );
}
glVertex3f( 476,232,0 );
glEnd();
glFlush();
}
任何想法?