Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Draw Text in C# using OpenGL

Draw Text in C# using OpenGL

Scheduled Pinned Locked Moved C#
helpcsharpc++graphicsgame-dev
5 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yasir Nawazish Ali
    wrote on last edited by
    #1

    I am using C#, OpenGL and want to draw the Text on screen ... I went to OpenGL site and see the GLFont and other methods. Problem I face in these are: They give Code in C++ that uses pointers and references that are not supported in C# and it call them as unmanaged code, i write unsafe modifier in front of it but other problem arises. So, these codes are not helpful unless they are in C# language. if anyone know the method how to draw text in openGL or how to use C++ code in C# language then tell me .... I will be very pleased for your help ....

    C 1 Reply Last reply
    0
    • Y Yasir Nawazish Ali

      I am using C#, OpenGL and want to draw the Text on screen ... I went to OpenGL site and see the GLFont and other methods. Problem I face in these are: They give Code in C++ that uses pointers and references that are not supported in C# and it call them as unmanaged code, i write unsafe modifier in front of it but other problem arises. So, these codes are not helpful unless they are in C# language. if anyone know the method how to draw text in openGL or how to use C++ code in C# language then tell me .... I will be very pleased for your help ....

      C Offline
      C Offline
      Christoph Menge
      wrote on last edited by
      #2

      Hey, be careful not to mix up things here. First, OpenGL is a native C Library, so 'talking to' OpenGL, at some point, requires you to communicate with it - good news is, you don't have to that yourself (but you can if you want to). Check out the following libraries which may help: o Tao Framework[^] o EaseWrapperSDK[^] NOTE: Tao is for C#, EaseWrapper is for C++. If you haven't worked with managed C++ / Interop, look at Tao first. Tao has more to offer than just wrapping OpenGL, by the way (also wraps SDL, OpenAL, etc.) Second comes text rendering. There are a number of ways to it: o Manually. This involves a texture which contains letters and numbers. Then, you render little rectangles with orthographic projection on the screen. For a GUI, you want to do this after the scene is rendered. This is not as hard as it may sound. o Using a library such as glFont. As far as I know, glFont is a program or a library. Its not an OpenGL-Command. However, I don't know any C# gl font-render libraries, so again you might have to mess with a managed C++ wrapper. o Using a high-level library such as CeGUI which has a lot more to offer than text rendering. It is included in the EaseWrapperSDK, but it's also C++. There might be a GUI library in Tao, I'm not sure. I suggest you go for Tao and have a look at thoseNeHe Lessons[^] which concern font rendering. He presents a number of options. NeHe's tutorials are available as C#, but you will have to (in other words, you should) convert them to Tao if you use it. Hope that helps, Chris

      "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
      Articles  Blog

      Y P 2 Replies Last reply
      0
      • C Christoph Menge

        Hey, be careful not to mix up things here. First, OpenGL is a native C Library, so 'talking to' OpenGL, at some point, requires you to communicate with it - good news is, you don't have to that yourself (but you can if you want to). Check out the following libraries which may help: o Tao Framework[^] o EaseWrapperSDK[^] NOTE: Tao is for C#, EaseWrapper is for C++. If you haven't worked with managed C++ / Interop, look at Tao first. Tao has more to offer than just wrapping OpenGL, by the way (also wraps SDL, OpenAL, etc.) Second comes text rendering. There are a number of ways to it: o Manually. This involves a texture which contains letters and numbers. Then, you render little rectangles with orthographic projection on the screen. For a GUI, you want to do this after the scene is rendered. This is not as hard as it may sound. o Using a library such as glFont. As far as I know, glFont is a program or a library. Its not an OpenGL-Command. However, I don't know any C# gl font-render libraries, so again you might have to mess with a managed C++ wrapper. o Using a high-level library such as CeGUI which has a lot more to offer than text rendering. It is included in the EaseWrapperSDK, but it's also C++. There might be a GUI library in Tao, I'm not sure. I suggest you go for Tao and have a look at thoseNeHe Lessons[^] which concern font rendering. He presents a number of options. NeHe's tutorials are available as C#, but you will have to (in other words, you should) convert them to Tao if you use it. Hope that helps, Chris

        "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
        Articles  Blog

        Y Offline
        Y Offline
        Yasir Nawazish Ali
        wrote on last edited by
        #3

        Thanks 4 the Reply ... NeHe Lessons's Link was not Opened in my browser i think link is broken .... I want to ask one more thing that i am using this code ... where height is the Font height and startPoint_x and startPoint_y is the point where text is to be display CsGL.OpenGL.GDITextureFont myGDITextureFont; Font newFont; newFont = new System.Drawing.Font("Microsoft Sans Serif", (float)height); myGDITextureFont = new GDITextureFont(newFont, 'a', 'z'); GL.glTranslatef((float)startPoint_x, (float)startPoint_y, 0); myGDITextureFont.DrawString(text); and in this way text displayed but when i click on it it turns into solid bar .... Can you tell me, What is the problem with this code ....

        C 1 Reply Last reply
        0
        • Y Yasir Nawazish Ali

          Thanks 4 the Reply ... NeHe Lessons's Link was not Opened in my browser i think link is broken .... I want to ask one more thing that i am using this code ... where height is the Font height and startPoint_x and startPoint_y is the point where text is to be display CsGL.OpenGL.GDITextureFont myGDITextureFont; Font newFont; newFont = new System.Drawing.Font("Microsoft Sans Serif", (float)height); myGDITextureFont = new GDITextureFont(newFont, 'a', 'z'); GL.glTranslatef((float)startPoint_x, (float)startPoint_y, 0); myGDITextureFont.DrawString(text); and in this way text displayed but when i click on it it turns into solid bar .... Can you tell me, What is the problem with this code ....

          C Offline
          C Offline
          Christoph Menge
          wrote on last edited by
          #4

          Hi, the link to NeHe works out for me. If it doesn't work, you might want to google it or visit gamedev.net, which links to NeHe. As for the code you supplied, I don't see any trouble. However, the problem might be caused by your update/resize methods. The question is: Under which circumstances do you redraw the screen? You have to do that whenever Windows tells you to do so, because it might have invalidated the screen. This can happen when resizing, minimizing, when another application draws in front of yours or even if a different control receives focus. The latter happens upon click, so make sure you redraw the scene for the events named above. Chris

          "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
          Articles  Blog

          1 Reply Last reply
          0
          • C Christoph Menge

            Hey, be careful not to mix up things here. First, OpenGL is a native C Library, so 'talking to' OpenGL, at some point, requires you to communicate with it - good news is, you don't have to that yourself (but you can if you want to). Check out the following libraries which may help: o Tao Framework[^] o EaseWrapperSDK[^] NOTE: Tao is for C#, EaseWrapper is for C++. If you haven't worked with managed C++ / Interop, look at Tao first. Tao has more to offer than just wrapping OpenGL, by the way (also wraps SDL, OpenAL, etc.) Second comes text rendering. There are a number of ways to it: o Manually. This involves a texture which contains letters and numbers. Then, you render little rectangles with orthographic projection on the screen. For a GUI, you want to do this after the scene is rendered. This is not as hard as it may sound. o Using a library such as glFont. As far as I know, glFont is a program or a library. Its not an OpenGL-Command. However, I don't know any C# gl font-render libraries, so again you might have to mess with a managed C++ wrapper. o Using a high-level library such as CeGUI which has a lot more to offer than text rendering. It is included in the EaseWrapperSDK, but it's also C++. There might be a GUI library in Tao, I'm not sure. I suggest you go for Tao and have a look at thoseNeHe Lessons[^] which concern font rendering. He presents a number of options. NeHe's tutorials are available as C#, but you will have to (in other words, you should) convert them to Tao if you use it. Hope that helps, Chris

            "Obstacles are those frightening things you see when you take your Eyes off your aim" - Henry Ford
            Articles  Blog

            P Offline
            P Offline
            Paul Harsent
            wrote on last edited by
            #5

            I have been looking at the NeHe lesson and they seem to be in C++, sorry if im being blind. Also what is the best way to rotate text, i.e. having it writing at the angle or vertical. Thanks

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups