didattici:esempio2sfml
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
didattici:esempio2sfml [2019/12/31 10:43] – profpro | didattici:esempio2sfml [2020/06/08 22:20] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | Esempio 2 | ||
+ | Prima potrebbe essere necessario installare tutti i pacchetti elencati nella pagina [[didattici: | ||
+ | |||
+ | Poi per compilare questo file si deve usare il comando | ||
+ | |||
+ | gcc main.c -lcsfml-graphics -lcsfml-system -lcsfml-window | ||
+ | |||
+ | |||
+ | <file c main.c> | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | int main() | ||
+ | { | ||
+ | sfVideoMode mode = {400, 200, 32}; | ||
+ | sfRenderWindow* window=NULL; | ||
+ | |||
+ | |||
+ | sfTexture* texture=NULL; | ||
+ | sfEvent event; | ||
+ | /* Create the main window */ | ||
+ | window = sfRenderWindow_create(mode, | ||
+ | if (!window) | ||
+ | return EXIT_FAILURE; | ||
+ | | ||
+ | /* Create a sprite to display */ | ||
+ | | ||
+ | sfSprite* sprite=sfSprite_create(); | ||
+ | texture = sfTexture_createFromFile(" | ||
+ | if (!texture) | ||
+ | return EXIT_FAILURE; | ||
+ | sfSprite_setTexture(sprite, | ||
+ | |||
+ | | ||
+ | /* Start the game loop */ | ||
+ | while (sfRenderWindow_isOpen(window)) | ||
+ | { | ||
+ | /* Process events */ | ||
+ | while (sfRenderWindow_pollEvent(window, | ||
+ | { | ||
+ | /* Close window : exit */ | ||
+ | if (event.type == sfEvtClosed) | ||
+ | sfRenderWindow_close(window); | ||
+ | | ||
+ | else if (event.type == sfEvtKeyPressed ) | ||
+ | if(sfKeyboard_isKeyPressed(sfKeyA)==true) // simboli in SFML/ | ||
+ | { | ||
+ | printf(" | ||
+ | sfVector2f vec = {10.0f, 0.0f};// Shader.h:/// | ||
+ | sfSprite_move(sprite, | ||
+ | } | ||
+ | } | ||
+ | /* Clear the screen */ | ||
+ | sfRenderWindow_clear(window, | ||
+ | |||
+ | /* draw, draw, ... TRA CLEAR E DISPLAY . Vedi RenderWindow.h*/ | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | /* Update the window */ | ||
+ | sfRenderWindow_display(window); | ||
+ | } | ||
+ | /* Cleanup resources */ | ||
+ | |||
+ | sfText_destroy(text); | ||
+ | |||
+ | sfRenderWindow_destroy(window); | ||
+ | return EXIT_SUCCESS; | ||
+ | } | ||
+ | </ |