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
| #include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
//°°°°° EN-TETES °°°°°//
void INITS();
void CONFIGS(SDL_Surface *screen);
void RECTCOLOR(int largeur, int hauteur, int resolution_couleur, int red, int green, int blue, int a, int b, SDL_Surface *rectangle; SDL_Surface *tmpy_screen);
void PAUSE();
//°°°°° FONCTION PRINCIPALE °°°°°//
int main(int argc, char *argv[])
{
SDL_Surface ecran;
SDL_Surface surface;
INITS();
CONFIGS(&ecran);
RECTCOLOR(30, 30, 32, 255, 255, 255, 0, 0, &surface, &ecran);
PAUSE();
SDL_Quit();
}
//°°°°° FONCTION POUR L'INITIALISATIONS °°°°°//
void INITS()
{
FILE *SDL_erreur=NULL;
SDL_erreur=fopen("erreur_initialisation.txt","r+");
/***** On vérifie que "erreur_initialisation.txt" existe *****/
if ( SDL_erreur==NULL )
{
fprintf( SDL_erreur, "Le fichier erreur_initialisation.txt n'existe pas !");
}
else
{
fprintf( SDL_erreur, "L'initialisation va pouvoir être effectuée !");
}
fclose(SDL_erreur);
/***** On vérifie l'initialisation de la SDL *****/
if (SDL_Init(SDL_INIT_VIDEO) == -1)
{
fprintf( SDL_erreur, "Erreur d'initialisation de la SDL : %s\n", SDL_GetError() );
}
else
{
fprintf( SDL_erreur, "Initialisation de la SDL terminée avec succés !");
}
}
//°°°°° FONCTION POUR CONFIGURER LA FENETRE °°°°°//
void CONFIGS(SDL_Surface *screen)
{
/***** CONFIGURATIONS DE LA FENETRE VIDEO ****/
screen=SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE);
/***** CONFIGURATION DU TITRE DE LA FENETRE ****/
SDL_WM_SetCaption("SDL", NULL);
/***** COULEUR DE FOND D'ECRAN *****/
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 17, 206, 112));
/***** APRES AVOIR MODIFIEE LA COULEUR ON RAFRAICHIT POUR QU'ELLE S'AFFICHE *****/
SDL_Flip(screen);
}
//°°°°° FONCTION POUR PERMETTRE UNE PAUSE °°°°°//
void PAUSE()
{
int continuer = 1;
SDL_Event event;
while (continuer)
{
SDL_WaitEvent(&event);
switch(event.type)
{
case SDL_QUIT:
continuer = 0;
}
}
}
//°°°°° FONCTION POUR AJOUTER UN RECTANGLE DE COULEUR °°°°°//
void RECTCOLOR(int largeur, int hauteur, int resolution_couleur, int red, int green, int blue, int a, int b, SDL_Surface *rectangle, SDL_Surface *tmpy_screen )
{
/***** Sous-fonction pour colorier le rectangle *****/
//~~~~ Affectation a rectangle une surface de largeur x et de hauteur y ~~~~//
rectangle = SDL_CreateRGBSurface(SDL_HWSURFACE, largeur, hauteur, resolution_couleur, 0, 0, 0, 0);
//~~~~ Coloriage de rectangle *****/
SDL_FillRect(rectangle, NULL, SDL_MapRGB(tmpy_screen->format, red, green, blue));
//~~~~ Rafraichissement de l'écran pour afficher la nouvelle couleur ~~~~//
SDL_Flip(tmpy_screen);
/***** Sous-fonction pour placer le rectangle sur l'écran *****/
//~~~~ Déclaration des variables coordonnées du rectangle ~~~~//
SDL_Rect coordonnees;
coordonnees.x = a;
coordonnees.y = b;
//~~~~ Insertion du rectangle dans l'écran ~~~~//
SDL_BlitSurface(rectangle, NULL, tmpy_screen, &coordonnees);
//~~~~ Rafraichissement de l'écran pour afficher le rectangle ~~~~//
SDL_Flip(tmpy_screen);
} |
Partager