绘制一条简单的Bezier曲线
畿米阳光 2011-11-02 07:59:30
#include <Windows.h>
#include<GL/glut.h>
GLfloat ctrlpoints[4][3] = {(-4.0, -4.0, 0.0), (-2.0, 4.0, 0.0),
(2.0, -4.0, 0.0), (4.0, 4.0, 0.0)};
void init(void)
{
glClearColor(0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 2, 4, &ctrlpoints[0][0]);
glEnable(GL_MAP1_VERTEX_3);
}
void display(void)
{ int i;
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_LINE_STRIP);
for(i=0; i<=30; i++)
glEvalCoord1f( (GLfloat)i/30.0 );
glEnd();
glPointSize(5.0);
glColor3f(1.0, 1.0, 0.0);
glBegin(GL_POINTS);
for(i=0; i<4; i++)
glVertex3fv(&ctrlpoints[i][0]);
glEnd();
glFlush();
}
void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if(w <= h)
glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w,
5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
else
glOrtho(-5.0*(GLfloat)w/(GLfloat)h,
5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
int main(int argc,char *argv[])
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowSize(450,450);
glutInitWindowPosition(100,100);
glutCreateWindow("Bezier Curves");
init();
glutDisplayFunc(display);
glutReshapeFunc(reshape);
glutMainLoop();
return 0;
}
///////////////////////////////////////////////////////////////////////////////////
这个程序是绘制一条简单的Bezier曲线。但是运行之后,只有一个点。找了半天了
也没找到原因。有哪位大侠知道哪出错了,告诉小弟一声。谢谢了!