User Tools

Site Tools


projtec:sdl2

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
projtec:sdl2 [2017/02/13 09:58] orelprojtec:sdl2 [2024/03/18 15:06] (current) – external edit 127.0.0.1
Line 7: Line 7:
   * https://www.libsdl.org/projects/SDL_image/   * https://www.libsdl.org/projects/SDL_image/
  
 +Voici quelques tuoriels utiles pour bien commençer :
 +
 +  * http://lazyfoo.net/tutorials/SDL/
  
 Nous proposons ici un modèle de programme avec SDL2, et une petit exemple d'utilisation de ce modèle. La démo montre diverses possibilités de SDL2, comme le texte TTF, les textures transparentes en PNG, ... Vous trouverez tout cela dans l'archive : {{:projtec:sdl2-demo.zip}}. Lire le README.txt pour démarrer. Nous proposons ici un modèle de programme avec SDL2, et une petit exemple d'utilisation de ce modèle. La démo montre diverses possibilités de SDL2, comme le texte TTF, les textures transparentes en PNG, ... Vous trouverez tout cela dans l'archive : {{:projtec:sdl2-demo.zip}}. Lire le README.txt pour démarrer.
Line 48: Line 51:
 #define PRINT(STR, ...) do { SDL_Log(STR, ##__VA_ARGS__);  } while(0) #define PRINT(STR, ...) do { SDL_Log(STR, ##__VA_ARGS__);  } while(0)
 #define ERROR(STR, ...) do { SDL_Log(STR, ##__VA_ARGS__); exit(EXIT_FAILURE); } while(0)  #define ERROR(STR, ...) do { SDL_Log(STR, ##__VA_ARGS__); exit(EXIT_FAILURE); } while(0) 
-// #define LOG(TAG, STR, ...) __android_log_print(ANDROID_LOG_VERBOSE, TAG ,STR, ##__VA_ARGS__) 
 # else # else
 #define PRINT(STR, ...) do { printf(STR, ##__VA_ARGS__); } while(0) #define PRINT(STR, ...) do { printf(STR, ##__VA_ARGS__); } while(0)
Line 72: Line 74:
 // SDL2 Demo by aurelien.esnard@u-bordeaux.fr // SDL2 Demo by aurelien.esnard@u-bordeaux.fr
            
-#include <SDL2/SDL.h> +#include <SDL.h> 
-#include <SDL2/SDL_image.h>  // required to load transparent texture from PNG +#include <SDL_image.h>  // required to load transparent texture from PNG 
-#include <SDL2/SDL_ttf.h>    // required to use TTF fonts     +#include <SDL_ttf.h>    // required to use TTF fonts     
 #include <stdio.h> #include <stdio.h>
 #include <stdbool.h> #include <stdbool.h>
Line 84: Line 86:
  
   /* initialize SDL2 and some extensions */   /* initialize SDL2 and some extensions */
-  if(SDL_Init(SDL_INIT_VIDEO) != 0) ERROR("SDL_Init VIDEO");  +  if(SDL_Init(SDL_INIT_VIDEO) != 0) ERROR("Error: SDL_Init VIDEO (%s)", SDL_GetError());   
-  if(IMG_Init(IMG_INIT_PNG & IMG_INIT_PNG) != IMG_INIT_PNG) ERROR("IMG_Init PNG"); +  if(IMG_Init(IMG_INIT_PNG & IMG_INIT_PNG) != IMG_INIT_PNG) ERROR("Error: IMG_Init PNG (%s)", SDL_GetError());   
-  if(TTF_Init() != 0) ERROR("TTF_Init");  +  if(TTF_Init() != 0) ERROR("Error: TTF_Init (%s)", SDL_GetError());  
            
   /* create window and renderer */   /* create window and renderer */
   SDL_Window * win = SDL_CreateWindow(APP_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,   SDL_Window * win = SDL_CreateWindow(APP_NAME, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
           SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);           SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
-  if(!win) ERROR("SDL_CreateWindow");  +  if(!win) ERROR("Error: SDL_CreateWindow (%s)", SDL_GetError());  
   SDL_Renderer * ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);   SDL_Renderer * ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
-  if(!ren) ERROR("SDL_CreateWindow");    +  if(!ren) ERROR("Error: SDL_CreateRenderer (%s)", SDL_GetError());  
            
   /* initialize your environment */   /* initialize your environment */
Line 139: Line 141:
 // SDL2 Demo by aurelien.esnard@u-bordeaux.fr // SDL2 Demo by aurelien.esnard@u-bordeaux.fr
  
-#include <SDL2/SDL.h> +#include <SDL.h> 
-#include <SDL2/SDL_image.h>  // required to load transparent texture from PNG +#include <SDL_image.h>  // required to load transparent texture from PNG 
-#include <SDL2/SDL_ttf.h>    // required to use TTF fonts     +#include <SDL_ttf.h>    // required to use TTF fonts     
  
 #include <stdio.h> #include <stdio.h>
Line 202: Line 204:
 ==== Portage sous Android  ==== ==== Portage sous Android  ====
  
-Le code proposé ci-dessus est 100% portable sous Android... Plus dé détails bientôt.+Le code proposé ci-dessus est 100% portable sous Android : [[projtec:android|c'est ici !]]
  
projtec/sdl2.1486979938.txt.gz · Last modified: 2024/03/18 15:05 (external edit)