Advertisement
CapsAdmin

Untitled

Feb 2nd, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.08 KB | None | 0 0
  1.  #include <SFML/Audio.h>
  2.  #include <SFML/Graphics.h>
  3.  
  4.  int main()
  5.  {
  6.      sfVideoMode mode = {800, 600, 32};
  7.      sfRenderWindow* window;
  8.      sfTexture* texture;
  9.      sfSprite* sprite;
  10.      sfFont* font;
  11.      sfText* text;
  12.      sfMusic* music;
  13.      sfEvent event;
  14.  
  15.      /* Create the main window */
  16.      window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL);
  17.      if (!window)
  18.          return EXIT_FAILURE;
  19.  
  20.      /* Load a sprite to display */
  21.      texture = sfTexture_createFromFile("cute_image.jpg");
  22.      if (!texture)
  23.          return EXIT_FAILURE;
  24.      sprite = sfSprite_create();
  25.      sfSprite_setTexture(sprite, texture, sfTrue);
  26.  
  27.      /* Create a graphical text to display */
  28.      font = sfFont_createFromFile("arial.ttf");
  29.      if (!font)
  30.          return EXIT_FAILURE;
  31.      text = sfText_create();
  32.      sfText_setString(text, "Hello SFML");
  33.      sfText_setFont(text, font);
  34.      sfText_setCharacterSize(text, 50);
  35.  
  36.      /* Load a music to play */
  37.      music = sfMusic_createFromFile("nice_music.ogg");
  38.      if (!music)
  39.          return EXIT_FAILURE;
  40.  
  41.      /* Play the music */
  42.      sfMusic_play(music);
  43.  
  44.      /* Start the game loop */
  45.      while (sfRenderWindow_isOpen(window))
  46.      {
  47.          /* Process events */
  48.          while (sfRenderWindow_pollEvent(window, &event))
  49.          {
  50.              /* Close window : exit */
  51.              if (event.type == sfEvtClosed)
  52.                  sfRenderWindow_close(window);
  53.          }
  54.  
  55.          /* Clear the screen */
  56.          sfRenderWindow_clear(window, sfBlack);
  57.  
  58.          /* Draw the sprite */
  59.          sfRenderWindow_drawSprite(window, sprite, NULL);
  60.  
  61.          /* Draw the text */
  62.          sfRenderWindow_drawText(window, text, NULL);
  63.  
  64.          /* Update the window */
  65.          sfRenderWindow_display(window);
  66.      }
  67.  
  68.      /* Cleanup resources */
  69.      sfMusic_destroy(music);
  70.      sfText_destroy(text);
  71.      sfFont_destroy(font);
  72.      sfSprite_destroy(sprite);
  73.      sfTexture_destroy(texture);
  74.      sfRenderWindow_destroy(window);
  75.  
  76.      return EXIT_SUCCESS;
  77.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement