lab.cpp/SDL#1/main.cpp

93 lines
1.8 KiB
C++
Raw Permalink Normal View History

2016-03-10 11:06:45 +00:00
#include "main.h"
// On cree un sdl-toplevel statique
2016-03-10 20:38:15 +00:00
static sdltl *mgr = NULL;
static bool running = true;
2016-03-10 11:06:45 +00:00
int main(int argc, char* argv[]) {
2016-03-10 20:38:15 +00:00
srand(time(0));
2016-03-10 11:06:45 +00:00
/* [0] Initialisation de SDL
=========================================================*/
mgr = new sdltl("Ma fenetre SDL", WIN_WIDTH, WIN_HEIGHT);
/* [1] Creation de la fenetre
=========================================================*/
2016-03-10 20:38:15 +00:00
if( !mgr->status() ) cout << "Erreur: " << SDL_GetError() << endl;
2016-03-10 11:06:45 +00:00
/* [3] On definit le background color
=========================================================*/
2016-03-10 20:38:15 +00:00
mgr->setBackground(255, 255, 255);
// bool imageLoaded = mgr->setImage( "src/1.bmp" );
/* [4] On ajoute une sprite
=========================================================*/
2016-03-10 23:00:26 +00:00
SpriteGroup background;
2016-03-10 20:38:15 +00:00
/* (1) Bloc vide */
2016-03-10 23:00:26 +00:00
background.add( new Sprite(
(SDL_Rect) {0, 0, 200, 200}
));
2016-03-10 20:38:15 +00:00
/* (2) Bloc rose */
int pink[] = {255, 0, 255};
2016-03-10 23:00:26 +00:00
cout << "a: [" << (sizeof(pink)/sizeof(*pink)) << "]" << endl;
background.add( new Sprite(
pink,
(SDL_Rect){200, 0, 200, 200}
));
2016-03-10 20:38:15 +00:00
/* (2) Bloc image */
2016-03-10 23:00:26 +00:00
background.add( new Sprite(
"src/1.bmp",
(SDL_Rect){400, 0, 200, 200},
(SDL_Rect){200, 200, 200, 200}
));
2016-03-10 20:38:15 +00:00
/* [5] On ajoute les elements + mise a jour affichage
=========================================================*/
2016-03-10 23:00:26 +00:00
background.appendTo( mgr->screen() );
2016-03-10 11:06:45 +00:00
mgr->update();
2016-03-10 20:38:15 +00:00
2016-03-10 11:06:45 +00:00
/* [n-1] Boucle infinie
=========================================================*/
2016-03-10 20:38:15 +00:00
mgr->manageFps(FPS);
running = true;
while(running){
mgr->waitEvent(SDL_QUIT, &quitEventHandler);
// Gestion des FPS (vitesse de la boucle)
mgr->manageFps();
}
2016-03-10 11:06:45 +00:00
/* [n] Fin d'execution
=========================================================*/
delete mgr;
return 0;
}
2016-03-10 20:38:15 +00:00
void quitEventHandler(SDL_Event *e){
2016-03-10 11:06:45 +00:00
cout << "Ferme" << endl;
2016-03-10 20:38:15 +00:00
running = false;
2016-03-10 11:06:45 +00:00
}