al_draw_line failure
ponyman

Hi everyone, it's my first post here.

#SelectExpand
1for(int i = 0; i<(n-1); i++) 2{ 3 for(int j = (i+1); j<n; j++) 4 { 5 al_draw_line(pX[i], pY[i], pX[j], pY[j], red, 2); 6 file<<"Line between "<<pX[i]<<" "<<pY[i]<<" and "<<pX[j]<<" "<<pY[j]<< endl; 7 } 8}

The code above is supposed to draw lines between points "i" and "j" described by coordinates stored in "float" type vectors, f.e. pX[1] and pY[1] are coordinates of "Point 2".

Problem is, lines are not drawn, and I don't know, why. As a part of crude debugging, notifications of supposed drawings are saved in .txt file in pattern shown below. In result, I get properly filled file:

#SelectExpand
2Line between 417.815 260.791 and 411.355 280.674 3Line between 417.815 260.791 and 400.902 298.778 4Line between 417.815 260.791 and 386.913 314.314 5Line between 417.815 260.791 and 370 326.602 6Line between 417.815 260.791 and 350.902 335.106 7Line between 417.815 260.791 and 330.453 339.452 8and so on...

which means numerical input is all right. I get no errors nor warnings. It's not the first time this function is acting weird - not drawing when code seems to be all-OK. There's an possibility that I'm missing something little yet essential about the usage of this function, but right now, I'm clueless.
Ideas, anyone?

Full listing of fuction using this code : http://pastebin.com/JvsGVrTM

Arthur Kalliokoski

Did you initialize primitives? Also try substituting al_map_rgb_f(1.0,0.0,0.0) for red.

ponyman

@Arthur - I've changed the drawing colour with your suggestion and it works! ;D
"red" was defined like this
ALLEGRO_COLOR red = al_map_rgb(255,0,0);
outside the functions in the file (as a file-global variable) and it worked in other functions, yet it failed here.
Care to explain, what is the difference in this case?
I would be really helpful for me, just to avoid mistakes like this one in the future. This one gave a lot of stress.

Arthur Kalliokoski

You can't call functions such as al_map_rgb() outside of main() or another function, I'd guess it loaded "red" with the address of al_map_rgb(). Try to find out how to increase the error reporting of your compiler.

ponyman

Good old DevC++ does not report this as an error. Well, I'll be wiser now.
Thanks a lot! :)

Arthur Kalliokoski
ponyman said:

Good old DevC++

IIRC, DevC++ uses MinGW and the gcc compiler, right? You can turn up the errors and warnings with

-O2 -Wall -Wextra

in the compiler options (whereever those are).

ponyman

You're right, I'll try it.

Thomas Fjellstrom

You can't call functions such as al_map_rgb() outside of main() or another function, I'd guess it loaded "red" with the address of al_map_rgb(). Try to find out how to increase the error reporting of your compiler.

Calling functions outside of main like that is valid in C++.

However, it is not normally valid to call allegro functions before you've called al_init or after al_uninstall_system has been called. Many also don't like it if there isn't a current display or target bitmap. It's something that is easy to trip up on when using C++ "as normal".

Thread #611460. Printed from Allegro.cc