user3351750
user3351750

Reputation: 927

glutMouseWheelFunc doesnt trigger callback

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.

Upvotes: 0

Views: 2875

Answers (1)

ahmed taiko
ahmed taiko

Reputation: 31

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 .

Upvotes: 1

Related Questions