views:

1040

answers:

2

Hey, This is my scenario: Using visual studio 2008. Project is in c# Using Tao framework along with ISE.FreeType to render text. The font is already loaded and converted to texture bitmap:

//Creamos la fuente
            fuenteActual = new FTFont(fuentes.FontMap[fuente], out ultimoError);
            //Convierte la fuente a textura. Estos valores se usan en el ejemplo, creo que tiene que ver con la calidad/eficiencia.
            fuenteActual.ftRenderToTexture(64, 96);
            //Ponemos la alineacion por defecto como centrada.
            fuenteActual.FT_ALIGN = FTFontAlign.FT_ALIGN_CENTERED;

To get straight to the point, this is my code to render some text.

    Gl.glLoadIdentity();
    float tamaño = texto.Tamaño;
    double tan = texto.Orientacion.Y / texto.Orientacion.X;
    float angulo = (float)Math.Atan(tan);

    Gl.glColor3f(texto.getRFloat(), texto.getGFloat(), texto.getBFloat());
    Gl.glScalef(tamaño, tamaño, tamaño);
    Gl.glTranslatef((float)texto.Posicion.X, (float)texto.Posicion.Y, (float)texto.Posicion.Z);
    Gl.glRotatef(angulo,0,1,0);
    if (texto.Alineacion == Align.left)
        fuenteActual.FT_ALIGN = FTFontAlign.FT_ALIGN_LEFT;
    if (texto.Alineacion == Align.center)
        fuenteActual.FT_ALIGN = FTFontAlign.FT_ALIGN_CENTERED;
    if (texto.Alineacion == Align.right)
        fuenteActual.FT_ALIGN = FTFontAlign.FT_ALIGN_RIGHT;

    fuenteActual.ftBeginFont();
    fuenteActual.ftWrite(texto.Text);
    fuenteActual.ftEndFont();

1) The first time the control draws the text, the position is detected properly The second time the control redraws, the X position is ingored and the text is horizontally centered. Only the height (Y position) is working.

2) Rotate does not work. The text is always displayed horizontally despite having the modelview matrix rotated. Why is this? I thought texture fonts were treated like any other OpenGL primitive.

+1  A: 

Could it be that you are rotating around the Y axis instead of the Z axis?

Gl.glRotatef(angulo,0,1,0);

Also I'm not familiar with the C# interface, but angles in OpenGL are normally specified in degrees, but you are passing a value return from Math.Atan2, which is in radians.

This also looks wrong:

Gl.glScalef(tamaño, tamaño, tamaño);
Gl.glTranslatef((float)texto.Posicion.X, (float)texto.Posicion.Y, (float)texto.Posicion.Z);

It is usual to do the translate first, then the scale. If you scale first then the scaling will be applied to your X and Y offsets as well as the texture. Try swapping these around.

finnw
Unfortunately that didnt work... i tried every axis lol...dont know whats wrong!! :(
OMG Man u are god... it was the radian thing... i thought the convention was to use radians not degrees... thanks manU know why the x positioning problem tho?
A: 

Try use "3f" function versions, for example: glTranslate3f glScale3f

And be careful with the order, as finw said.

Regards

Luis