GL_LINE_STRIPを使用してベジェ曲線アルゴリズムで2つの形状を描画しました。私の形は月が好きで、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();
}
何か案が?