Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Running Ubuntu 11.04, SDL 1.2 trying to pickup mouse wheel up/down movement with this (stripped down) code:

int main( int argc, char **argv )
{
    SDL_MouseButtonEvent *mousebutton = NULL;

    while ( !done )
    {
        if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_LEFT)
            yrot += 0.75f;
        else if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_RIGHT)
            yrot -= 0.75f;
        else if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_WHEELUP){
            xrot += 0.75f;
        }else if(mousebutton != NULL && mousebutton->button == SDL_BUTTON_WHEELDOWN){
            xrot -= 0.75f;
        }

        while ( SDL_PollEvent( &event ) )
        {
            switch( event.type )
            {
                case SDL_MOUSEBUTTONDOWN:
                    mousebutton = &event.button; 
                    break;
                case SDL_MOUSEBUTTONUP:
                    mousebutton = NULL;
                    break;
                default:
                    break;
             }
        }
    }
    return 0;
}

strange thing is, scrolling with the mouse button does nothing, but if I hold down a mouse button or two and then move the mouse it hits the SDL_BUTTON_WHEEL code occasionally. This honestly reeks of a pointer issue, which would make sense since I've been spoiled with C# for the past couple years, but I am just not seeing it.

How do i correctly find mouse scroll events in SDL?

share|improve this question
add comment

1 Answer

up vote 3 down vote accepted

I'd recommend going through these two tutorials:

If you still have problems after going through these tutorials, let me know - I'd be glad to help you out :)

share|improve this answer
    
Assassin: This code was hacked together from a NeHe tutorial, those LazyFoo tutorials, and some API documentation. I will definitely go through those two tutorials again and see if it sheds some light, after work. –  Chris Mar 30 '12 at 12:44
    
Aha! that was an insidious bug. For [mouse wheels] (www.libsdl.org/cgi/docwiki.cgi/SDL_MouseButtonEvent) it places two events into the event queue. SDL_PollEvent reads until the queue is empty, so my code was hitting the inner loop twice, setting wheel button to null before i hit the yrot code. –  Chris Mar 30 '12 at 23:55
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.