toggle fullscreen
This commit is contained in:
parent
0686d226b3
commit
b42a20e490
30
main.cpp
30
main.cpp
|
@ -156,7 +156,7 @@ int main(int argc, char *argv[])
|
|||
SDL_WINDOWPOS_UNDEFINED,
|
||||
sw,
|
||||
sh,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_FULLSCREEN);
|
||||
SDL_WINDOW_OPENGL);
|
||||
if (window == NULL)
|
||||
{
|
||||
fprintf(stderr, "Could not create window: %s\n", SDL_GetError());
|
||||
|
@ -384,18 +384,19 @@ int main(int argc, char *argv[])
|
|||
|
||||
int framerate = 60;
|
||||
float frame_length = 1000.0 / framerate;
|
||||
int last_frame_timestamp = SDL_GetTicks();
|
||||
int last_frame_timestamp, frame_count_timestamp, last_capture_timestamp;
|
||||
last_frame_timestamp = frame_count_timestamp = last_capture_timestamp = SDL_GetTicks();
|
||||
bool is_recording = false;
|
||||
std::list<SDL_Surface*> frames;
|
||||
int recording_capture_framerate = 100, last_capture_timestamp = SDL_GetTicks();
|
||||
int frame_time_overflow = 0, capture_time_overflow = 0, ticks;
|
||||
int recording_capture_framerate = 100, frame_time_overflow = 0, capture_time_overflow = 0,
|
||||
frame_count = 0, ticks;
|
||||
|
||||
while (!done)
|
||||
{
|
||||
ticks = SDL_GetTicks();
|
||||
if (ticks - last_frame_timestamp + frame_time_overflow >= frame_length)
|
||||
{
|
||||
printf("frame at %i, overflow %i\n", ticks, frame_time_overflow);
|
||||
frame_count++;
|
||||
frame_time_overflow = ticks - last_frame_timestamp +
|
||||
frame_time_overflow - frame_length;
|
||||
last_frame_timestamp = ticks;
|
||||
|
@ -427,6 +428,17 @@ int main(int argc, char *argv[])
|
|||
end_recording(frames, &is_recording);
|
||||
}
|
||||
}
|
||||
else if (event.key.keysym.sym == SDLK_F11)
|
||||
{
|
||||
if (SDL_GetWindowFlags(window) & SDL_WINDOW_FULLSCREEN)
|
||||
{
|
||||
SDL_SetWindowFullscreen(window, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (is_recording && ticks - last_capture_timestamp + capture_time_overflow >
|
||||
|
@ -472,7 +484,13 @@ int main(int argc, char *argv[])
|
|||
//SDL_RenderPresent(renderer);
|
||||
SDL_GL_SwapWindow(window);
|
||||
}
|
||||
SDL_Delay(15);
|
||||
if (ticks - frame_count_timestamp >= 1000)
|
||||
{
|
||||
frame_count_timestamp = ticks;
|
||||
printf("%i\n", frame_count);
|
||||
frame_count = 0;
|
||||
}
|
||||
// SDL_Delay(15);
|
||||
}
|
||||
SDL_GL_DeleteContext(glcontext);
|
||||
SDL_DestroyTexture(texture);
|
||||
|
|
Loading…
Reference in New Issue