Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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; 
                case SDL_MOUSEBUTTONUP:
                    mousebutton = NULL;
    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
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] ( 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

Your Answer


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.