|
Failed to get bitmap font with alx wrapper for Allegro 5 |
Ojars_L
Member #15,861
January 2015
|
Hi! 1void Game::load_fonts()
2{
3 //ALLEGRO_BITMAP *temp;
4 //const int ranges[] = { 32, 126 };
5
6 ////normalfont
7 //temp = al_load_bitmap("Media/Fonts/ex06.pcx");
8 //al_convert_mask_to_alpha(temp, al_map_rgb(255, 0, 255));
9 //normalfont = al_grab_font_from_bitmap(temp, 1, ranges);
10
11 ////titlefont
12 //temp = al_load_bitmap("Media/Fonts/TITLE_FONT.pcx");
13 //al_convert_mask_to_alpha(temp, al_map_rgb(0, 0, 0));
14 //titlefont = al_grab_font_from_bitmap(temp, 1, ranges);
15
16 alx::Bitmap temp;
17 std::vector<std::tuple<int, int>> ranges;
18 ranges.push_back(std::make_tuple(32, 126));
19
20 //normalfont
21 temp.load("Media/Fonts/ex06.pcx");
22 temp.convertMaskToAlpha(alx::Color(0xFF00FFFF));
23 normalfont.grab(temp, ranges);
24
25 //titlefont
26 temp.load("Media/Fonts/TITLE_FONT.pcx");
27 temp.convertMaskToAlpha(alx::Color(0));
28 titlefont.grab(temp, ranges);
29}
A grabber function from Font.hpp (namespace alx) 1 /**
2 Creates a font from a bitmap.
3 @param bmp bitmap.
4 @param ranges ranges.
5 @return true on success.
6 */
7 bool grab(const Bitmap &bmp, const std::vector<std::tuple<int, int>> &ranges) {
8 std::vector<int> rangeBuffer;
9 for(auto t : ranges) {
10 rangeBuffer.push_back(std::get<0>(t));
11 rangeBuffer.push_back(std::get<1>(t));
12 }
13 reset(al_grab_font_from_bitmap(bmp.get(), rangeBuffer.size(), rangeBuffer.data()), al_destroy_font);
14 return (bool)(*this);
15 }
I tried to debugger the code and all works until debugger brakes when returning from this function in a <memory>file 1_Ty *get() const _NOEXCEPT
2 { // return pointer to resource
3 return (this->_Get());
4 }
It mean that there is not a resource from what return a pointer. Temp file is loaded correctly with a pointer to it. |
SiegeLord
Member #7,827
October 2006
|
This line is wrong: reset(al_grab_font_from_bitmap(bmp.get(), rangeBuffer.size(), rangeBuffer.data()), al_destroy_font); It should be ranges.size() rather than rangeBuffer.size(). "For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18 |
Ojars_L
Member #15,861
January 2015
|
Thank you. Now it works. |
|