Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.42 KB | None | 0 0
  1. //Using SDL and standard IO
  2. #include <SDL2/SDL.h>
  3. #include <stdio.h>
  4.  
  5. //Screen dimension constants
  6. const int SCREEN_WIDTH = 640;
  7. const int SCREEN_HEIGHT = 480;
  8.  
  9. int main( int argc, char* args[] )
  10. {
  11.     //The window we'll be rendering to
  12.     SDL_Window* window = NULL;
  13.    
  14.     //The surface contained by the window
  15.     SDL_Surface* screenSurface = NULL;
  16.  
  17.     int gogogo = 1;
  18.         SDL_Event event;
  19.     SDL_Surface * image = SDL_LoadBMP("image.bmp");
  20.  
  21.     //Initialize SDL
  22.     if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  23.     {
  24.         printf( "SDL could not initialize! SDL_Error: %s\n", SDL_GetError() );
  25.     }
  26.     else
  27.     {
  28.         //Create window
  29.         window = SDL_CreateWindow( "Test Icon", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN );
  30.         SDL_SetWindowIcon(window, image);
  31.         if( window == NULL )
  32.         {
  33.             printf( "Window could not be created! SDL_Error: %s\n", SDL_GetError() );
  34.         }
  35.         else
  36.         {
  37.             //Get window surface
  38.             screenSurface = SDL_GetWindowSurface( window );
  39.  
  40.             //Fill the surface white
  41.             SDL_FillRect( screenSurface, NULL, SDL_MapRGB( screenSurface->format, 0xFF, 0xFF, 0xFF ) );
  42.            
  43.             //Update the surface
  44.             SDL_UpdateWindowSurface( window );
  45.  
  46.             while (gogogo) {
  47.                     SDL_WaitEvent(&event);
  48.                     if (event.type == SDL_QUIT)
  49.                             gogogo = 0;
  50.                     }
  51.             }
  52.     }
  53.  
  54.     //Destroy window
  55.     SDL_DestroyWindow( window );
  56.  
  57.     //Quit SDL subsystems
  58.     SDL_Quit();
  59.  
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement