0

I am trying to implement zoom in or zoom out operations using mouse scroll button by glutMouseWheelFunc in opengl . I have implemted the code as below :

#include<GL/freeglut.h>

void mouseWheel(int button, int dir, int x, int y)
{

    printf("in mouse wheel \n");

    if (dir > 0)
    {
        // Zoom in
        ztrans = ztrans - 1.0;
        printf("scroll in = %0.3f\n ",ztrans);
    }
    else
    {
        // Zoom out
        ztrans = ztrans + 1.0;
        printf("scroll out = %0.3f\n ",ztrans);
    }

        glutPostRedisplay();

}

    int main(int argc, char **argv)
    {
      // general initializations
      glutInit(&argc, argv);
      glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
      glutInitWindowPosition(100, 100);
      glutInitWindowSize(800, 400);
      glutCreateWindow("Rotation");

      // register callbacks
      glutReshapeFunc(changeSize); 
      glutDisplayFunc(renderScene);
      glutIdleFunc(renderScene);
      glutIgnoreKeyRepeat(1);
      glutMouseFunc(mouseButton); 
      glutMotionFunc(mouseMove); 
      glutMouseWheelFunc(mouseWheel); // Register mouse wheel function

      glEnable(GL_DEPTH_TEST);

      glutMainLoop();
      return 0;

}

On executing, it is not calling the registered callback function(mouseWheel) . My system has freeglut3 installed.

user3351750
  • 927
  • 13
  • 24
  • What operating system are you developing on? I just tried this on my Ubuntu 12.04 with freeglut and it worked fine. Do the other mouse callbacks work? – Hugh Fisher Apr 10 '14 at 02:18
  • I tried it in Ubuntu 13.04 . Yes other mouse callbacks are working fine. – user3351750 Apr 10 '14 at 08:10
  • There may be window manager settings in Ubuntu 13 which reserve the mouse wheel for scrolling virtual desktops or something. Check your preferences. If that isn't it, I'm out of ideas – Hugh Fisher Apr 11 '14 at 00:50
  • See this answer [http://stackoverflow.com/questions/14378/using-the-mouse-scrollwheel-in-glut][1] [1]: http://stackoverflow.com/questions/14378/using-the-mouse-scrollwheel-in-glut – ferry Jul 29 '14 at 11:58

1 Answers1

1

try using a static int inside void mouseWheelmethod, and then use it in renderScene like this

static int k;
static int ztrans
void mouseWheel(int button, int dir, int x, int y)
{

   k = dir; // int dir is +1 of -1 based on the direction of the wheel motion

   ztrans = ztrans + k;

}

This worked for me, Try this and feedback, GoodLuck .