Allegro.cc - Online Community

Allegro.cc Forums » Game Design & Concepts » al_draw_prim()

This thread is locked; no one can reply to it. rss feed Print
al_draw_prim()
AleX-G Squadron
Member #13,593
October 2011
avatar

Hi!
I was having difficulty in understanding al_draw_prim() as it seems more complex than the other al_draw functions. Can anyone show an example or how to make it work?
Here is the page
http://www.allegro.cc/manual/5/al_draw_prim

www.anothergames.com

Edgar Reynaldo
Member #8,592
May 2007
avatar

AleX-G Squadron
Member #13,593
October 2011
avatar

I understood the last parameter, but i dont understand other parameters.

int al_draw_prim(const void* vtxs, const ALLEGRO_VERTEX_DECL* decl,
ALLEGRO_BITMAP* texture, int start, int end, int type)

Is says:
For example to draw a textured triangle you could use:

#SelectExpand
1ALLEGRO_VERTEX v[] = { 2 {.x = 128, .y = 0, .z = 0, .u = 128, .v = 0}, 3 {.x = 0, .y = 256, .z = 0, .u = 0, .v = 256}, 4 {.x = 256, .y = 256, .z = 0, .u = 256, .v = 256}}; 5al_draw_prim(v, NULL, texture, 0, 3, ALLEGRO_PRIM_TRIANGLE_LIST);

I copy pasted the code and it doesnt explain anything.
Not mentioning that all variables get red on visual studio + you get a bonus package of that "texture" variable put in.
I get it to work using these values after modified a little and i get a black screen

#SelectExpand
1ALLEGRO_VERTEX v[] = { 2 {128, 0, 0, 128, 0}, 3 {0, 256, 0, 0, 256}, 4 {256, 256, 0, 256, 256}}; 5 6 al_draw_prim(v, NULL, 0, 0, 3, ALLEGRO_PRIM_TRIANGLE_LIST);

www.anothergames.com

Trent Gamblin
Member #261
April 2000
avatar

Click ALLEGRO_VERTEX in that code listing and it'll show you that there is another parameter, color. So That code probably shouldn't have compiled in MSVC. I usually just set them like this:

v = 0;
verts[v].x = some_x; // same for y, z = 0
verts[v].u = some_u; // same for v
verts[v].color = some_ALLEGRO_COLOR;
v++;
// next vertex

Color is important for texturing too. If you want the texture to show up without tinting, use pure white.

alehbeer
Member #12,996
July 2011
avatar

const ALLEGRO_VERTEX_DECL* decl
Out of curiosity, when would you ever not set this (parameter 2) to NULL?

Color is important for texturing too. If you want the texture to show up without tinting, use pure white.

Talking about colour, what is meant by 'multiply by colour' as the new way of dealing with colour manipulation? I have seen this stated a couple of times on the forum, although I would have to go find a link to an example if one was needed. Does this apply for the al_draw_prim function too?

I'm not sure, but this should probably be in 'Programming Questions' rather than 'Game Design & Concepts'.

EDIT:
Here is an example:

#SelectExpand
2ALLEGRO_COLOR color = al_map_rgba_f(1.0*alpha, 0.4*alpha, 0.6*alpha, alpha); // <-- correct 3//ALLEGRO_COLOR color = al_map_rgba_f(1.0, 0.4, 0.6, alpha); // <--no longer correct

Trent Gamblin
Member #261
April 2000
avatar

texels will be multiplied by the tint (in al_draw_tinted_*_bitmap) and color (in al_draw_prim).

If you have a RGB value of (0.5, 1.0, 0.25) in the texture...

Multiply by white: (0.5*1, 1.0*1, 0.25*1) it doesn't change.

If you wanted to make it half the brightness, multiply by a shade of gray (0.5, 0.5, 0.5):

(0.5*0.5, 1.0*0.5, 0.25*0.5) and you get (0.25, 0.5, 0.125) which is half as bright as the original texture color.

You could also filter out all color components but red, as another example:

(0.5*1, 1.0*0, 0.25*0) = (0.5, 0, 0) only the red color remains. And so on for any color you choose, in any proportion.

EDIT: Your example just shows the way alpha blending is done. Allegro uses premultipled alpha by default, which has the blender set like so:

al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);

All it means is the color components should be pre-multiplied by the alpha value before drawing, which you can see is what's done in your example.

What may seem more familiar (but has problems, see the manual) is this blend mode:

al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);

With that mode you'd use the comment out line in your example instead.

alehbeer
Member #12,996
July 2011
avatar

Trent Gamblin, you're the man. I can see some cool stuff to do with that 'multiply by colour'! I'm off to make 3D glasses out of paper and plastic...

AleX-G Squadron
Member #13,593
October 2011
avatar

I still cannot get it to work, i dont know why.
Can you make a full example which works if executed with the prim?

www.anothergames.com

alehbeer
Member #12,996
July 2011
avatar

check out ex_prim.c

Go to: