let newtextcolor=[255,255,255,255,255,255];

function SetFontColorNew(r1,g1,b1,r2,g2,b2){
//RGB for top, then RGB for bottom
   newtextcolor=[r1,g1,b1,r2,g2,b2];
}

function DrawTextNew(string,x,y,angle,xsize,ysize,layer,alpha){
//string: the string to write
//font: what image file to use
//x,y,angle: obvious
//size: default 1, multiplies the size by that amount
//layer: what layer to draw it on
//align: 1 is left-justified, -1 is right-justified, 0 is centered
//align currently does not work
//alpha: obvious

   let obj = Obj_Create(OBJ_EFFECT);
   let ii=0;
   let midx=0;
   let miny=0;
   let string2=[];

   Obj_SetPosition(obj,x,y-8);
   ObjEffect_SetAngle(obj, 0,0,angle);
   ObjEffect_SetTexture(obj,GetCurrentScriptDirectory ~ "lib\DrawTextNew\text.png");
   ObjEffect_SetPrimitiveType(obj,PRIMITIVE_TRIANGLESTRIP);
   ObjEffect_SetLayer(obj,layer);
   ObjEffect_CreateVertex(obj,length(string)*6);
   ObjEffect_SetRenderState(obj,ALPHA);
   ObjEffect_SetScale(obj,xsize,ysize);

   let rect=[];
   let CharSpace = 0;
   let LastCharSpace = 0;
   ascent(ii in 0..length(string)){
      rect=ToArray(string[ii]);
      midx+= LastCharSpace/2+CharSpace/2;
   
      ObjEffect_SetVertexXY(obj,(ii*6)  ,midx,0);
      ObjEffect_SetVertexXY(obj,(ii*6)+1,midx,0);
      ObjEffect_SetVertexXY(obj,(ii*6)+2,midx+14,0);
      ObjEffect_SetVertexXY(obj,(ii*6)+3,midx,14);
      ObjEffect_SetVertexXY(obj,(ii*6)+4,midx+14,14);
      ObjEffect_SetVertexXY(obj,(ii*6)+5,midx+14,14);
   
      ObjEffect_SetVertexUV(obj,(ii*6)  ,rect[0],rect[1]);
      ObjEffect_SetVertexUV(obj,(ii*6)+1,rect[0],rect[1]);
      ObjEffect_SetVertexUV(obj,(ii*6)+2,rect[2],rect[1]);
      ObjEffect_SetVertexUV(obj,(ii*6)+3,rect[0],rect[3]);
      ObjEffect_SetVertexUV(obj,(ii*6)+4,rect[2],rect[3]);
      ObjEffect_SetVertexUV(obj,(ii*6)+5,rect[2],rect[3]);

      ObjEffect_SetVertexColor(obj,(ii*6)  ,alpha,newtextcolor[0],newtextcolor[1],newtextcolor[2]);
      ObjEffect_SetVertexColor(obj,(ii*6)+1,alpha,newtextcolor[0],newtextcolor[1],newtextcolor[2]);
      ObjEffect_SetVertexColor(obj,(ii*6)+2,alpha,newtextcolor[0],newtextcolor[1],newtextcolor[2]);
      ObjEffect_SetVertexColor(obj,(ii*6)+3,alpha,newtextcolor[3],newtextcolor[4],newtextcolor[5]);
      ObjEffect_SetVertexColor(obj,(ii*6)+4,alpha,newtextcolor[3],newtextcolor[4],newtextcolor[5]);
      ObjEffect_SetVertexColor(obj,(ii*6)+5,alpha,newtextcolor[3],newtextcolor[4],newtextcolor[5]);
      
      LastCharSpace = CharSpace;
    }
    return obj;
   
   

   function ToArray(character){
      let ret=[0, 0, 14, 14];
      alternative(character)
         case('!'){ret=[14,0,28,14];CharSpace=8;}
         case('\'){ret=[28,0,42,14];CharSpace=10;}
         case('#'){ret=[42,0,56,14];CharSpace=10;}
         case('$'){ret=[56,0,70,14];CharSpace=10;}
         case('%'){ret=[70,0,84,14];CharSpace=12;}
         case('&'){ret=[84,0,98,14];CharSpace=12;}
         case('/'){ret=[98,0,112,14];CharSpace=10;}
         case('('){ret=[112,0,126,14];CharSpace=10;}
         case(')'){ret=[126,0,140,14];CharSpace=10;}
         case('*'){ret=[140,0,154,14];CharSpace=8;}
         case('+'){ret=[154,0,168,14];CharSpace=10;}
         case(','){ret=[168,0,182,14];CharSpace=10;}
         case('-'){ret=[182,0,196,14];CharSpace=10;}
         case('.'){ret=[196,0,210,14];CharSpace=10;}
         case('0'){ret=[224,0,238,14];CharSpace=10;}
         case('1'){ret=[238,0,252,14];CharSpace=10;}
         case('2'){ret=[0,14,14,28];CharSpace=10;}
         case('3'){ret=[14,14,28,28];CharSpace=10;}
         case('4'){ret=[28,14,42,28];CharSpace=10;}
         case('5'){ret=[42,14,56,28];CharSpace=10;}
         case('6'){ret=[56,14,70,28];CharSpace=10;}
         case('7'){ret=[70,14,84,28];CharSpace=10;}
         case('8'){ret=[84,14,98,28];CharSpace=10;}
         case('9'){ret=[98,14,112,28];CharSpace=10;}
         case(':'){ret=[112,14,126,28];CharSpace=8;}
         case(';'){ret=[126,14,140,28];CharSpace=8;}
         case('<'){ret=[140,14,154,28];CharSpace=10;}
         case('='){ret=[154,14,168,28];CharSpace=10;}
         case('>'){ret=[168,14,182,28];CharSpace=10;}
         case('?'){ret=[182,14,196,28];CharSpace=10;}
         case('@'){ret=[196,14,210,28];CharSpace=12;}
         case('A'){ret=[210,14,224,28];CharSpace=10;}
         case('B'){ret=[224,14,238,28];CharSpace=10;}
         case('C'){ret=[238,14,252,28];CharSpace=10;}
         case('D'){ret=[0,28,14,42];CharSpace=10;}
         case('E'){ret=[14,28,28,42];CharSpace=12;}
         case('F'){ret=[28,28,42,42];CharSpace=10;}
         case('G'){ret=[42,28,56,42];CharSpace=10;}
         case('H'){ret=[56,28,70,42];CharSpace=12;}
         case('I'){ret=[70,28,84,42];CharSpace=8;}
         case('J'){ret=[84,28,98,42];CharSpace=8;}
         case('K'){ret=[98,28,112,42];CharSpace=12;}
         case('L'){ret=[112,28,126,42];CharSpace=10;}
         case('M'){ret=[126,28,140,42];CharSpace=12;}
         case('N'){ret=[140,28,154,42];CharSpace=10;}
         case('O'){ret=[154,28,168,42];CharSpace=10;}
         case('P'){ret=[168,28,182,42];CharSpace=10;}
         case('Q'){ret=[182,28,196,42];CharSpace=12;}
         case('R'){ret=[196,28,210,42];CharSpace=10;}
         case('S'){ret=[210,28,224,42];CharSpace=10;}
         case('T'){ret=[224,28,238,42];CharSpace=10;}
         case('U'){ret=[238,28,252,42];CharSpace=10;}
         case('V'){ret=[0,42,14,56];CharSpace=10;}
         case('W'){ret=[14,42,28,56];CharSpace=12;}
         case('X'){ret=[28,42,42,56];CharSpace=10;}
         case('Y'){ret=[42,42,56,56];CharSpace=10;}
         case('Z'){ret=[56,42,70,56];CharSpace=10;}
         case('['){ret=[70,42,84,56];CharSpace=10;}
         case(']'){ret=[98,42,112,56];CharSpace=10;}
         case('^'){ret=[112,42,126,56];CharSpace=8;}
         case('_'){ret=[126,42,140,56];CharSpace=8;}
         case('a'){ret=[154,42,168,56];CharSpace=8;}
         case('b'){ret=[168,42,182,56];CharSpace=8;}
         case('c'){ret=[182,42,196,56];CharSpace=8;}
         case('d'){ret=[196,42,210,56];CharSpace=8;}
         case('e'){ret=[210,42,224,56];CharSpace=8;}
         case('f'){ret=[224,42,238,56];CharSpace=8;}
         case('g'){ret=[238,42,252,56];CharSpace=10;}
         case('h'){ret=[0,56,14,70];CharSpace=8;}
         case('i'){ret=[14,56,28,70];CharSpace=6;}
         case('j'){ret=[28,56,42,70];CharSpace=8;}
         case('k'){ret=[42,56,56,70];CharSpace=10;}
         case('l'){ret=[56,56,70,70];CharSpace=6;}
         case('m'){ret=[70,56,84,70];CharSpace=12;}
         case('n'){ret=[84,56,98,70];CharSpace=8;}
         case('o'){ret=[98,56,112,70];CharSpace=8;}
         case('p'){ret=[112,56,126,70];CharSpace=8;}
         case('q'){ret=[126,56,140,70];CharSpace=8;}
         case('r'){ret=[140,56,154,70];CharSpace=8;}
         case('s'){ret=[154,56,168,70];CharSpace=8;}
         case('t'){ret=[168,56,182,70];CharSpace=8;}
         case('u'){ret=[182,56,196,70];CharSpace=8;}
         case('v'){ret=[196,56,210,70];CharSpace=8;}
         case('w'){ret=[210,56,224,70];CharSpace=12;}
         case('x'){ret=[224,56,238,70];CharSpace=10;}
         case('y'){ret=[238,56,252,70];CharSpace=10;}
         case('z'){ret=[0,70,14,84];CharSpace=8;}
         case('{'){ret=[14,70,28,84];CharSpace=8;}
         case('|'){ret=[28,70,42,84];CharSpace=6;}
         case('}'){ret=[42,70,56,84];CharSpace=8;}
         case('~'){ret=[56,70,70,84];CharSpace=10;}
         others{CharSpace=8;}

      return ret;
   }
}