how to drawing continues line just like in paint [on hold]

Posted by hussain shah on Game Development See other posts from Game Development or by hussain shah
Published on 2014-06-03T20:24:49Z Indexed on 2014/06/03 21:41 UTC
Read the original article Hit count: 467

Filed under:

hi sir i want to draw a points.the following code is work good but the problem is than when i drag the mouse button, if i move slow working good but if i move the curser fast they cannot made continues line.please what is the solution...?

#include <iostream>
#include <GL/glut.h>
#include <GL/glu.h>
#include <stdlib.h>

void first()
{
    glPushMatrix();
    glTranslatef(1,01,01);
    glScalef(1, 1, 1);
glColor3f(0, 1, 0);
glBegin(GL_QUADS);
glVertex2f(0.8, 0.6);
glVertex2f(0.6, 0.6);
glVertex2f(0.6, 0.8);
glVertex2f(0.8, 0.8);
glEnd();
glPopMatrix();

glFlush();
}

void display (void)
{
glClear(GL_COLOR_BUFFER_BIT); //store color of each pixels of a frame
glClearColor(0, 0, 0, 0);// screen color
//glFlush();
}
void drag (int x, int y)
{
{
    y=500-y;
    //x=500-x;

    glPointSize(5);
    glColor3f(1.0,1.0,1.0);

 glBegin(GL_POINTS);
 glVertex2f(x,y+2);
 glEnd();
 glutSwapBuffers();
glFlush();
}
}
void reshape (int w, int h){}

void init (void)
{
    glClear(GL_COLOR_BUFFER_BIT); //store color of each pixels of a frame
glClearColor(0, 0, 0, 0);
glViewport(0,0,500,500);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, 500.0, 0.0, 500.0, 1.0, -1.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
}
void mouse_button (int button, int state, int x, int y)
{

if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN)
{
     drag(x,y);
    first();
}
//else if (button == GLUT_MIDDLE_BUTTON && state == GLUT_DOWN)
//{
//
//}
else if (button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN)
{
    exit(0);

}
}

int main (int argc, char**argv)
{

glutInit (&argc, argv); //initialize the program.
glutInitDisplayMode (GLUT_SINGLE); //set up a basic display buffer (only singular for now)
glutInitWindowSize (500,500); //set whe width and height of the window
glutInitWindowPosition (100, 100); //set the position of the window
glutCreateWindow ("A basic OpenGL Window"); //set the caption for the window
glutMotionFunc(drag);
//glutMouseFunc(mouse_button);
init();
glutDisplayFunc (display);//call the display function to draw our world
glutMainLoop(); //initialize the OpenGL loop cycle
return 0;
}

© Game Development or respective owner

Related posts about opengl