1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220
|
#include "c_sdl2_windows.hpp"
C_MeSDL2Windows::C_MeSDL2Windows(){}
bool C_MeSDL2Windows::Initilize(const bool & InitVideo,
const bool & InitAudio,
const bool & InitEvent,
const bool & InitTimer)
{
if ((InitVideo == true) && SDL_Init(SDL_INIT_VIDEO) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_VIDEO) (%s)\n",SDL_GetError());
return false;
}
if ((InitAudio == true) && SDL_Init(SDL_INIT_AUDIO) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_AUDIO) (%s)\n",SDL_GetError());
return false;
}
if ((InitEvent == true) && SDL_Init(SDL_INIT_EVENTS) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_EVENTS) (%s)\n",SDL_GetError());
return false;
}
if ((InitTimer == true) && SDL_Init(SDL_INIT_TIMER) != 0 )
{
fprintf(stdout,"Échec de l'initialisation de la SDL (SDL_INIT_TIMER) (%s)\n",SDL_GetError());
return false;
}
return true;
}
void C_MeSDL2Windows::M_SetExitSdl(){
if( pWindow != nullptr) { pWindow=nullptr;}
SDL_Quit();
}
void C_MeSDL2Windows::M_CreateWindows(const std::string & WTitre,
const bool & AuCentre,
const int & TailleVertical,
const int & TailleHorizontal,
const bool & Visible){
int vHideOrShows=0;
if (Visible == true){
vHideOrShows=SDL_WINDOW_SHOWN;
}
else
{
vHideOrShows=SDL_WINDOW_HIDDEN;
}
if (AuCentre){
pWindow = SDL_CreateWindow(WTitre.c_str(),
SDL_WINDOWPOS_CENTERED,
SDL_WINDOWPOS_CENTERED,
TailleHorizontal,
TailleVertical,
vHideOrShows);
}
else{
pWindow = SDL_CreateWindow(WTitre.c_str(),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
TailleHorizontal,
TailleVertical,
vHideOrShows);
}
if( pWindow == NULL) {std::cout << "Erreur: pointeur null suite a la creation de la fenêtre";}
else { C_MeSDL2Windows::M_SetGpuRenderer();}
}
void C_MeSDL2Windows::M_Pause(const Uint32 & Time){
if( pWindow )
{
SDL_Delay(Time);
}
else
{
fprintf(stderr,"Erreur de création de la fenêtre: %s\n",SDL_GetError());
}
}
void C_MeSDL2Windows::M_DestructionWindows(){
if( pWindow )
{
SDL_DestroyWindow(pWindow);
}
pWindow=nullptr;
}
bool C_MeSDL2Windows::M_SetFullScreen(){
if( pWindow )
{
if (SDL_SetWindowFullscreen(pWindow,SDL_WINDOW_FULLSCREEN_DESKTOP ) == 0 )
{
return true;
}
else
{
return false;
}
}
return false;
}
int C_MeSDL2Windows::M_GetResolution(std::vector<int> & F_VecHauteur,
std::vector<int> & F_VecLargeur,
std::vector<int> & F_VecFrequance)
{
int modeNumber = SDL_GetNumDisplayModes(0);
int error = 0;
if (modeNumber < 0)
{
fprintf(stdout,"Échec lors de la récupération du nombre de modes (%s)\n",SDL_GetError());
// return -2;
}
fprintf(stdout,"Vous avez %d mode(s) d'affichage\n", modeNumber);
// Affichage des différents modes
SDL_DisplayMode displayMode;
for (int i = 0 ; i < modeNumber ; i++)
{
error = SDL_GetDisplayMode(0, i, &displayMode);
if (error < 0)
{
fprintf(stdout, "Échec lors de la récupération du mode d'affichage (%s)\n", SDL_GetError());
return -3;
}
/*
std::cout << "Ligne: " << i <<
" Largeur: " << displayMode.w <<
"Hauteur" << displayMode.h <<
" Frequance " << displayMode.refresh_rate <<
std::endl;
*/
F_VecHauteur.push_back(displayMode.h);
F_VecLargeur.push_back(displayMode.w);
F_VecFrequance.push_back(displayMode.refresh_rate);
//fprintf(stdout, "Mode %d : %dx%dx%d\n", i, displayMode.w, displayMode.h, displayMode.refresh_rate);
}
}
void C_MeSDL2Windows::M_sprit(std::string & pathimage){
// SDL_Surface* pSprite = SDL_LoadBMP("./image.bmp");
// std::string pathimage="./image.bmp";
SDL_Renderer *pRenderer = SDL_CreateRenderer(pWindow,-1,SDL_RENDERER_ACCELERATED); // Création d'un SDL_Renderer utilisant l'accélération matérielle
if ( pRenderer )
{
SDL_Surface* pSprite = SDL_LoadBMP(pathimage.c_str());
if ( pSprite )
{
SDL_Texture* pTexture = SDL_CreateTextureFromSurface(pRenderer,pSprite); // Préparation du sprite
if ( pTexture )
{
SDL_Rect dest = { 640/2 - pSprite->w/2,480/2 - pSprite->h/2, pSprite->w, pSprite->h};
SDL_RenderCopy(pRenderer,pTexture,NULL,&dest); // Copie du sprite grâce au SDL_Renderer
SDL_RenderPresent(pRenderer); // Affichage
SDL_Delay(3000); /* Attendre trois secondes, que l'utilisateur voit la fenêtre */
SDL_DestroyTexture(pTexture); // Libération de la mémoire associée à la texture
}
else
{
fprintf(stdout,"Échec de création de la texture (%s)\n",SDL_GetError());
}
SDL_FreeSurface(pSprite); // Libération de la ressource occupée par le sprite
}
else
{
fprintf(stdout,"Échec de chargement du sprite (%s)\n",SDL_GetError());
}
SDL_DestroyRenderer(pRenderer); // Libération de la mémoire du SDL_Renderer
}
else
{
fprintf(stdout,"Échec de création du renderer (%s)\n",SDL_GetError());
}
}
void C_MeSDL2Windows::M_SetGpuRenderer(){
pRenderer = SDL_CreateRenderer(pWindow, -1, SDL_RENDERER_ACCELERATED);
}
void C_MeSDL2Windows::M_SetLuminositer(const float & lum){
if( pWindow )
{
SDL_SetWindowBrightness(pWindow,lum);
}
else
{
std::cout << "Erreur pointeur invalide M_SetLuminositer " << std::endl;
}
}
void C_MeSDL2Windows::M_SetUpdateScreen(){
if( pWindow )
{
SDL_RenderPresent(pRenderer);
}
else
{
std::cout << "Erreur pointeur invalide M_SetUpdateScreen " << std::endl;
}
}
void C_MeSDL2Windows::M_SetWindowsShow(){
SDL_ShowWindow(pWindow);
}
void C_MeSDL2Windows::M_CouleurDefond(const int & rouge,
const int & vert ,
const int & bleu,
const int & transparence){
SDL_SetRenderDrawColor(pRenderer, rouge, vert, bleu, transparence);
} |
Partager