projtec:sdl2
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| projtec:sdl2 [2017/02/09 10:13] – orel | projtec:sdl2 [2024/03/18 15:06] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 7: | Line 7: | ||
| * https:// | * https:// | ||
| - | ==== Une petite coquille | + | Voici quelques tuoriels utiles |
| - | Notre coquille | + | * http:// |
| + | |||
| + | Nous proposons ici un modèle de programme avec SDL2, et une petit exemple d' | ||
| + | |||
| + | |||
| + | {{ : | ||
| + | |||
| + | |||
| + | ==== Un Modèle de Programme SDL2 ==== | ||
| + | |||
| + | Notre modèle | ||
| + | |||
| + | * La fonction //init()// permet l' | ||
| + | * La fonction //clean()// permet principalement de terminer votre programme, en libérant les allocations mémoire effectuées dans la phase d' | ||
| + | * La fonction // | ||
| + | * La fonction // | ||
| + | |||
| + | Voici la déclaration des fonctions utiles à notre modèle | ||
| + | |||
| + | <code C model.h> | ||
| + | // SDL2 Model by aurelien.esnard@u-bordeaux.fr | ||
| + | |||
| + | #ifndef MODEL_H | ||
| + | #define MODEL_H | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | typedef struct Env_t Env; | ||
| + | |||
| + | /* **************************************************************** */ | ||
| + | |||
| + | #define APP_NAME "Hello World!" | ||
| + | #define SCREEN_WIDTH 600 | ||
| + | #define SCREEN_HEIGHT 600 | ||
| + | |||
| + | /* **************************************************************** */ | ||
| + | |||
| + | #ifdef __ANDROID__ | ||
| + | #define PRINT(STR, ...) do { SDL_Log(STR, | ||
| + | #define ERROR(STR, ...) do { SDL_Log(STR, | ||
| + | # else | ||
| + | #define PRINT(STR, ...) do { printf(STR, ## | ||
| + | #define ERROR(STR, ...) do { fprintf(stderr, | ||
| + | #endif | ||
| + | |||
| + | /* **************************************************************** */ | ||
| + | |||
| + | Env * init(SDL_Window* win, SDL_Renderer* ren, int argc, char* argv[]); | ||
| + | void render(SDL_Window* win, SDL_Renderer* ren, Env * env); | ||
| + | void clean(SDL_Window* win, SDL_Renderer* ren, Env * env); | ||
| + | bool process(SDL_Window* win, SDL_Renderer* ren, Env * env, SDL_Event * e); | ||
| + | |||
| + | /* **************************************************************** */ | ||
| + | |||
| + | #endif | ||
| + | </ | ||
| - | * init() : ... | ||
| - | * render() : ... | ||
| - | * process() : ... | ||
| - | * clean() : ... | ||
| Voici le code du programme principal : | Voici le code du programme principal : | ||
| Line 21: | Line 74: | ||
| // SDL2 Demo by aurelien.esnard@u-bordeaux.fr | // SDL2 Demo by aurelien.esnard@u-bordeaux.fr | ||
| - | #include <SDL2/SDL.h> | + | #include < |
| - | #include <SDL2/SDL_image.h> | + | #include < |
| - | #include <SDL2/SDL_ttf.h> | + | #include < |
| #include < | #include < | ||
| #include < | #include < | ||
| #include " | #include " | ||
| - | + | ||
| - | /* **************************************************************** */ | + | |
| - | + | ||
| - | #define SCREEN_WIDTH 640 | + | |
| - | #define SCREEN_HEIGHT 480 | + | |
| - | + | ||
| /* **************************************************************** */ | /* **************************************************************** */ | ||
| Line 38: | Line 86: | ||
| { | { | ||
| /* initialize SDL2 and some extensions */ | /* initialize SDL2 and some extensions */ | ||
| - | if(SDL_Init(SDL_INIT_VIDEO) != 0) ERROR(" | + | if(SDL_Init(SDL_INIT_VIDEO) != 0) ERROR(" |
| - | if(IMG_Init(IMG_INIT_PNG & IMG_INIT_PNG) != IMG_INIT_PNG) ERROR(" | + | if(IMG_Init(IMG_INIT_PNG & IMG_INIT_PNG) != IMG_INIT_PNG) ERROR(" |
| - | if(TTF_Init() != 0) ERROR(" | + | if(TTF_Init() != 0) ERROR(" |
| /* create window and renderer */ | /* create window and renderer */ | ||
| - | SDL_Window * win = SDL_CreateWindow("Hello World!" | + | SDL_Window * win = SDL_CreateWindow(APP_NAME, SDL_WINDOWPOS_UNDEFINED, |
| SCREEN_WIDTH, | SCREEN_WIDTH, | ||
| - | if(!win) ERROR(" | + | if(!win) ERROR(" |
| SDL_Renderer * ren = SDL_CreateRenderer(win, | SDL_Renderer * ren = SDL_CreateRenderer(win, | ||
| - | if(!ren) ERROR(" | + | if(!ren) ERROR(" |
| /* initialize your environment */ | /* initialize your environment */ | ||
| Line 87: | Line 135: | ||
| </ | </ | ||
| - | <code C model.h> | ||
| - | // SDL2 Model by aurelien.esnard@u-bordeaux.fr | ||
| - | #ifndef MODEL_H | + | Et voici une coquille vide pour implanter les fonctions de notre modèle : |
| - | #define MODEL_H | + | |
| - | + | ||
| - | #include < | + | |
| - | #include < | + | |
| - | #include < | + | |
| - | + | ||
| - | typedef struct Env_t Env; | + | |
| - | + | ||
| - | /* **************************************************************** */ | + | |
| - | + | ||
| - | #ifdef __ANDROID__ | + | |
| - | #define PRINT(STR, ...) do { SDL_Log(STR, | + | |
| - | #define ERROR(STR, ...) do { SDL_Log(STR, | + | |
| - | // #define LOG(TAG, STR, ...) __android_log_print(ANDROID_LOG_VERBOSE, | + | |
| - | # else | + | |
| - | #define PRINT(STR, ...) do { printf(STR, ## | + | |
| - | #define ERROR(STR, ...) do { fprintf(stderr, | + | |
| - | #endif | + | |
| - | + | ||
| - | /* **************************************************************** */ | + | |
| - | + | ||
| - | Env * init(SDL_Window* win, SDL_Renderer* ren, int argc, char* argv[]); | + | |
| - | void render(SDL_Window* win, SDL_Renderer* ren, Env * env); | + | |
| - | void clean(SDL_Window* win, SDL_Renderer* ren, Env * env); | + | |
| - | bool process(SDL_Window* win, SDL_Renderer* ren, Env * env, SDL_Event * e); | + | |
| - | + | ||
| - | /* **************************************************************** */ | + | |
| - | + | ||
| - | #endif | + | |
| - | </ | + | |
| <code C model.c> | <code C model.c> | ||
| // SDL2 Demo by aurelien.esnard@u-bordeaux.fr | // SDL2 Demo by aurelien.esnard@u-bordeaux.fr | ||
| - | #include <SDL2/SDL.h> | + | #include < |
| - | #include <SDL2/SDL_image.h> | + | #include < |
| - | #include <SDL2/SDL_ttf.h> | + | #include < |
| #include < | #include < | ||
| Line 184: | Line 200: | ||
| } | } | ||
| </ | </ | ||
| - | |||
| - | |||
| - | ==== Petite Démo ==== | ||
| - | |||
| - | Pour illustrer notre petite coquille, voici une petite démo qui montre les différentes possibilités de SDL2 (texte TTF, texture transparente PNG, ...). Vous trouverez tout cela dans l' | ||
| ==== Portage sous Android | ==== Portage sous Android | ||
| - | //coming soon!// | + | Le code proposé ci-dessus est 100% portable sous Android : [[projtec: |
projtec/sdl2.1486635214.txt.gz · Last modified: 2024/03/18 15:05 (external edit)
