Hi I am changing all my examples from the book programming linux games from sdl1 to sdl2
some of the programs work fine when the functions are updated but this one compiles fine but does nothing, can anyone help me get it running? thanks.
compiled on gcc with -lSDL2
#include<SDL2/SDL.h>
#include<stdio.h>
#include<stdlib.h>
int main(int argn, char **argv)
{
SDL_Event event;
/*Initialize SDL's video system and check for errors. */
if (SDL_Init(SDL_INIT_VIDEO) !=0) {
printf("Unable to initialize SDL: %s\n", SDL_GetError());
return 1;
}
/*Make sure SDL_Quit gets called when the program exits" */
atexit(SDL_Quit);
/* Attempt to set a 256x256 hicolour (16-bit) video mode */
SDL_Window * window = SDL_CreateWindow("MouseMonitoring",0,0,256,256,SDL_WINDOW_RESIZABLE);
if (window == NULL){printf("Could not create Window! %s\n", SDL_GetError());
/* Start the event loop. Keep reading events untill there
is an error, or the user presses a mouse button. */
while(SDL_WaitEvent(&event) !=0)
{
/* SDL_WaitEvent has filled in our event structure
with the next event. We check its type field to
find out what happened. */
switch(event.type)
{
/* The next two event types deal
with mouse activity. */
case SDL_MOUSEMOTION:
printf("Mouse motion. ");
/* SDL provides the current position. */
printf("New position is (%i,%i). ",
event.motion.x, event.motion.y);
/*We can also get relative motion */
printf("That is a (%i,%i) change.\n",
event.motion.xrel, event.motion.yrel);
break;
case SDL_MOUSEBUTTONDOWN:
printf("Mouse button pressed. ");
printf("Button %i at (%i,%i)\n",
event.button.button,
event.button.x, event.button.y);
break;
/* The SDL_Quit event indicates that
the window "Close" button has been
pressed. We can ignore this if we
need to, but that tends to make
users rather impatient, */
case SDL_QUIT:
printf("Quit event. Bye,\n");
exit(0);
}
}
return 0;
}
}