uniform vec4 lignePos[100]; //coords of the line to follow uniform int pointsCount; //how many points in the line uniform float zoom =1;//zoom factor uniform int horizontalOffset=0;//0 to start at the first point of the line, 100 to start at 100 pixels from the start uniform int verticalOffset = 10;//vertical offset in px uniform int charWidth = 20;//should be the average width of a letter in int gl_VertexID; void main() { bool notFound = true; float totalLineWidth = 0.0; //total length of the already float currentWidth = 0.0; //Idem moins le segment courant int i = 0; float invZoom = 1.0/zoom; vec4 origine = vec4(0.0, 0.0, 0.0, 0.0); mat4 total; vec4 my_vertex = gl_Vertex; bool finish = false; my_vertex.y = gl_Vertex.y+ 1 + charWidth * 0.5; float deltaVertexX = (gl_Vertex.x - origine.x); for (int i=0; notFound && i < pointsCount-1; i++) { float deltaY = invZoom*(lignePos[i+1].y - lignePos[i].y); float deltaX = invZoom*(lignePos[i+1].x - lignePos[i].x); float segmentLenght = sqrt(deltaY*deltaY+deltaX*deltaX); totalLineWidth += segmentLenght; if(i == (pointsCount -2)){finish = true;} ; if((deltaVertexX -charWidth < totalLineWidth) || finish){ //check if the current vertex has to be pinned to the current segment float sina = deltaY / segmentLenght; float cosa = deltaX / segmentLenght; mat4 retourChariot = mat4( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, -currentWidth, 0.0, 0.0, 1.0); mat4 rotation = mat4(cosa, -sina,0.0,0.0, sina, cosa,0.0,0.0, 0.0,0.0,1.0,0.0, 0.0,0.0,0.0,1.0); mat4 translation_segment_start = mat4( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, (lignePos[i].x -lignePos[0].x)*invZoom , (-lignePos[i].y +lignePos[0].y)*invZoom, 0.0, 1.0); mat4 translation_milieu = mat4( 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0) ; total = gl_ModelViewProjectionMatrix * translation_segment_start*rotation*retourChariot; gl_Position = total*my_vertex ; notFound = false; } else { currentWidth=totalLineWidth; } } if (notFound) { gl_Position = total*my_vertex ; } gl_TexCoord[0] = gl_TextureMatrix[0] * gl_MultiTexCoord0; }