Category Archives: StackOverFlow

Stack Overflow is a question and answer site for professional and enthusiast programmers.

Libgdx distance field font support on iOS

Using distance field fonts like explained in the Libgdx wiki:
Gives good results on android. I’m using the example shader provided.

But when I run the same program on iOS the text is filled up with white everywhere (see image below).
Is distance field not supported by iOS or do I need to add/change something else to get it to work?

distance field problem

shader code font.vert:

uniform mat4 u_projTrans;

attribute vec4 a_position;
attribute vec2 a_texCoord0;
attribute vec4 a_color;

varying vec4 v_color;
varying vec2 v_texCoord;

void main() {
    gl_Position = u_projTrans * a_position;
    v_texCoord = a_texCoord0;
    v_color = a_color;


#ifdef GL_ES
    precision mediump float;

uniform sampler2D u_texture;

varying vec4 v_color;
varying vec2 v_texCoord;

const float smoothing = 1.0/16.0;

void main() {
    float distance = texture2D(u_texture, v_texCoord).a;
    float alpha = smoothstep(0.5 - smoothing, 0.5 + smoothing, distance);
    gl_FragColor = vec4(v_color.rgb, alpha);

read more

Xcode MyProjectName-Bridging-Header.h does not exist

I want to start using Swift in my Objective-C project. So i added a swift class:

import Foundation
@objc class System : NSObject {
    @objc func printSome() {
        println("Print line System");

And imported it into a .m file:

#import "MyProjectName-Swift.h"

When building my project i get the following error:

Bridging header 'PathToMyProject/MyProjectName-Bridging-Header.h' does not exist

NOTE: Under “Build Settings->Swift Compiler – Code Generation->Objective-C Briding Header” is set to MyProjectName-Bridging-Header.h

What should i do to solve this issue?

Any help is much appreciated.

EDIT: Bridging-Header file:
#if defined(__has_include) && __has_include()
# include

#include <objc/NSObject.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>

#if defined(__has_include) && __has_include(<uchar.h>)
# include <uchar.h>
#elif __cplusplus < 201103L
typedef uint_least16_t char16_t;
typedef uint_least32_t char32_t;
#if !defined(SWIFT_PASTE)
# define SWIFT_PASTE_HELPER(x, y) x##y
#if !defined(SWIFT_METATYPE)
# define SWIFT_METATYPE(X) Class

#if defined(__has_attribute) && __has_attribute(objc_runtime_name)
# define SWIFT_RUNTIME_NAME(X) __attribute__((objc_runtime_name(X)))
#if !defined(SWIFT_CLASS_EXTRA)
#if !defined(SWIFT_CLASS)
# if defined(__has_attribute) && __has_attribute(objc_subclassing_restricted) 
#  define SWIFT_CLASS(SWIFT_NAME) SWIFT_RUNTIME_NAME(SWIFT_NAME) __attribute__((objc_subclassing_restricted)) SWIFT_CLASS_EXTRA
# else
# endif

#if !defined(SWIFT_PROTOCOL)

#if !defined(SWIFT_EXTENSION)

# if defined(__has_attribute) && __has_attribute(objc_designated_initializer)
#  define OBJC_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
# else
# endif
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wproperty-attribute-mismatch"

#if defined(__has_feature) && __has_feature(modules)

#pragma clang diagnostic pop

read more

Changing tab bar font in Swift

I have been trying to change the font for the tab bar items however I haven’t been able to find any Swift examples. I know that this is how you change it in Objective-C:

[[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"AmericanTypewriter" size:20.0f], UITextAttributeFont, nil] forState:UIControlStateNormal];

But how can I translate this into Swift?

Changing tab bar font in Swift

How do I convert a Swift Array to a String?

I know how to programmatically do it, but I’m sure there’s a built-in way…

Every language I’ve used has some sort of default textual representation for a collection of objects that it will spit out when you try to concatenate the Array with a string, or pass it to a print() function, etc. Does Apple’s Swift language have a built-in way of easily turning an Array into a String, or do we always have to be explicit when stringifying an array?

How do I convert a Swift Array to a String?

read more

How can I shuffle bits efficiently?

I need to shuffle a 16 bit unsigned integer in a way that the even indexes land in the lower byte, and the odd indexes land in the upper byte.

fedcba98 76543210 (contiguously numbered)

fdb97531 eca86420 (even and odd separated)

My code looks like this at the moment:

typedef unsigned short u16;

u16 segregate(u16 x)
    u16 g = (x & 0x0001);
    u16 h = (x & 0x0004) >> 1;
    u16 i = (x & 0x0010) >> 2;
    u16 j = (x & 0x0040) >> 3;
    u16 k = (x & 0x0100) >> 4;
    u16 l = (x & 0x0400) >> 5;
    u16 m = (x & 0x1000) >> 6;
    u16 n = (x & 0x4000) >> 7;

    u16 o = (x & 0x0002) << 7;
    u16 p = (x & 0x0008) << 6;
    u16 q = (x & 0x0020) << 5;
    u16 r = (x & 0x0080) << 4;
    u16 s = (x & 0x0200) << 3;
    u16 t = (x & 0x0800) << 2;
    u16 u = (x & 0x2000) << 1;
    u16 v = (x & 0x8000);

    return g | h | i | j | k | l | m | n | o | p | q | r | s | t | u | v;

read more