Draw Text in C# using OpenGL
-
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 ....
-
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 ....
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 -
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 BlogThanks 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 ....
-
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 ....
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 -
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 BlogI 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