So far this is my code:
#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();
}
What this does is that it lights up a pixel every 10 msecs from the point (0,0) to (1,0.5). What I want is that when a pixel lights up it stays in that state, so eventually you will see a line. How can I achieve this?
I am not familiar with
glutbut I am guessingdisplayis the function that is called on each redraw. This function starts withglClear(GL_COLOR_BUFFER_BIT). This function clears your color buffer on each redraw.You might find that removing
glCleardoes not entirely fix your problem. This could well be because your graphics context may be double buffered and to make things more efficient, the front buffer is not copied to the back buffer on each animation run.You best bet to get the desired effect will probably be to draw a line that grows on each animation run.