User Tools

Site Tools


didattici:esempio1sfml

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
didattici:esempio1sfml [2019/12/31 10:42]
profpro
didattici:esempio1sfml [2020/06/08 22:20] (current)
Line 1: Line 1:
 +Esempio 1
  
 +Prima potrebbe essere necessario installare tutti i pacchetti elencati nella pagina [[didattici:sfml]]
 +
 +Poi per compilare questo file si deve usare il comando
 +
 +  gcc main.c -lcsfml-graphics -lcsfml-system -lcsfml-window 
 +
 +<file c main.c>
 +#include <stdlib.h>
 +#include <SFML/Audio.h>
 +#include <SFML/Graphics.h>
 +
 +int main()
 +{
 +    sfVideoMode mode = {400, 200, 32};
 +    sfRenderWindow* window;
 +    sfTexture* texture;
 +    sfFont* font;
 +    sfText* text;
 +
 +    sfEvent event;
 +    /* Create the main window */
 +    window = sfRenderWindow_create(mode, "SFML Titolone", sfResize | sfClose, NULL);
 +    if (!window)
 +        return EXIT_FAILURE;
 +
 +    /* Create a graphical text to display */
 +    font = sfFont_createFromFile("/usr/share/fonts/truetype/ttf-dejavu/DejaVuSans.ttf"); /* modificato per ubuntu*/
 +    /* font = sfFont_createFromFile("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf"); /* modificato per debian */
 +    text = sfText_create();
 +    sfText_setString(text, "ciao a qualcuno");
 +    sfText_setFont(text, font);
 +    sfText_setCharacterSize(text, 20);
 +
 +    /* sfColor colore = sfColor_fromRGB(111,255,111); //aggiunto eventuale colore*/
 +    /* Start the game loop */
 +    while (sfRenderWindow_isOpen(window))
 +    {
 +        /* Process events */
 +        while (sfRenderWindow_pollEvent(window, &event))
 +        {
 +            /* Close window : exit */
 +            if (event.type == sfEvtClosed)
 +                sfRenderWindow_close(window);
 +        }
 +        /* Clear the screen */
 +        sfRenderWindow_clear(window, sfGreen);
 +        /* Draw the text */
 +       sfRenderWindow_drawText(window, text, NULL);
 +
 +        /* Draw the text */
 +       sfRenderWindow_drawText(window, text, NULL);
 +        /* Update the window */
 +        sfRenderWindow_display(window);
 +    }
 +    /* Cleanup resources */
 +
 +    sfText_destroy(text);
 +
 +    sfRenderWindow_destroy(window);
 +    return EXIT_SUCCESS;
 +}
 +</file>