Added fullscreen toggle

This commit is contained in:
Michael Chen 2018-01-08 00:45:32 +01:00
parent 1eb3804673
commit d5276012bb

28
main.c
View File

@ -15,6 +15,8 @@ void QUIT();
void GAMELOOP();
void mousePress(SDL_MouseButtonEvent b);
void keyPress(SDL_KeyboardEvent b);
void windowChanged(SDL_WindowEvent b);
void toggleFullscreen();
const int width = 1600; // TODO: Fullscreen
const int height = 900;
@ -23,7 +25,7 @@ Uint8 * keystate; // TODO: export all this into scenery and enemy waves
SDL_Window * window;
SDL_Renderer * renderer;
SDL_Event event;
bool running = true;
bool running = true, fullscreen = false;
int main(int argc, char * args[]){
INITIALIZE();
@ -42,6 +44,9 @@ int main(int argc, char * args[]){
case SDL_MOUSEBUTTONDOWN:
mousePress(event.button);
break;
case SDL_WINDOWEVENT:
windowChanged(event.window);
break;
}
}
}
@ -65,6 +70,26 @@ void mousePress(SDL_MouseButtonEvent b){ // Debug prop
void keyPress(SDL_KeyboardEvent b){ // Debug prop
printf("Key pressed: ID is %d\n", b.keysym.scancode);
if (b.keysym.scancode == SDL_SCANCODE_F11) {
toggleFullscreen();
}
}
void toggleFullscreen(){
if (fullscreen) {
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP);
} else {
SDL_SetWindowFullscreen(window, 0);
}
fullscreen = !fullscreen;
}
void windowChanged(SDL_WindowEvent b){ // Debug prop
switch (b.event) {
case SDL_WINDOWEVENT_SIZE_CHANGED:
printf("Window was resized to (%d|%d)!\n", event.window.data1, event.window.data2);
break;
}
}
void DrawFrame(){
@ -81,6 +106,7 @@ void INITIALIZE() {
else printf("SDL was successfully initialized!\n");
window = SDL_CreateWindow("Asteroids Game", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, SDL_WINDOW_OPENGL);
SDL_SetWindowResizable(window, true);
printf("Window was created!\n");
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
printf("Renderer was created!\n");