Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Texture on ALLEGRO_VERTEX

This thread is locked; no one can reply to it. rss feed Print
Texture on ALLEGRO_VERTEX
SaintBass
Member #16,076
September 2015
avatar

Hi guys!!! I`m using ALLEGRO_VERTEX but i can`t understand how the texture`s work, the u and v attributes are in pixels, but ┬┐How can i draw a complete image?.
In my code i have this rectangle:

ALLEGRO_VERTEX v[4] = {
{150,50,0,0,0,al_map_rgb(255,255,255)},
{300,50,0,0,0,al_map_rgb(255,255,255)},
{150,200,0,0,0,al_map_rgb(255,255,255)},
{300,200,0,0,0,al_map_rgb(255,255,255)},
}

and draw this:

al_draw_prim(v, NULL, texture, 0, 4, 4);

Edgar Reynaldo
Member #8,592
May 2007
avatar

al_draw_prim

I swapped your 3rd and 4th vertices so that it draws triangles with vertices 0,1,2 and 0,2,3. You also need to adjust your u,v coordinates to match the bitmap's corners.

int w = al_get_bitmap_width(bmp);
int h = al_get_bitmap_height(bmp);
ALLEGRO_VERTEX v[4] = {
{150,50 ,0,0,0,al_map_rgb(255,255,255)},
{300,50 ,0,w,0,al_map_rgb(255,255,255)},
{300,200,0,w,h,al_map_rgb(255,255,255)},
{150,200,0,0,h,al_map_rgb(255,255,255)}
};

al_draw_prim(v, NULL, texture, 0, 4, ALLEGRO_PRIM_TRIANGLE_FAN);

SaintBass
Member #16,076
September 2015
avatar

Thanks for your help!!!
it works perfectly :D

Go to: