2012-02-24 2 views
0

나는 OpenGL을가 OpenTK를 사용하는 방법을 배우려고하고 나는 성공적으로 지금까지 다각형, 원, 삼각형을 그릴 수 있지만 내 다음 질문은 텍스트를 그리는 방법입니까? C#에있는 홈페이지의 예제를 살펴본 결과 VB .NET으로 번역되었습니다.OpenTK OpenGL 그리기 텍스트

그것은 현재 너무 나는 누군가가 내 코드에서 오류를 발견하거나 텍스트를 그릴 수있는 또 다른 방법을 제안 할 수 있다고 기대했다 흰색 사각형을 그립니다. 나는 나의 페인트 이벤트를 열거 할 것이다.

페인트 이벤트 : 카드가 (비 파워 - 중 - 두) 텍스처 크기 NPOT을 지원하지 않는 경우

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

당신은 흰색 사각형을 얻을 것이다. 비트 맵 크기를 예 : 256x256.

0

괜찮습니다. 많은 양의 텍스트 또는 중간 정도의 양을 그릴 계획이라면 성능이 완전히 저하됩니다. 와 xml 파일과 함께이 무엇

텍스트의 텍스처 아틀라스를 만드는 것입니다

www.angelcode.com/products/bmfont/ : 당신이하고 싶은 BMFont라는 프로그램을 조사입니다 위치, 너비 및 높이와 모든 문자의 오프셋. 먼저 xml 파일을 읽고 각 문자를 다양한 값으로 클래스에로드하여 시작합니다. 그런 다음 문자열에있는 문자보다 atlas를 바인딩하는 문자열을 전달하는 함수를 만들면 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 

BMFont 웹 사이트에 도움이 될만한 다른 언어로 제공되는 자습서가 있습니다.