且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

OpenGL ES显示字符串2(Windows Mobile)

更新时间:2022-09-06 11:27:30

发现了OpenGLFont,所以这里备份一下。
例子:使用OpenGL ES画“Hello World!”
1:首先声明OpenGLFont font和GlyphRun title,然后在SetupScene使用


  1. OpenGLFont font;      
  2. GlyphRun title;      
  3. protected override void SetupScene()      
  4. {      
  5.     base.SetupScene();      
  6.     
  7.     font = new OpenGLFont(new Font(FontFamily.GenericSerif, 12, FontStyle.Regular));      
  8.     title = new GlyphRun(font, "Hello World!"new Size(int.MaxValue, int.MaxValue), OpenGLTextAlignment.Left, true);      
  9. }  

2:最后在DrawScene函数中调用


  1. protected override void DrawScene()      
  2. {      
  3.             base.DrawScene();      
  4.     
  5.             title.Draw();      
  6. }   

效果如下:

OpenGL ES显示字符串2(Windows Mobile)

3:如果要对文字进行旋转和尺度变化,我们需要使用gl.Rotate和gl.Translate方法


  1. gl.Translatef(50.0f,50.0f,0);      
  2. gl.Rotatef(40.0f,0,0,1.0f);      
  3. title.Draw();    

效果如下:

OpenGL ES显示字符串2(Windows Mobile)

最后附上所需的文件(见附件!)。




本文转自 yarin 51CTO博客,原文链接:http://blog.51cto.com/yarin/381959,如需转载请自行联系原作者