Allegro.cc Forums » Programming Questions » Coordinate systems

 Edgar Reynaldo Member #8,592 May 2007 In allegro the top left pixel is at 0,0 and the bottom right pixel is at width-1,height-1. However, the center of the top left pixel is at 0.5,0.5 and the center of the bottom right pixel is at width-0.5,height-0.5.This code actually fails to properly outline the display. I'll tell you why below. It's actually in the page I linked to as well. ``` ALLEGRO_DISPLAY* display = ((Allegro5GraphicsContext*)win)->AllegroDisplay(); float lx = 0.5; float rx = al_get_display_width(display) - 0.5; float ty = 0.5; float by = al_get_display_height(display) - 0.5; ALLEGRO_COLOR c = al_map_rgb(255,0,0); float t = 1.0; al_clear_to_color(al_map_rgb(255,255,255)); al_draw_line(lx,ty,rx,ty,c,t); al_draw_line(lx,by,rx,by,c,t); al_draw_line(lx,ty,lx,by,c,t); al_draw_line(rx,ty,rx,by,c,t); ``` {"name":"610315","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/c\/7cf67f3ab41dfdd7b68e59024b51cc32.png","w":800,"h":600,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/7\/c\/7cf67f3ab41dfdd7b68e59024b51cc32"}So you can see that the bottom right pixel is not lit. What you actually want to do when drawing axis aligned lines is to draw at the middle of the line along its width, and extend to the full width you desire along its length.So you can see the two lines on the bottom and the right both failed to draw the bottom right pixel. When drawing the horizontal line it should have been : ```al_draw_line(0.0 , al_get_display_height(display) - 0.5 , al_get_display_width(display) , al_get_display_height(display) - 0.5 , al_map_rgb(255,0,0) , 1.0); ``` And the vertical line should have been : ```al_draw_line(al_get_display_width(display)-0.5 , 0.0 , al_get_display_width(display)-0.5 , al_get_display_height(display) , al_map_rgb(255,0,0) , 1.0); ``` So the horizontal line is vertically centered around y = h - 0.5, and is drawn from x = 0 to x = w. And the vertical line is horizontally centered around x = w-0.5 and is drawn from y = 0 to y = h. You can see it in the blue line in the second image in the page I linked you to.{"name":"primitives2.png","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac1f802e04dfc4830bb169c64050a142.png","w":789,"h":426,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/a\/c\/ac1f802e04dfc4830bb169c64050a142"} Elizabeth Warren for President 2020! | Modern Allegro 4 and 5 binaries | Allegro 5 compile guideKing Piccolo will make it so