使用openGL进行文本渲染:无法旋转文本,定位不正常 [英] Text rendering with openGL: Can't rotate text, positioning not working properly

查看:224
本文介绍了使用openGL进行文本渲染:无法旋转文本,定位不正常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,这是我的场景:
使用visual studio 2008.
项目在c#
中使用Tao框架和ISE.FreeType来呈现文本。
字体已经加载并转换为纹理位图:

$ p $ //美元
fuenteActual =新的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;

为了直接说明问题,这是我的代码来渲染一些文本。 b
$ b

  Gl.glLoadIdentity(); 
floattamañ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>
控件第一次绘制文本时, b $ b第二次控制重绘时,X位置被编入,文本水平居中。只有高度(Y位置)正在工作。

2)
旋转不起作用。尽管旋转了模型视图矩阵,文本总是水平显示。为什么是这样?我认为纹理字体像其他任何OpenGL原语一样处理。

解决方案

是不是可以围绕Y轴旋转而不是Z轴?

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

另外我对C#界面不熟悉,但是OpenGL中的角度通常用度来指定,但是你传递了一个从 Math.Atan2 的弧度值的返回值。





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

通常首先进行翻译,然后是比例尺。如果您先缩放,缩放将应用于您的X和Y偏移以及纹理。尝试交换这些。


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.

解决方案

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.

这篇关于使用openGL进行文本渲染:无法旋转文本,定位不正常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆