Created
March 13, 2012 09:00
-
-
Save objective-audio/2027722 to your computer and use it in GitHub Desktop.
Unityのテクスチャを書き換えるプラグイン
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//texIDはTexture.GetNativeTextureID()で取得したGLのTexture | |
//texWidthとtexHeightはテクスチャのサイズ | |
//strは書き込みたい文字列 | |
void WriteTextToTexture_(int texID, int texWidth, int texHeight, const char *str) { | |
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); | |
Byte *bitmapBuffer = calloc(texHeight, texWidth * 4); | |
CGContextRef bitmapContext = CGBitmapContextCreate(bitmapBuffer, texWidth, texHeight, 8, texWidth * 4, colorSpace, kCGImageAlphaPremultipliedLast); | |
CGColorSpaceRelease(colorSpace); | |
UIGraphicsPushContext(bitmapContext); | |
[[UIColor whiteColor] set]; | |
CGRect drawRect = CGRectMake(0, 0, texWidth, texHeight); | |
NSString *text = [NSString stringWithCString:str encoding:NSUTF8StringEncoding]; | |
[text drawInRect:drawRect withFont:[UIFont systemFontOfSize:120] lineBreakMode:UILineBreakModeClip alignment:UITextAlignmentLeft]; | |
UIGraphicsPopContext(); | |
glBindTexture(GL_TEXTURE_2D, texID); | |
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, texWidth, texHeight, GL_RGBA, GL_UNSIGNED_BYTE, bitmapBuffer); | |
glBindTexture(GL_TEXTURE_2D, 0); | |
free(bitmapBuffer); | |
CGContextRelease(bitmapContext); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment