Mouse Event Question.

Second Newbie Question of the Day.

So I’m working with processMouseActiveMotion & processMouse.
I’m using a Method that is alike a Spray tool on any regular ‘paint’. Paints Random Pixels around an Area.

The Problem is, I’m using ActiveMotion to activate such method, and when I Stop moving the mouse, the tool stops painting, even if the button is still pressed.

I’ve Tried several things, to no avail.

Am I missing something? What could I do here?

I’m guessing that you’re using GLUT and processMouseActiveMotion is the name of your callback.

If that’s the case, tell me which glut function is it a callback of. Is it glutMotionFunc or glutMouseFunc?

Oh, yes, sorry. I forgot bout’ that.

Here it is:
glutMouseFunc( processMouse );
glutMotionFunc( processMouseActiveMotion );

Now, On processMouse I got this:

if(b==GLUT_LEFT_BUTTON && s==GLUT_DOWN)
{
i=0;
im=0;
press=1;
y=winHeight-y;
xoo[i]=x;
yoo[i]=y;
}

And in processMouseActiveMotion I got this:

i++;
glDrawPixels(winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, colores);
xoo[i] = x;
yoo[i] = winHeight-y;
if(i==(im+10)){
pint(xoo,yoo,i,im);
im=i;
glFlush();
glReadPixels(0, 0,winWidth, winHeight, GL_RGB, GL_UNSIGNED_BYTE, colores);
}

xoo & yoo are arrays that follow the Starting Point and then the Mouse Movements.

pint is a Bresenham Algorithm that in place, calls one called spray That actually paints.

Now, I Imagine that I have to put such method in the processMouse, But When I do, nothing happens.
=/

Thanks in Advance.

glutPassiveMotionFunc ?

No. PassiveMotion is for when you move the mouse and no buttons are pressed right? I need the Opposite. The Mouse is Static yet the Button is pressed.

Now, I can tell it’s going to be:

processMouse from glutMouseFunc( processMouse );

But How Do I Implement it?

glutMouseFunc then ?

Do you want to do an action when the button of the mouse is pressed even if you don’t move the mouse ? If so, this is the solution.

http://www.opengl.org/documentation/specs/glut/spec3/node50.html#SECTION00085000000000000000

Usually is logically wrong draw object outside the draw function. I will do something like that.


onMouseButtonPressed(){
  iHaveToDrawSomething = button1 is pressed;
}

onMouseMove(){
  storeMouseTraiectory(newMousePos);
}

drawFunction(){
  if(iHaveToDrawSomething)
    drawMouseTraiectory();
}

I was using MouseFunc. And I thought it wasn’t working.
It is… it’s just working REALLY slow. =/

I have it like this on MouseFunc

[b]if(boton==GLUT_LEFT_BUTTON && estado==GLUT_DOWN)
{
spray(x,y);

    }[/b]

and on spray

void spray(int x, int y)
{
int temp;
glColor3f(0.0, 0.0, 10.0);
glBegin(GL_POINTS);
glPointSize(10.0f); // determina el tamano del pixel
for(temp=0;temp<3;temp++){
sy = (rand() % 25);
sx = (rand() % 25);
glVertex2i(x-sx,sy+y);
}
glEnd();
}

It does paint, it just does it REALLY slow. Anyone knows why would that be?

Ah in fact you need a “no event” event :slight_smile:
Try this : glutIdleFunc