The way XNA 4.0 render fonts on the screen is a step back from XNA 3.1, to say the least. Thankfully, using the Nuclex Framework has solved this problem. However, this is for spritefont files.
Is there a way Nuclex can support spritefont textures(Nubik's, etc...) as well? If not,
how do you take "not-so-common" font, convert it to a spritefont, and make sure it's displayed on another computer(which probably won't have that font installed)?
Spritefonts are compiled. You get a spritefont.xnb file when you build your content, and this file contains all of your characters (the ones you defined in the .spritefont file). Since the game uses the characters that are in these files - which get deployed with your game - there is no need for the target computer to have any fonts.
Also, there is no need for Nuclex to support spritefont textures - you can use these textures in your content as they are because they will remain unchanged. Nuclex fonts only use a different way of drawing characters than the default XNA Spritefont processor does. The spritefont texture characters are already drawn.
Related
I have not found solution for my problem.
I want to combine few textures (one under another, they won't overlap) and then write a text on one of them. So basically I would like to set some render target, draw there few textures and text and then save it to final texture. Of course I need to do it during run-time from script.
What is the best way to do it in Unity 5.0? (script is in C#)
You can do it with
target texture
In my app i want to add feature to use custom fonts.
User choose font from list on my server, download and use it in app.
How to do the part of the app that will render font?
How to do it in an app that does not use the xaml?
The task you're about to embark on is probably going to involve a fair amount of code because the characters in the font will need to be rendered to a texture first before they can be rendered as part of a SpriteBatch.
Typically, this works in XNA by going through the content pipeline. You select a font file and setup the font properties in XML, then the content content pipeline compiles this information into an xnb resource which can be loaded and rendered. The problem is, it all happens at compile time and therefore it's going to be hard to do at run-time.
Reference: http://rbwhitaker.wikidot.com/drawing-text-with-spritefonts
An alternative method is to use a tool like BMFont to pre-render your font to a texture and write your own renderer. I wrote a tutorial once using this technique. However, it's much the same thing but you're replacing the XNA content pipeline with the BMFont tool.
http://www.craftworkgames.com/blog/tutorial-bmfont-rendering-with-monogame/
With this in mind, if you want to achieve this you'll probably need to write your own code to render each font to a texture after you've loaded it at run-time. You'll also need to keep track of the rectangle on the texture for each glyph as you're loading in the font. To save texture space and support larger font sizes you might also need to consider texture packing and excluding certain characters.
I need to draw simple alpha maps in xna which depends on current game state. I cannot save many kinds of alpha maps in reseources, so i want to draw them dynamically.
For example sprite can be partially hidden behind wall.
I think about using System.Drawing, but when i'm including this dll, there are conflicts with Xna namespaces. Is there another way to draw simple bitmaps in xna?
Thank you for your time.
You should not use the System.Drawing classes. These work on images that lie in the system RAM. Instead use XNA to manipulate a texture that lies in GPU memory.
You can use SetRenderTarget() to set the texture as the render target. This will cause further draw calls to be executed on the texture. This way, you can draw everything on the texture. However, you will not have methods for drawing circles, squares etc. To achieve this, you should either create vertex buffers with the according geometry or use a sprite template.
Situation: Simple 3D game project - OpenGL + C#
I read that OpenGL functions doesn't support easily print the text on the screen.
Have anyone clue how to do it? I don't need any too much sophisticated solution.
I just need show for example FPS rate in one corner or show the number of picked up objects in anohter corner.
thx.
One good method for text rendering is to use a texture with the font characters and draw one quad for each character with the good texturing coordinates. This usually gives good results and is platform independant. However this is quite heavy to implement.
Use wgl functions of Opengl32.dll on windows to render text. Example here: http://www.pinvoke.net/default.aspx/opengl32.wglusefontoutlines#
The basic process is you have to build a display list of glyphs in advance (rending the Windows font into an OpenGL context), then you can draw characters on the OpenGL display surface using the characters as indices into the pre-rendered display list.
For a prepackaged managed solution, take a look at Mono's Tao library: http://www.mono-project.com/Tao
http://nehe.gamedev.net/tutorial/freetype_fonts_in_opengl/24001/ This should give you all you want. Its in C++ but I am guessing that should not be a problem. It basically elaborates on what neodelphi suggested.
Although you say you don't need to much complexity and require it for just the FPS, having
a nice font rendering system comes in extremely handy.
HTH
The title really says it all. I need help in creating a custom font from either a set of separate image files or from one image with a series of characters setup in a grid fashion in C#. I have searched everywhere and haven't found any useful resources on the subject. If you have any advice, thanks in advance.
As far as I have read, there is nothing within the C# framework that allows for the creation of a font, by the looks of it you will have to implement this on your own. Microsoft of course puts out some tools and a SDK for font creation, here along with other information here There are several tools outside of Microsoft that will allow you to create fonts aswell, for example this. I'm sure this isn't quite what you are looking for but it's a start.
This was something that was done 20 years ago, before freely scalable outline font technologies like TrueType became available. Some of these fonts are still on your machine, the .fon files in c:\windows\fonts. They actually contain bitmaps of the letters in the font, usually around 256 of them for each individual font height supported by the font.
Support for these fonts is not present in .NET so don't consider creating one of them. In general, the disadvantages of not using a TrueType font are:
only available in certain point sizes
no decent Unicode support
different code pages require different fonts
no support for kerning and glyph overhang
no anti-aliasing support
no ClearType support
Tools are available to create your own TrueType font. It is not exactly easy to get right, one of the things that makes TrueType shine is 'hinting', altering the letter shapes when they font is rendered at small point sizes so that they are still legible. Verdana is a exemplary font that is hinted extraordinarily well.
Anyhoo, to pursue your approach you'll need to create a bitmap that contains all the letters that you are willing to support, arranged horizontally for example. The best way to order them is to pick the letters in a code page that's close to you, like Windows 1252 which is common in Western Europa and the Americas.
Things are simple if the font is fixed-pitched, every letter will start at a multiple of the letter width. A proportionally spaced font requires a separate lookup table that specifies at what pixel offset each letter starts. Using System.Drawing for example, you'd use the Graphics.DrawImage(image, rectangle, rectangle, graphicsunit) overload where you setup the rectangles so that the letter you want to render is copied. Use Encoding.GetBytes() to convert the string to render to indices in your font bitmap.