So i just started learning SDL and came across "Event driven programming", just wanted to be sure if i understood the tutorial correcly. So lets say by adding:

SDL_Event event;

i add lets say a container that keeps track of every event i do? After that i start using:

while ( program == true )
{
	while(SDL_PollEvent(&event)
	{
		if ( event.type == SDL_QUIT )
		{
			program = false;
		}
	}
}

If i understand correcly, in the second loop we say that while theres some sort of event ( and we send a list of events ) do the loop and if it happens that one of those events type is SDL_QUIT then the program will terminate. I think i understand it good enough but would like to hear something about the event handling in the SDL that i dont know about or correct me if im wrong.

Correct enough. SDL maintains the queue of events for you, so all you're doing is checking whether there's an event on the queue and if so, retrieving it so you can decide what to do about it.

After line 7, consider adding a 'break;' statement so that you don't have to check whether the event-type is all of the other possible options before exiting the event-queue-polling loop (which you have to do at -some- point anyway, so that you can get back out to the while(program) loop).

Correct enough. SDL maintains the queue of events for you, so all you're doing is checking whether there's an event on the queue and if so, retrieving it so you can decide what to do about it.

After line 7, consider adding a 'break;' statement so that you don't have to check whether the event-type is all of the other possible options before exiting the event-queue-polling loop (which you have to do at -some- point anyway, so that you can get back out to the while(program) loop).

Thanks, all i wanted to know.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.