2012-02-24 102 views
0

OpenTKを使用してOpenGLを使用する方法を学びたいと思っています。これまでのところ、多角形、円、三角形をうまく描くことができましたが、次の質問はどのようにテキストを描くのですか?私はC#にあるホームページの例を見て、それをVB .NETに翻訳しました。OpenTK OpenGL図面テキスト

現在のところ、白い矩形を描画しているので、コード内にエラーが見つかるか、テキストを描画する別の方法を提案することができます。私は私のペイントイベントをリストアップします。

Paintイベント:

GL.Clear(ClearBufferMask.ColorBufferBit) 
    GL.Clear(ClearBufferMask.DepthBufferBit) 






    Dim text_bmp As Bitmap 
    Dim text_texture As Integer 

    text_bmp = New Bitmap(ClientSize.Width, ClientSize.Height) 
    text_texture = GL.GenTexture() 

    GL.BindTexture(TextureTarget.Texture2D, text_texture) 
    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMagFilter, All.Linear) 
    GL.TexParameter(TextureTarget.Texture2D, TextureParameterName.TextureMinFilter, All.Linear) 

    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, text_bmp.Width, text_bmp.Height, 0 _ 
    , PixelFormat.Bgra, PixelType.UnsignedByte, IntPtr.Zero) 



    Dim gfx As Graphics 



    gfx = Graphics.FromImage(text_bmp) 

    gfx.DrawString("TEST", Me.Font, Brushes.Red, 0, 0) 





    Dim data As Imaging.BitmapData 
    data = text_bmp.LockBits(New Rectangle(0, 0, text_bmp.Width, text_bmp.Height), Imaging.ImageLockMode.ReadOnly, System.Drawing.Imaging.PixelFormat.Format32bppArgb) 


    GL.TexImage2D(TextureTarget.Texture2D, 0, PixelInternalFormat.Rgba, Width, Height, 0, PixelFormat.Bgra, PixelType.UnsignedByte, data.Scan0) 

    text_bmp.UnlockBits(data) 


    GL.MatrixMode(MatrixMode.Projection) 
    GL.LoadIdentity() 
    GL.Ortho(0, width, Height, 0, -1, 1) 

    GL.Enable(EnableCap.Texture2D) 
    GL.Enable(EnableCap.Blend) 
    GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.OneMinusSrcAlpha) 

    GL.Begin(BeginMode.Quads) 

    GL.TexCoord2(0.0F, 1.0F) 
    GL.Vertex2(0.0F, 0.0F) 

    GL.TexCoord2(1.0F, 1.0F) 
    GL.Vertex2(1.0F, 0.0F) 

    GL.TexCoord2(1.0F, 0.0F) 
    GL.Vertex2(1.0F, 1.0F) 

    GL.TexCoord2(0.0F, 0.0F) 
    GL.Vertex2(0.0F, 1.0F) 



    GL.End() 



    GlControl1.SwapBuffers() 

答えて

0

あなたのカードがNPOT(非2の累乗)のテクスチャサイズをサポートしていない場合は、白い四角形を取得します。ビットマップサイズを例えばに設定してテストを試してください。 256x256。

0

これはokメソッドです。たくさんのテキストや中程度の量を描画する予定がある場合、それはパフォーマンスを絶対に破壊します。とxmlファイルと一緒に、これは何

は、テキストのテクスチャアトラスを作成している

www.angelcode.com/products/bmfont/:やりたいことBMFontと呼ばれるプログラムに見ています各文字の位置、幅、高さ、オフセット。まずxmlファイルを読み込み、さまざまな値を使って各文字をクラスに読み込みます。次に、文字列の文字に依存するよりも、アトラスをバインドする文字列を渡す関数を作成するだけで、xmlデータで変化するテクスチャ座標を持つクワッドが描画されます。

for each _char in string 
    create quad according to xml size 
    assign texture coordinates relative to xml position 
    increase position so letters don't draw on top of each other 

他の言語のチュートリアルが役立つかもしれません。