const GLfloat factor = 0.1f;
void display()
{
GLfloat x;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_LINES);
glVertex2f(-1.0, 0.0);
glVertex2f(1.0, 0.0);
glVertex2f(0.0, -1.0);
glVertex2f(0.0, 1.0);
glEnd();
glBegin(GL_LINE_STRIP);
for (x = -1.0/factor; x < 1.0/factor; x+=0.01)
{
glVertex2f(x*factor, sin(x)*factor);
}
glEnd();
glFlush();
}
int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
glutInitWindowPosition(100, 100);
glutInitWindowSize(500, 200);
glutCreateWindow("opengl 3d view");
//init();
glutDisplayFunc(display);
glutMainLoop();
return 0;
}
一、当factor=0.1时
二、当factor=0.3时