Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » ALLEGRO 5.2, ERROR TO LOAD IMAGE!

This thread is locked; no one can reply to it. rss feed Print
ALLEGRO 5.2, ERROR TO LOAD IMAGE!
Jefferson Silva de Almeida
Member #15,764
October 2014

Good evening, please help me?
Giving error loading the image PUSHSTART

**the code is missing the indentation here, but in my code: blocks is ok!**

#SelectExpand
1 bmp = al_load_bitmap("images/pushstart.jpg"); 2 if(!bmp) { 3 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO CARREGAR IMAGEM PUSHSTART!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 4 return 0; 5 }

ALL CODE

#SelectExpand
1#include "MyMenu.h" 2#include <allegro5/allegro.h> 3#include <allegro5/allegro_font.h> 4#include <allegro5/allegro_image.h> 5#include <allegro5/allegro_ttf.h> 6#include <allegro5/allegro_primitives.h> 7#include "allegro5/allegro_native_dialog.h" 8#include <stdio.h> 9 10 11 12enum GameState { 13 PRESSKEY, 14 SHOWSTART, 15 STARTNEWGAME, 16 LOADGAME, 17 QUESTMODE 18}; 19 20class Flasher { 21private: 22 ALLEGRO_BITMAP* bmp; 23 float x, y; 24 double time_visible; 25 double time; 26 bool visible; 27public: 28 Flasher(ALLEGRO_BITMAP* bitmap, float xpos, float ypos, float flash_time) : 29 bmp(bitmap), 30 x(xpos), 31 y(ypos), 32 time_visible(flash_time), 33 time(0.0), 34 visible(true) 35 {} 36 void Update(double tsec) { 37 time += tsec; 38 while (time > time_visible) { 39 time -= time_visible; 40 visible = !visible; 41 } 42 } 43 void Draw() { 44 if (visible) { 45 al_draw_bitmap(bmp, x, y, 0); 46 } 47 } 48}; 49 50class Game { 51private: 52 Flasher* flasher; 53 GameState state; 54 55/*APLICANDO CADA ESTADO DO MENU*/ 56 void DrawPressKey() { 57 ALLEGRO_BITMAP* logo, *creditos; 58 al_clear_to_color(al_map_rgb(0, 0, 0)); 59 logo = al_load_bitmap("images/logo.png"); 60 creditos = al_load_bitmap("images/creditos.jpg"); 61 al_draw_bitmap(logo, 150, 150, 0); 62 al_draw_bitmap(creditos, 120, 451, 0); 63 flasher->Draw(); 64 al_flip_display(); 65 } 66 void DrawShowStart() {} 67 void DrawStartNewGame() {} 68 void DrawLoadGame() {} 69 void DrawQuestMode() {} 70 71/*ENTRADA DE ESTADOS */ 72 void CheckPressKeyInput(ALLEGRO_EVENT& ev) { 73 if (ev.type == ALLEGRO_EVENT_TIMER) { 74 flasher->Update(1.0/FPS); 75 76 } else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 77 if (ev.keyboard.keycode == ALLEGRO_KEY_ENTER) 78 state = SHOWSTART; 79 } 80 } 81 void CheckShowStartInput(ALLEGRO_EVENT& ev) {} 82 void CheckStartNewGameInput(ALLEGRO_EVENT& ev) {} 83 void CheckLoadGameInput(ALLEGRO_EVENT& ev) {} 84 void CheckQuestModeInput(ALLEGRO_EVENT& ev) {} 85 86 public: 87 bool redraw; 88 bool quit; 89 90 Game() : flasher(0), state(PRESSKEY), redraw(true), quit(false) {} 91 92 void SetFlasher(Flasher* f) { flasher = f; } 93 94 void Draw() { 95 switch (state) { 96 case PRESSKEY: 97 DrawPressKey(); 98 break; 99 case SHOWSTART: 100 DrawShowStart(); 101 break; 102 case STARTNEWGAME: 103 DrawStartNewGame(); 104 break; 105 case LOADGAME: 106 DrawLoadGame(); 107 break; 108 case QUESTMODE: 109 DrawQuestMode(); 110 break; 111 } 112 } 113 114 void CheckInput(ALLEGRO_EVENT& ev) { 115 switch (state) { 116 case PRESSKEY: 117 CheckPressKeyInput(ev); 118 break; 119 case SHOWSTART: 120 CheckShowStartInput(ev); 121 break; 122 case STARTNEWGAME: 123 CheckStartNewGameInput(ev); 124 break; 125 case LOADGAME: 126 CheckLoadGameInput(ev); 127 break; 128 case QUESTMODE: 129 CheckQuestModeInput(ev); 130 break; 131 } 132 if (ev.type == ALLEGRO_EVENT_TIMER) { 133 redraw = true; 134 } 135 else if (ev.type == ALLEGRO_EVENT_KEY_DOWN) { 136 if (ev.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { 137 quit = true; 138 } 139 } 140 else if (ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 141 quit = true; 142 } 143 } 144}; 145 146int main() { 147 ALLEGRO_DISPLAY * display; 148 ALLEGRO_BITMAP * bmp; 149 ALLEGRO_EVENT_QUEUE * event_queue; 150 ALLEGRO_TIMER * timer; 151 if(!al_init()) { 152 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO INICIAR ALLEGRO!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 153 return 0; 154 } 155 if(!al_init_primitives_addon()) { 156 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO INICIAR ADDON!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 157 return 0; 158 } 159 if(!al_install_mouse()) { 160 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO INICIAR MOUSE!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 161 return 0; 162 } 163 if(!al_install_keyboard()) { 164 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO INICIAR TECLADO!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 165 return 0; 166 } 167 timer = al_create_timer(1.0 / FPS); 168 if(!timer) { 169 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO CRIAR TIMER!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 170 return 0; 171 } 172 display = al_create_display(SCREEN_W, SCREEN_H); 173 if(!display) { 174 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO CRIAR DISPLAY!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 175 return 0; 176 } 177 event_queue = al_create_event_queue(); 178 if(!event_queue) { 179 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO CRIAR EVENTOS!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 180 return 0; 181 } 182 bmp = al_load_bitmap("images/pushstart.jpg"); 183 if(!bmp) { 184 al_show_native_message_box(display, "ERRO", "ERRO", "FALHA AO CARREGAR IMAGEM PUSHSTART!", NULL, ALLEGRO_MESSAGEBOX_ERROR); 185 return 0; 186 } 187 188 Flasher myflasher(bmp, 200, 200, 0.5); 189 Game game; 190 game.SetFlasher(&myflasher); 191 192 while (!game.quit) { 193 if (game.redraw) { 194 game.Draw(); 195 } 196 while (!game.quit) { 197 ALLEGRO_EVENT ev; 198 al_wait_for_event(event_queue, &ev); 199 game.CheckInput(ev); 200 if (al_is_event_queue_empty(event_queue)) { break; } 201 } 202 } 203 204 return 0; 205}

Edgar Reynaldo
Member #8,592
May 2007
avatar

Jefferson Silva de Almeida
Member #15,764
October 2014

Thank you Edgar!

Really, I add al_init_image_addon and fix the extension to jpeg.

Go to: