Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unsigned char* DrawBoDes1(unsigned int width, unsigned int height)
- {
- assert(width > 0);
- assert(height > 0);
- // Pas besoin de protéger le new ici: s'il déclenche une exception nous n'avons aucune mémoire à libérer
- unsigned char* img = new unsigned char[width * height * 4];
- try
- {
- if (!FillImage(img, Color(135, 206, 235)))
- {
- delete[] img;
- return nullptr;
- }
- }
- catch (const std::exception& e)
- {
- delete[] img;
- throw; //< On relance l'exception
- }
- // Chargeons une image de soleil à mettre dans le coin haut-gauche
- unsigned char* sunImg;
- try
- {
- sunImg = LoadImgFromFile("sun.png");
- if (!sunImg)
- {
- delete[] img;
- return nullptr;
- }
- }
- catch (const std::exception& e)
- {
- delete[] img;
- throw;
- }
- try
- {
- if (!BlitImage(img, sunImg, 0, 0))
- {
- delete[] sunImg;
- delete[] img;
- return nullptr;
- }
- }
- catch (const std::exception& e)
- {
- delete[] sunImg;
- delete[] img;
- return nullptr;
- }
- delete[] sunImg; //< Nous avons terminé avec le soleil, on le libère
- // Maintenant chargeons une image de maison
- unsigned char* houseImg;
- try
- {
- houseImg = LoadImgFromFile("sun.png");
- if (!houseImg)
- {
- delete[] img;
- return nullptr;
- }
- }
- catch (const std::exception& e)
- {
- delete[] img;
- throw;
- }
- try
- {
- if (!BlitImage(img, houseImg, 300, 2000))
- {
- delete[] houseImg;
- delete[] img;
- return nullptr;
- }
- }
- catch (const std::exception& e)
- {
- delete[] houseImg;
- delete[] img;
- return nullptr;
- }
- delete[] houseImg; //< Nous avons fini avec la maison, on la libère
- // Autres opération similaires (dessin de nuages, colline, etc.)
- return img;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement