forked from bisqwit/cpp_parallelization_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdl1-mainloop.cc
More file actions
35 lines (30 loc) · 786 Bytes
/
Copy pathsdl1-mainloop.cc
File metadata and controls
35 lines (30 loc) · 786 Bytes
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
#include <SDL.h>
static const unsigned Xres = 320, Yres = 240;
double GetTime()
{
static std::chrono::time_point<std::chrono::system_clock> begin = std::chrono::system_clock::now();
return std::chrono::duration<double>( std::chrono::system_clock::now() - begin );
}
class Display
{
SDL_Surface* s = SDL_SetVideoMode(Xres, Yres, 32,0);
unsigned frame = 0;
public:
void Put(const std::vector<unsigned>& pixels)
{
std::memcpy(s->pixels, &pixels[0], 4*Xres*Yres);
SDL_Flip(s);
++frame;
std::fprintf(stderr, "Frame%6u, %.2f fps...\r", frame, GetTime() / frame);
std::fflush(stderr);
}
};
int main()
{
Display d;
for(;;)
{
std::vector<unsigned> pixels (Xres * Yres);
d.Put(pixels);
}
}