Frame Per Second Didn't Update


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <sstream>
#include <SDL.h>
#include <SDL_ttf.h>
#include "KD_Surface.h"
#include "KD_Message.h"
#include "KD_Sound.h"
#include "KD_Timer.h"

void event_handler();

int main(int argc,char *argv[])
{
	if( initialization() == false )
	{
		return 1;
	}

	//Frame Calculation
	int frame = 0;
	KD_TIMER fps;
	KD_TIMER update;

	//Start Update Timer
	update.start();
	//Start FPS Timer
	fps.start();

	//Background Of Game
	SDL_Surface *background = NULL;
	background = load_image("background.jpg");
	
	apply_surface(0,0,background,screen);

	//Update The Screen
	if(SDL_Flip(screen) == -1)
	{
		return false;
	}

	event_handler();

	//Increment Frame
	frame++;

	//If a second has passed since the caption was last updated
	if(update.get_ticks() > 1000)
	{
		//The frame rate as string
		std::stringstream caption;

		//Calculate FPS
		caption << "FPS : " << frame / (fps.get_ticks() / 1000.f );

		//Update Caption
		SDL_WM_SetCaption(caption.str().c_str(),NULL);

		//Restart Update Timer
		update.start();
	}

	clean_up();

	return 0;
}


//The Ultimate Event Handler !
void event_handler()
{
	while(quit == false)
	{
		while(SDL_PollEvent(&event))
		{
			if(event.type == SDL_QUIT)
			{
				//Quit the program
				quit = true;
			}
		}
	}
}


The caption didn't change,but when I close the program,the fps flashed on the caption then the window vanished.Why ?

Thanks in advance.
event_handler() will hold on your program until you close it.
Topic archived. No new replies allowed.