Hi I tried to run this code but it doesn’t interact with my drawing immeditly … so can u tell me what is wrong or can i find better programs like it?
thanx
/* A simple curve drawing program, 1/31/01 by Mark Harris
Illustrates mouse, mouse motion callback functions
*/
#include <GL/glut.h>
int squarecolor=1;
int anchorx,anchory;
int WindowWidth=500;
int WindowHeight=500;
void myinit(void)
{
/* attributes */
glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */
/* set up viewing */
/* 500 x 500 window with origin lower left */
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0.0, 500.0, 0.0, 500.0);
glMatrixMode(GL_MODELVIEW);
}
void display( void )
{
glClear(GL_COLOR_BUFFER_BIT); /*clear the window /
glFlush(); / clear buffers */
}
void mouse(int button,int state,int x,int y)
{
y=500-y; // convert system orientation
anchorx=x;
anchory=y;
return;
}
void motion(int x, int y)
{
y=500-y; // convert system orientation
glColor3f(1,0,0); /* draw in red */
glBegin(GL_LINES);
glVertex2f(anchorx,anchory);
glVertex2f(x,y);
glEnd();
anchorx=x; // update anchor point
anchory=y;
}
void main(int argc, char** argv)
{
glutInit(&argc,argv);
glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); /* default, not needed */
glutInitWindowSize(WindowWidth,WindowHeight);
glutInitWindowPosition(0,0); /* place window top left on display */
glutCreateWindow("Draw"); /* window title */
glutDisplayFunc(display); /* display callback invoked when window opened */
glutMouseFunc(mouse);
glutMotionFunc(motion);
myinit(); /* set attributes */
glutMainLoop(); /* enter event loop */
}