Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Mouse Interaction

  1. #1
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    3

    Mouse Interaction

    I am trying to draw a moving rectangle such that it moves one step, waits for the mouse key and then moves again.
    here is my code:

    void mymouse(int button, int state, int x, int y)
    {
    if(state== GLUT_DOWN && button == GLUT_LEFT_BUTTON) exit(0);
    }


    and i call mymouse function using glutMouseFunc(mymouse).

    the problem is that im trying to change the exit(0) to a return, but its not wokring. any suggestions?

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Jun 2000
    Location
    Gastonia, NC, USA
    Posts
    2,070

    Re: Mouse Interaction

    You know that glutMouseFunc works when the mouse is click inside the window, should be called before glutMainFunc.

    example of what you need to do:


    void mymouse(int button, int state, int x, int y)
    {
    if(state== GLUT_DOWN && button == GLUT_LEFT_BUTTON)
    {
    // When left button down pass current x/y mouse values to rectangle
    rectangle_x = x;
    rectangle_y = y;
    }

    }


    my_display()
    {

    draw_rectangle(rectangle_x, rectangle_y);

    }

    Originally posted by melmiligui:
    I am trying to draw a moving rectangle such that it moves one step, waits for the mouse key and then moves again.
    here is my code:

    void mymouse(int button, int state, int x, int y)
    {
    if(state== GLUT_DOWN && button == GLUT_LEFT_BUTTON) exit(0);
    }


    and i call mymouse function using glutMouseFunc(mymouse).

    the problem is that im trying to change the exit(0) to a return, but its not wokring. any suggestions?

  3. #3
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    3

    Re: Mouse Interaction

    actually I'm reading in the coordinates from a file and I just need it to stop after each coordinate reading, until I click the mouse and then it reads the next coordinates again and moves and on and on. You're help is greatly appreciated. Thanks. melmiligui

  4. #4
    Junior Member Newbie
    Join Date
    Nov 2002
    Posts
    3

    Re: Mouse Interaction

    All im trying to do is draw a rectangle and then wait for a mouse key and draw another rectangle someplace else.
    I did this by makig a for loop in the display function to draw the first rectangle then wait for the mouse then draw the second rectangle and so on...
    the problem is that mymouse function doesnt work except when i use the exit(0) function and that too only works when the for loop has gone through all its iterations...

    ANY HELP PLEASE??????

  5. #5
    Intern Contributor
    Join Date
    Oct 2002
    Location
    bangalore
    Posts
    56

    Re: Mouse Interaction

    Hi,
    i agree with the nexus . this is the way ur main should be.


    int main(int argc, char **argv)
    {
    glutInit(&argc,argv);
    glutInitWindowSize(1200,900);
    glutInitWindowPosition(0,0);
    pw=glutCreateWindow(" opening first ");
    glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGB );
    init();
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutReshapeFunc(reshape);
    glutMouseFunc(mouse);
    glutMainLoop();
    return 0;
    }

    that means , mouse function should be before glutMainLoop.

    and ur mouse functin can be,

    void mouse(int button,int state, int x,int y)
    {
    if(state== GLUT_DOWN && button ==GLUT_LEFT_BUTTON)
    {
    for(;
    {
    // read the coordinates
    Rectangle(); // draw rectangle
    }
    }


    hope this helps.
    thanks & regards
    Prashant G.P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •