到目前为止,这是我的代码:
#include <iostream>
#include <cstdlib>
#include <GL/glut.h>
#include <cmath>
void keyboard(unsigned char key, int x, int y);
void display(void);
void timer(int);
static float x=0.0f,y=0.0f;
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitWindowPosition(200,200);
glutInitWindowSize(640,480);
glutCreateWindow("draw a line");
glutKeyboardFunc(&keyboard);
glutDisplayFunc(&display);
glutTimerFunc(10,timer,0);
glutMainLoop();
return EXIT_SUCCESS;
}
void keyboard(unsigned char key, int x, int y)
{
switch (key)
{
case '\x1B':
exit(EXIT_SUCCESS);
break;
}
}
void timer(int value){
x+=0.001;
y+=0.0005;
glutPostRedisplay();
glutTimerFunc(10,timer,0);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity ();
glColor3f(0.0f, 1.0f, 0.0f);
glBegin(GL_POINTS);
glVertex2f(x,y);
glEnd();
glFlush();
}
这样做是它从点 (0,0) 到 (1,0.5) 每 10 毫秒点亮一个像素。我想要的是当一个像素点亮时它保持在那个状态,所以最终你会看到一条线。我怎样才能做到这一点?