0

I'm quite new on SharpGL (OpenGl) and I'm trying to draw some squares and add some text inside. I use the code below.

The Problem is, gl.DrawText3D method translates by itself according to text lenght. When I wanted to add a new line that starts from the left edge of square, the second line's start point doesn't match with the first line.

What I am looking for is:

1) if there is way of preventing DrawText3d method to translate

or

2) to find how much it's translated by this method.

    public void addPlc(PLCTreeNode plc,int level)
    {
        OpenGL gl = openGLControl.OpenGL;

        gl.Translate(plc.level * 6, -6, 0);
        gl.PushMatrix();
        setColor(plc.plcColor);
        drawSquare();
        if (!isFirt)
        {
            setColor(plc.LineColor); 
                drawLine(-3, 4 + level * 6, -3, 2, 12);  
        }

        isFirt = false; 
        gl.Translate(-3.9, 1, 0);
        setColor(0);
      //  Where text is written. 
        gl.DrawText3D("Arial", 25, 2, 0.1f, plc.plcId + " - " + plc.slaveCount+"\n"+plc.lastInfoTime.ToString("s").Replace('T', ' ')); 

        //translate assumpstion is 7.0f but it is not always 
        gl.Translate(-7, -1, 0);
        // setColor(0);
        gl.DrawText3D("Arial", 25, 2, 0.1f, plc.lastInfoTime.ToString("s").Replace('T', ' '));
        gl.PopMatrix();
        gl.Translate(plc.level * -6, 0, 0);
Barbaros
  • 13
  • 9
  • It might be center-aligned instead of left-aligned – Drew McGowen Sep 25 '14 at 13:46
  • if there isn't a method that centerize the text, I still have to know how long is the text. If there is such method to centerize the text, do you know what is it? – Barbaros Sep 25 '14 at 13:50
  • If you enclose your gl.DrawText3D calls in their separate gl.PushMatrix() and gl.PopMartix() there should be no transformation change between them. If you remove your gl.Translate calls, you should *in theory* have the texts overlapping – Thanasis Kapelonis Dec 14 '15 at 12:27

0 Answers0