forked from bisqwit/cpp_parallelization_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsdl2-mainloop.cc
More file actions
38 lines (33 loc) · 1.06 KB
/
Copy pathsdl2-mainloop.cc
File metadata and controls
38 lines (33 loc) · 1.06 KB
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
#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_Window* w = SDL_CreateWindow("zoom", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, Xres, Yres, SDL_WINDOW_RESIZABLE);
SDL_Renderer* r = SDL_CreateRenderer(w, -1, 0);
SDL_Texture* t = SDL_CreateTexture(r, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, Xres, Yres);
unsigned frame = 0;
public:
void Put(const std::vector<unsigned>& pixels)
{
SDL_UpdateTexture(t, nullptr, &pixels[0], 4*Xres);
SDL_RenderCopy(r, t, nullptr, nullptr);
SDL_RenderPresent(r);
++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);
}
}