0
\$\begingroup\$

According to the SDL2 wiki,

SDL_SetEventFilter : Use this function to set up a filter to process all events before they change internal state and are posted to the internal event queue.

void SDL_SetEventFilter(SDL_EventFilter filter, void* userdata)

The function prototype for filter is: int YourEventFilter(void* userdata, SDL_Event* event)

And so, my code as follows is:

`

#include <SDL.h>
#include <stdio.h>
#include <memory>

//Screen dimension constants
const int SCREEN_WIDTH = 640;
const int SCREEN_HEIGHT = 480;


int isMouseEvent(SDL_Event* ev);



int main(int argc, char* args[])
{


    SDL_Event ev;

    //The window we'll be rendering to
    SDL_Window* window = NULL;

    //The surface contained by the window
    SDL_Surface* screenSurface = NULL;

    //Initialize SDL
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
    }
    else
    {

        //Create window
        window = SDL_CreateWindow("SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
        if (window == NULL)
        {
            printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
        }
        else
        {

            bool black = false;

            //Get window surface
            screenSurface = SDL_GetWindowSurface(window);
            SDL_SetEventFilter(isMouseEvent);
            bool isOn = true;
            while (isOn)
            {
                //Pump events
                SDL_PumpEvents();

                SDL_FillRect(screenSurface, NULL, SDL_MapRGB(screenSurface->format, 0xFF, 0xFF, 0xFF));

                //Update the surface
                SDL_UpdateWindowSurface(window);
            }
        }
    }
    //Destroy window
    SDL_DestroyWindow(window);

    //Quit SDL subsystems
    SDL_Quit();

    return 0;
}

int isMouseEvent(SDL_Event* ev)
{
    if(ev!=NULL) {
        if (ev->type == SDL_MOUSEMOTION)
            return 0;
    }
    return 1;
}

However, when the code is ran no events are filtered, every event passed to isMouseEvent() is null. The SDL2 Wiki is very bare, and the examples on using SDL_SetEventFilter are very basic and do not work properly. Any ideas as to where I should go from here, seeing as the events are constantly null when checked from the isMouseEvent() function?

\$\endgroup\$
4
  • \$\begingroup\$ void pointer is a pointer that can point at any data type. You are mixing it with default arguments that's what can be omitted. \$\endgroup\$
    – concept3d
    Feb 13, 2014 at 2:14
  • \$\begingroup\$ Yep, that's where I was mistaken at. I'm going to edit my question, now that this is compiling, the events are not being filtered. \$\endgroup\$ Feb 13, 2014 at 3:09
  • \$\begingroup\$ Nevermind, I'm an idiot. Got it fixed now! Reading is power. \$\endgroup\$ Feb 13, 2014 at 3:23
  • \$\begingroup\$ How did you fixed ? \$\endgroup\$
    – eri0o
    May 17, 2018 at 2:21

1 Answer 1

1
\$\begingroup\$

void pointers cannot simply be omitted. Feel free to pass NULL, though.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .