How can I render text using font files on Direct3D 11? - direct3d11

I've read many questions about this, but they don't satisfy what I'm trying to do. I'm trying to use a TTF file for the text's font on my application, I thought of using Direct Draw, but the tutorial from Microsoft website only explains how to use it with Direct2D. How am I supposed to load data from this file and render text for my Direct3D application using this file's font? I've also read about the AddFontResourceExA() function, but I didn't find any content of how I could use this. I'm really lost here, so any help is appreciated.

There are basically two approaches for rendering text on a Direct3D 11 Render Target / Texture.
Rendering using a 'sprite sheet'. Here you capture the font at a particular resolution and generate a texture from it. Then you use the texture to render the glyphs as textured triangles. This is very fast and inexpensive to render, but does not scale to arbitrary resolutions (you can capture the 'sprite sheet' at multiple point sizes to get some scaling) and does not work well with "CKJ" languages due to the large size of the fonts. For an example of this, see SpriteFont in the DirectX Tool Kit. This is what legacy D3DX9/D3DX10 did as well.
Rendering using vector fonts directly. Here you have some kind of library that generates triangles 'on-the-fly' from the "TrueType" vector font data. This is what Direct2D+DirectWrite is designed to do. You can use interop with Direct3D 11 surfaces, but essentially you are using DirectWrite -> Direct2D -> shared texture. Then you draw the shared texture with Direct3D as a 'sprite'. This is more complicated to setup, but results in arbitrary resolutions scaling, support for large character set fonts, and handles complex writing systems.

Related

How to pass 2x-resolution image to wxBitmapButton in OS X?

My app has a toolbar which is normally 64 pixels height. On OS X (with a retina display) the toolbar's height still equals to 64 (logical) pixels.
If I pass 64x64 bitmap when creating a wxBitmapButton I get a blurry image (which is expected), so I need to pass somehow a 128x128 bitmap.
When I pass it, it's just shown cropped without proper scaling. So how can I use wxBitmapButton to show high-quality bitmap?
I know this is a rather old question by now, but there is finally a good answer to it now if you're using the latest versions of wxWidgets from Git or 3.1.6+ once it will have been released.
The answer consists in using wxBitmapBundle which is basically a smart container for bitmaps to be used in different resolutions/at different DPI scale factors. In the simplest case, which is sufficient under Mac, you just need to create a bundle from the two bitmaps, to be used at normal (or 100%) and high (or 200%) DPI by using wxBitmapBundle::FromBitmaps(bmpNormal, bmpHigh) and pass this object to wxBitmapButton::SetBitmap().
This also works with wxToolBar tools, wxStaticBitmap and other (although not yet all) classes. And the bitmap bundle can be created from resources, which is especially convenient under Mac, as you can just have normal.png and normal#2x.png files in your application bundle (which has nothing to do with wxBitmapBundle, it's just an unfortunately overloaded term) Resources subdirectory.

How to auto generate Retina and Non-retina images from psd

I have a PSD file for my App Interface that was designed for Retina iPhones with a resolution of 640 x 1136. I want to add support for non-retina devices and and add all image assets with both a retina and non-retina version. I find the process of resizing every ui component on photoshop individually very tedious. Does anyone know how I can auto-generate Non-Retina images from the Retina images I have already exported? Thanks
If you have Photoshop CC, you can use Adobe Generator (especially nice when paired with Russell Brown’s free Layer Namer extension). Adobe Generator automatically exports any layers whose names end with .png, and can also export multiple resolutions.
There are also some great posts on this topic by Marc Edwards on the Bjango blog; specifically: Exporting from Photoshop. His articles deal with creating a slice sheet that you export semi-automatically with scripts.
I have used both of these workflows in production. Each has its quirks, but they can both probably be made to do what you’re after.
A tip: I prefer to design at 1x and then scale up. If you design and scale down, you might make an asset an odd number of pixels wide, which could look bad when scaled down. But many graphic designers I've worked with prefer to design at 2x.
For images i am using Resizer .Quite nice and fast application.
If you're able to work from the original .psd then the free SuperExport Photoshop script might be of use. It allows you to export flattened crops (not just entire layers) at multiple resolutions by careful naming of groups and layers. Documentation is here, and an updated version that also supports 3x is here (I'm the author of the - small - 3x modification).
The benefits, as pointed out in the docs, of using the original .psd are that you can see your design in context while selectively (and easily) regenerating assets with a single click.

Custom icons on google map not drawing correctly

I'm having problems with google maps, drawing icons was working fine few weeks ago in my project. At some time the icons are very frequently drawing in partly and I don't know what is causing it. It is both happening on my development machine and production server and on all machines.
I'm only using two different icons so I know the bitmap images are not corrupt.
Here below are two sample images.
You'll get more help if you post your outputted JSON. Your gmaps JSON must not have quotes around width or height, like so: "picture":"/assets/dayhome.png","width":32,"height":37,"lat":53.5402,"lng":-113.628
Another fix is to include optimized:false which disables the html5 canvas (the squares that are cutting off the markers).
My much more detailed analysis here: Canvas Tiles Cut Off Custom Markers
Set optimized:false in your Marker options.
If optimized is true (the default), then your marker images are incorporated into the tiles. Unfortunately where markers cross tile boundaries, they are not also used on the adjacent tile, so appear to be truncated at the edge of the tile. Using optimized:false forces the icons to be placed on the map as separate DOM objects.

Vector art on iOS

We've now got 4-resolutions to support and my app needs at least 6 full-screen background images to be pretty. Don't want to break the bank on megabytes of images.
I see guides online about loading PDFs as images and custom SVG libraries but no discussion of prectically.
Here's the question: considering rendering speed and file size, what is the bet way to use vector images in iOS? And in addition, are there any practical caching or other considerations one should make in real world app development?
Something to consider for simple graphics, such as the type of thing used for backgrounds, etc., is just to render them at runtime using CG.
For example, in one of our apps, instead of including the typical repeating background tile image in all the required resolutions, we instead draw it once into a CGPatternRef, then convert it to a UIColor, at which point things become simple.
We still use graphic files for complex things, but for anything that's simple in nature, we just render it at runtime and cache the result, so we get resolution independence without gobs of image files. It's also made maintenance quite a bit easier.

Using vectors in iOS

I'm working on a simple iOS game that's always drawing 5 to 10 layers of 32bit png images which requires enough memory to crash on the ipod touch 4g when retina enabled. On other devices it works just fine. I'm not even getting memory warnings. So I was trying with lower quality images, like RGB5_A1 format, but it looks really bad because I need alpha transparency and lots of gradients.
Since all the images are exports from Illustrator I was thinking that maybe i could just export a vector image and draw in on iOS. From what i was researching hardly anyone tried this and the only option I've come across was to implement a SVG parser for Quartz.
Did I miss anything?
Also I'm worried about performance, but I couldn't find any benchmarks.
Without knowing specifics of your game, I'm going to make a few assumptions based on normal use...
You are not going to want to use straight vector graphics for this. Stick with your raster graphics.
If you are talking about 32 bit color space for your PNG images, then you need to scale back. iOS uses 24 bit images and that includes 8 bits each for red, green, blue, and alpha. As it stands, you have an extra byte for every pixel shown.
If you are using Adobe products, import the Illustrator file into Photoshop and use the "Save for Web..." option. Choose PNG-24 and you'll be all set.