
static void DrawLine(CglCanvas *pcan,const int x1,const int y1,const int x2,const int y2,const u16 col)
{
  if((x1==x2)&&(y1==y2)) return;
  
  u16 *pbuf=pcan->GetVRAMBuf();
#define SetPixel(x,y) pbuf[(x)+(y)*ScreenWidth]=col;
  
  if(x1==x2){
    int ys,ye;
    if(y1<y2){
      ys=y1;
      ye=y2-1;
      }else{
      ys=y2+1;
      ye=y1;
    }
    for(int py=ys;py<=ye;py++){
      SetPixel(x1,py);
    }
    return;
  }
  
  if(y1==y2){
    int xs,xe;
    if(x1<x2){
      xs=x1;
      xe=x2-1;
      }else{
      xs=x2+1;
      xe=x1;
    }
    for(int px=xs;px<=xe;px++){
      SetPixel(px,y1);
    }
    return;
  }
  
  if(abs(x2-x1)>abs(y2-y1)){
    int px=0;
    float py=0;
    int xe=x2-x1;
    float ye=y2-y1;
    int xv;
    float yv;
    
    if(0<xe){
      xv=1;
      }else{
      xv=-1;
    }
    yv=ye/abs(xe);
    
    while(px!=xe){
      SetPixel(x1+px,y1+(int)py);
      px+=xv;
      py+=yv;
    }
    return;
    
    }else{
    float px=0;
    int py=0;
    float xe=x2-x1;
    int ye=y2-y1;
    float xv;
    int yv;
    
    xv=xe/abs(ye);
    if(0<ye){
      yv=1;
      }else{
      yv=-1;
    }
    
    while(py!=ye){
      SetPixel(x1+(int)px,y1+py);
      px+=xv;
      py+=yv;
    }
    return;
  }

#undef SetPixel
}

