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
|
//FLASHING SCREEN CODE
//Demonstrates screen freeze when you minimise then maximise the screen....
#include "SDL.h"
using namespace std;
int main( int argc, char* args[] )
{
//Initialise SDL2, declare Window + Renderer
SDL_Init( SDL_INIT_VIDEO | SDL_INIT_AUDIO ); //Initialize SDL for video and audio
SDL_Window* pWindow = NULL;
SDL_Renderer* pRenderer = NULL;
pWindow = SDL_CreateWindow("Minimise Maximise Test", 50, 50, 1200, 600, SDL_WINDOW_RESIZABLE | SDL_WINDOW_MAXIMIZED);
pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_TARGETTEXTURE);
//The Screen colour which is going to flash through different shades of grey
SDL_Color screenColour = {0, 0, 0};
//SDL event for detecting X-out (quit)
SDL_Event event;
bool quit = false;
//Loop
while( quit == false ) //While SDL has not been X'ed out
{
////Handle quit
if (SDL_PollEvent(&event) != 0)
{
if(event.type == SDL_QUIT) quit = true; //Press X-out to quit (but not visible on fullscreen)
}
//Make screen flash by changing its colour through shades of grey
screenColour.r++;
screenColour.g++;
screenColour.b++;
//Render the screen
SDL_SetRenderDrawColor(pRenderer, screenColour.r, screenColour.g, screenColour.b, 255);
SDL_RenderFillRect(pRenderer, NULL);
SDL_RenderPresent(pRenderer); //like SDL_flip
}
//Shutdown
SDL_DestroyRenderer(pRenderer);
SDL_DestroyWindow(pWindow);
SDL_Quit();
return 0;
}
|