Texture2D text color changed after updating from iOS 3.0 to 4.0
I'm using an OpenGL Texture2D class and initWithString method to display strings to the user. When running with iOS 3.0 and XCode 3.1.3 all the text would appear black in the simulator and white on the phone. After updating to iOS 4.0, XCode 3.2.3, and iPhone SDK 4.0 the text appears black on the phone! Not so good since my app i开发者_运维技巧s almost complete and the artwork was designed around white text. How can I fix this?
More info: I'm testing on a 3G phone. Also the texture2D class is from Crashlanding.
Ok I found a solution with some awesome help provided by this blog (majicjungle.com). Basically I modified the Texture2D class initWithString method as mentioned in the first few steps of the linked tutorial.
Here are the modifications I made:
1) Replaced four lines in initWithString w/ these four lines:
colorSpace = CGColorSpaceCreateDeviceRGB();
data = calloc(1, width * height * 4);
context = CGBitmapContextCreate(data, width, height, 8, width * 4, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
2) Replaced kTexture2DPixelFormat_A8 with kTexture2DPixelFormat_RGBA8888 in the call to initWithData
3) Changed CGContextSetGrayFillColor(context, 1.0, 1.0); to CGContextSetRGBFillColor(context, 1.0, 1.0, 1.0, 1.0);
The 2nd-4th arguments to CGContextSetRGBFillColor are the RGB values. Making them all 1.0 resulted in the desired white font color.
I definitely advise reading the blog post... it's very helpful.
精彩评论