This repository has been archived by the owner on Mar 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
75 lines (60 loc) · 1.42 KB
/
main.c
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
#include <stdlib.h>
#include <stdio.h>
#include <SDL/SDL.h>
#include "erreurs.h"
#define PROFONDEUR 24
typedef enum {
TRUE = (0==0),
FALSE = (0==1)
} bool;
// Variable globale boucle.
bool boucle = TRUE;
SDL_Surface* init() {
if (SDL_Init(SDL_INIT_VIDEO) != 0) {
die("Erreur lors de l'initialisation de SDL :");
}
SDL_Surface* fenetre;
fenetre = SDL_SetVideoMode(640, 480, PROFONDEUR, SDL_HWSURFACE);
if (fenetre == NULL) {
die("Erreur lors de la création de la fenêtre.");
}
SDL_WM_SetCaption("Lew", NULL);
SDL_WM_SetIcon(SDL_LoadBMP("icone.bmp"), NULL);
SDL_FillRect(fenetre, NULL, SDL_MapRGB(fenetre->format, 0, 0, 0));
SDL_Flip(fenetre);
return fenetre;
}
void quit() {
SDL_Quit();
exit(EXIT_SUCCESS);
}
void clavier(SDL_Event* ev) {
switch (ev->key.keysym.sym) {
case SDLK_ESCAPE:
case SDLK_q:
boucle = FALSE;
break;
}
}
int main(int argc, char** argv) {
SDL_Surface* fenetre = init();
SDL_Surface* bloc = SDL_CreateRGBSurface(SDL_HWSURFACE, 11, 11, PROFONDEUR, 0, 0, 0, 0);
SDL_FillRect(bloc, NULL, SDL_MapRGB(fenetre->format, 255, 255, 255));
SDL_Rect position = {0,0};
SDL_BlitSurface(bloc, NULL, fenetre, &position);
SDL_Flip(fenetre);
SDL_Event evenement;
while (boucle) {
SDL_WaitEvent(&evenement);
switch (evenement.type) {
case SDL_QUIT:
boucle = FALSE;
break;
case SDL_KEYDOWN:
clavier(&evenement);
break;
}
}
SDL_FreeSurface(bloc);
quit();
}