Thread: Mouse Trail in OpenGL

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    68

    Mouse Trail in OpenGL

    Hi,

    I am trying to bind an object to the PassiveMouseFunc

    now I can get it to draw the shape. however when i move the mouse it creates a trail, I don't want a trail.

    I am already using double buffering, is there a way to get rid of the trail?

    This is what i am talking about

    Thx
    -Ti22-

  2. #2
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    The first thing to do in your drawing function is this:
    Code:
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    // Do al the drawing and stuff

  3. #3
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    OK I did it, I put the thing in my passiveMotion callback but when i do this everything else (the flowers i draw appear for a sec and disappears.
    Last edited by Ti22; 11-07-2004 at 01:23 PM.
    -Ti22-

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    You need to call your drawing function every frame you want it to be drawn. If your doing that I dont know why it dissappears, then I need to see code.

  5. #5
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    Code:
    void mouseMotion (GLint x, GLint y)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	waterThingy(x-400, (-y)+250, 0.0, 1.0, 1.0, 1.0);
    	glutSwapBuffers();
    }
    
    void mainDisplay (GLvoid)
    {
    	glMatrixMode(GL_MODELVIEW);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	
    	glLoadIdentity();
    	world();
    	glLoadIdentity();
    	flower(500.0, 500.0, 0.0, 0.2, 0.2, 0.2);
    	glLoadIdentity();
    	flower(1000.0, 500.0, 0.0, 0.2, 0.2, 0.2);
    	glLoadIdentity();
    	drawBucket(1500.0, 500.0, 0.0, 0.2, 0.2, 0.2);
    	glLoadIdentity();
    	flower(100.0, 0.0, 0.0, 1.0, 1.0, 1.0);
    	glLoadIdentity();
    	drawBucket(-300, 0.0, 0.0, 1.0, 1.0, 1.0);
    	glLoadIdentity();
    	flower(300.0, 0.0, 0.0, 1.0, 1.0, 1.0);
    	
    	glutSwapBuffers();
    			
    }
    
    void main(int argc, char **argv)
    {
    	glutInit(&argc, argv);
    	
    	glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB);
    	glutInitWindowSize(800, 600);
    	glutCreateWindow("Flower and Pot");
    	InitGL();
    	glutReshapeFunc(resize);
    	glutDisplayFunc(mainDisplay);
    	glutKeyboardFunc(keyBoard);
    	glutPassiveMotionFunc(mouseMotion);
    	
    	glutMainLoop();
    }
    I am using the line u gave me in the passivemotionfunc callback.
    -Ti22-

  6. #6
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Code:
    void mouseMotion (GLint x, GLint y)
    {
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Get rid of this here
    	waterThingy(x-400, (-y)+250, 0.0, 1.0, 1.0, 1.0);
    	glutSwapBuffers(); // Get rid of this too
    }
    You should only clear the buffer once every frame, and only swap it once every frame. Also check out the FAQ or search the board why void main is bad.
    Last edited by Shakti; 11-07-2004 at 01:40 PM.

  7. #7
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    if i get rid of those lines it the object i bind to the mouse won't show up. and I changed it to int main.

    btw shakti(means power in hindi rite?), i really appreciate this. ur replying so fast.
    Last edited by Ti22; 11-07-2004 at 01:47 PM.
    -Ti22-

  8. #8
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    Ok do this instead, have two global variables that should be the place where you want to draw the waterthingy, then in your mainDisplay you draw that with those coordinates instead, something like
    Code:
    GLint waterX = 0;
    GLint waterY = 0;
    void mouseMotion (GLint x, GLint y)
    {
            waterX = x-400;
            waterY = (-y)+250;
    }
    
    void mainDisplay (GLvoid)
    {
    	glMatrixMode(GL_MODELVIEW);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    	
    	glLoadIdentity();
    	world();
    	glLoadIdentity();
    	flower(500.0, 500.0, 0.0, 0.2, 0.2, 0.2);
    	glLoadIdentity();
    	flower(1000.0, 500.0, 0.0, 0.2, 0.2, 0.2);
    	glLoadIdentity();
    	drawBucket(1500.0, 500.0, 0.0, 0.2, 0.2, 0.2);
    	glLoadIdentity();
    	flower(100.0, 0.0, 0.0, 1.0, 1.0, 1.0);
    	glLoadIdentity();
    	drawBucket(-300, 0.0, 0.0, 1.0, 1.0, 1.0);
    	glLoadIdentity();
    	flower(300.0, 0.0, 0.0, 1.0, 1.0, 1.0);
    
    	waterThingy(waterX,waterY, 0.0, 1.0, 1.0, 1.0);
    	
    	glutSwapBuffers();
    			
    }
    Try something along those lines. if waterThingy actaully draws something (as I suspect it does) you really really want it to be in the drawing function.

  9. #9
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    ok i did that but now the Watering Can gets fixed it one position it doesn't move with the mouse.

    Don't I have to return waterX and waterY to Global Variable ?
    Last edited by Ti22; 11-07-2004 at 01:59 PM.
    -Ti22-

  10. #10
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Code:
    void mouseMotion (GLint x, GLint y)
    {
            waterX = x-400;
            waterY = (-y)+250;
            glutPostRedisplay();
    }

  11. #11
    Registered User
    Join Date
    Jan 2004
    Posts
    68
    WOW its Works !!! thx alot guys, really appreciate this.

    Hugs and Kisses
    Last edited by Ti22; 11-07-2004 at 02:02 PM.
    -Ti22-

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. OpenGL Window
    By Morgul in forum Game Programming
    Replies: 1
    Last Post: 05-15-2005, 12:34 PM
  2. Mouse Train in OpenGL
    By Ti22 in forum C Programming
    Replies: 2
    Last Post: 11-07-2004, 12:58 PM
  3. opengl question. mouse location vs gluperspective
    By revelation437 in forum Game Programming
    Replies: 1
    Last Post: 10-19-2004, 07:18 PM
  4. Mouse 'control' prob in OpenGL
    By gazsux in forum Game Programming
    Replies: 5
    Last Post: 04-17-2003, 10:00 AM
  5. Mouse in OpenGL?
    By TheGr8one in forum Game Programming
    Replies: 0
    Last Post: 11-01-2001, 07:19 PM