![]() |
|
Why is this not drawing? |
EternalGames
Member #14,603
October 2012
|
Hello, first time poster here. 1void State_Mainmenu::Render()
2{
3 if(render){
4 render = false;
5 al_draw_bitmap(bg,0,0,0); // This does nothing
6
7
8 for(int i = 0; i< buttons.size(); i++)
9 {
10 buttons.at(i)->Render(); //This works
11 }
12 al_flip_display();
13 al_clear_to_color(al_map_rgb(0,0,0));
14 }
15}
16
17void GUI_Button::Render()
18{
19 if(!pressed){al_draw_bitmap(unclickedTexture,x_Pos,y_Pos,0);}
20 else{al_draw_bitmap(clickedTexture,x_Pos,y_Pos,0);}
21 if(text.size()!= 0)
22 {al_draw_text(font,al_map_rgb(0,0,0),x_Pos+width/2,y_Pos+height/2-al_get_font_line_height(font)/2,ALLEGRO_ALIGN_CENTRE,text.c_str());}
23}
Like I said. This is basically two times the same thing (calling al_draw_bitmap), not changing anything in between whatsoever. I'd really appreciate it, if someone could help me out on this one.
|
someone972
Member #7,719
August 2006
![]() |
You are sure that the image loaded properly and that it actually has image data saved in it right? Other than that I don't see anything wrong with this code here, so it might be somewhere else. ______________________________________ |
Kris Asick
Member #1,424
July 2001
|
Make sure all of your calls to al_create_bitmap() and al_load_bitmap() aren't returning NULL. If they do, then they have failed, likely due to an incorrect filename, invalid bitmap sizes, or other such things. --- Kris Asick (Gemini) |
weapon_S
Member #7,859
October 2006
![]() |
1. What they said. |
EternalGames
Member #14,603
October 2012
|
Kris Asick said: Make sure all of your calls to al_create_bitmap() and al_load_bitmap() aren't returning NULL. If they do, then they have failed, likely due to an incorrect filename, invalid bitmap sizes, or other such things. I did the following: if(al_load_bitmap("Stoffmalerei.png")) { bg = al_load_bitmap("Stoffmalerei.png"); } else { al_show_native_message_box(al_get_current_display(),"Error","Function","al_load_bitmap failed","aye",0); } it does not show the message box, so I guess I'm loading it right. weapon_S said: So when you comment out the button rendering, you see nothing? Yes, I only see black, when I comment out the button code.:-X
|
J-Gamer
Member #12,491
January 2011
![]() |
That's a memory leak right there... bg = al_load_bitmap("Stoffmalerei.png"); if(!bg) { al_show_native_message_box(al_get_current_display(),"Error","Function","al_load_bitmap failed","aye",0); }
" There are plenty of wonderful ideas in The Bible, but God isn't one of them." - Derezo |
weapon_S
Member #7,859
October 2006
![]() |
Technically you haven't checked bg yet bg = al_load_bitmap("Stoffmalerei.png"); if(! bg) al_show_native_message_box(al_get_current_display(), "Error", "Function", "al_load_bitmap failed", "aye" ,0); }
|
EternalGames
Member #14,603
October 2012
|
Well I thought that checking the return value of al_load_bitmap was supposed to work like that, because I can't do Thanks for reminding me of the memory leak, though.
|
weapon_S
Member #7,859
October 2006
![]() |
Yes, you can |
EternalGames
Member #14,603
October 2012
|
Haha, well I found my mistake and it made me laugh hard. I'm facepalming so hard right now.
|
Kris Asick
Member #1,424
July 2001
|
You still need to make sure you're not leaking memory. When you call al_load_bitmap(), you load a bitmap into video memory. So every single time you call this function, you absolutely MUST place the result into an empty pointer. If you don't: 1. The memory will be wasted and future calls to al_load_bitmap() may fail if memory is exhausted. 2. If the pointer you load to already has a bitmap in it, you'll lose access to that bitmap, again leaking memory and potentially running out if you keep doing this. Remember, a "pointer" simply points to an object in memory, it isn't itself the actual memory being used. If you forget the contents of a pointer, or fail to store one that's created, then the memory it points to will be inaccessible by ANYTHING for the duration of your application, and if you do this enough times, you will eventually have no memory left. --- Kris Asick (Gemini) |
|