Hi All,
Without being a completely random person asking a random question please allow me to introduce myself. My name is scorliss and I am new member to the Allegro.cc community. I am currently working towards my Game Development Certification.
I am in the process of making a Missile Defense game and I have learnt quite a bit from all of you and your previous posts.
I am currently creating the game in Allegro 5 and the source code that I am porting contains a call to do_line.
So reprogramming this call I am now just drawing a line on the display instead of a line being draw segment by segment.
The issue that I am having is that al_draw_soft_line has no examples and I am unsure how and why to use the state parameter for this function. Can someone please point me to or show me how to use this.
Thanks and again,
Scorliss
"see the implementation of the various shading routines in addons/primitives/line_soft.c"
Hi,
what exactly are you trying to achieve? I must admit I don't remember Missile Defense clearly. Do you want to track the position for collision detection? What is points[totalpoints]?
Maybe you could do it with simple (floating point) 2D vectors instead of tracking pixels in software as you seem to do?
Hi scorliss!
When you call al_draw_soft_line you pass in three functions, first, step and draw. Allegro will call your functions:
first(...); // Just once step(...); draw(...); step(...); draw(...); ... // for every point on the line
So to do the equivalent your code you need something like:
ALLEGRO_VERTEX v1; ALLEGRO_VERTEX v2; v1.x = x1; v1.y = y1; v2.x = x2; v2.y = y2; al_draw_soft_line(&v1, &v2, NULL, NULL, NULL, doline);
with
void doline(uintptr_t pv, int x, int y) { (void) pv; //line callback function...fills the points array points[totalpoints].x = x; points[totalpoints].y = y; totalpoints++; }
For your example you don't need state so it's null. In other cases it's useful to have some extra data that gets passed along to each function in turn. This is quite a common pattern for callbacks; it helps to avoid global variables.
Bogus example using state:
(typed in by hand so may have mistakes!!)