Ask Your Question

Revision history [back]

setMouseCallback and OpenGL

Hi,

I want to use a callback function for mouse inside an openGL windows. My program looks like :

static void onMouse(int event, int x, int y, int, void*)
{
    if (event==EVENT_LBUTTONDOWN)
    {
        prevX=x;
        prevY=y;
    }
    if (event == EVENT_LBUTTONUP)
    {    
        prevX=-1;
        prevY=-1;
    }
    if (prevX!=-1)
    {
        obsX += x - prevX;
        obsY += y - prevY;
    }
    cout << event << "\t" << x << "\t" << y << "\t" << prevX << "\t" << prevY << "\n";


}

void DrawOpenGLMSER(Mat img, Mat result)
{
    Mat imgGray;
    if (img.type() != CV_8UC1)
        cvtColor(img, imgGray, COLOR_BGR2GRAY);
    else
        imgGray = img;
    namedWindow("OpenGL", WINDOW_OPENGL);
    //resizeWindow("OpenGL", win_width, win_height);
    setMouseCallback("OpenGL", onMouse, NULL);.......

About Opengl everything works fine but mouse inside OpenGL windows does not work. I can see event but mouse position is always 0,0. (when I run opencv/samples/cpp/ffilldemo.cpp I can see mouse coordinates)

Help would be appreciate thanks.

setMouseCallback and OpenGL

Hi,

I want to use a callback function for mouse inside an openGL windows. My program looks like :

static void onMouse(int event, int x, int y, int, void*)
{
    if (event==EVENT_LBUTTONDOWN)
    {
        prevX=x;
        prevY=y;
    }
    if (event == EVENT_LBUTTONUP)
    {    
        prevX=-1;
        prevY=-1;
    }
    if (prevX!=-1)
    {
        obsX += x - prevX;
        obsY += y - prevY;
    }
    cout << event << "\t" << x << "\t" << y << "\t" << prevX << "\t" << prevY << "\n";


}

void DrawOpenGLMSER(Mat img, Mat result)
{
    Mat imgGray;
    if (img.type() != CV_8UC1)
        cvtColor(img, imgGray, COLOR_BGR2GRAY);
    else
        imgGray = img;
    namedWindow("OpenGL", WINDOW_OPENGL);
    //resizeWindow("OpenGL", win_width, win_height);
    setMouseCallback("OpenGL", onMouse, NULL);.......

About Opengl everything works fine but mouse inside OpenGL windows does not work. I can see event but mouse position is always 0,0. (when I run opencv/samples/cpp/ffilldemo.cpp I can see mouse coordinates)

Help would be appreciate thanks.

PS in file window_w32.cpp at line 1617

        window->on_mouse( event, pt.x*size.cx/MAX(rect.right - rect.left,1),
                                 pt.y*size.cy/MAX(rect.bottom - rect.top,1), flags,
                                 window->on_mouse_param );

Size is always 0,0