PDA

View Full Version : draw line between two existing points using left mouse click



Shashank
04-22-2016, 09:52 PM
Hi, i'm new to OpenGL programming, so i'm finding it difficult to figure this out. I have a printed a few points on the window and i want to draw a line between two existing points using left mouse click.
code:
#include<GL/glut.h>
int x,y;
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
glBegin(GL_POINTS);
for(x=150;x<=400;x+=30)
for(y=150;y<=400;y+=30)
glVertex2f(x,y);
glEnd();
glFlush();
}
void myinit()
{
glClearColor(1.0,1.0,1.0,1.0);
glColor3f(1.0,0.0,0.0);
glPointSize(5.0);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0,500.0,0.0,500.0);
glutPostRedisplay();

}

void main(int argc,char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
glutInitWindowSize(500,500);
glutInitWindowPosition(0,0);
glutCreateWindow("points");
glutDisplayFunc(display);
myinit();
glutMainLoop();
}


please help!!