Custom fonts in app - c#

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.

Related

Render OpenGL scene at two different locations

I am writing an application that renders an OpenGL scene. This application has two windows:
A large window that shows only the rendered scene
A "control window" that offers several settings and a preview of the rendered scene
This application is written in .NET (for the control window part) and uses a native C++ DLL to create the rendering window and do the actual OpenGL rendering.
This works fine, but one important part is still missing: getting a live preview of the rendered scene into my .NET control window.
So far I could think of two solutions:
Render the scene not only to the screen, but also to memory. Then shove that blob of memory to my .NET WinForm. Finally draw the image to a PictureBox or something. <- This sounds horribly slow!
Make my native OpenGL renderer render the scene twice, once to the native full size window, once to a control (panel?) on my .NET form.
Option 2 sounds faster, but I have no idea if/how that even works.
Can this be done? Are there better alternatives?
Look into the documentation on framebuffers. It is basically the destination of your rendering, by default it's your viewport (or the backbuffer, which switches with the displayed buffer once it's ready).
The first option should generally be faster as you render the scene once and then just basically copy a texture.

How can I use a scml animation from spriter in XNA

I have a program to make 2d animation and when I save my animation the format is scml and I can't open that animation in XNA.
Do I have to put it in another format?
The software is Spriter.
For one, XNA dosen't include content loaders for anything more than your default file types such as PNG, JPEG, TxT, etc.
I saw an exacmple of a scml file from spriter, and you will need to create your own content loader for it, but that is probably going to be a bit hard.
Your best bet is to take an animation example, and take the pictures that Spriter has made, and arrange them into a spritesheet.
I'm afraid this isnt as simple as you thought, but manually making a spritesheet will probably be your best bet.
Important Edit:
Your in luck, someone already made a content loader for Spriter in XNA!
https://github.com/schmelze/SpriterXNA and I belive a newer version https://bitbucket.org/dylanwolf/xspriter

How do you change the color of an Image in WPF?

I have a .png image that's just white-on-transparent, and I'm wondering if there's an easy way to make that green-on-transparent, red-on-transparent, etc so I don't need to make separate .png files for each color.
Take a look at these CodeProject Articles
Image Processing Lab
ImageMagic-WPF Image Color Spaces
Image Processing Lab is a simple tool for image processing, which
includes different filters and tools to analyze images available in
the AForge.NET framework.
You could also take a look at the FormatConvertedBitmap, ColorConvertedBitmap or WritableBitmap Class's
For a simpler solution that doesn't require pulling in huge libraries and lets you understand what's going on under their hood (and thus gives you greater flexibility), learn how to use WPF Pixel Shaders (google it).
Then you can use something like the multiply shader here: http://rakeshravuri.blogspot.com/2008/08/blending-modes-in-wpf-using.html

How to show text on the screen using OpenGL and C#

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

C# - Create font from image or set of images

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.

Categories

Resources