iPhone OpenGL ESで文字をテクスチャにする
Posted: 2012年3月17日(土) 21:21
iPhone OpenGL ESで文字をテクスチャにする関数を作っております。
google検索で色々試して
こちらのサイト様に辿り着きました。
http://dixq.net/forum/viewtopic.php?f=3&t=5904
GLuint の戻り値を吐き出すような関数を作りたいです。
google検索で色々試して
こちらのサイト様に辿り着きました。
http://dixq.net/forum/viewtopic.php?f=3&t=5904
GLuint の戻り値を吐き出すような関数を作りたいです。
GLuint loadFont(){
// コンテキストの生成
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGContextRef bitmapContext = CGBitmapContextCreate(NULL,
imageRect.size.width, imageRect.size.height, 8,
imageRect.size.width * 4, colorSpace, kCGImageAlphaPremultipliedLast);
CGColorSpaceRelease(colorSpace);
// 文字列を描画
UIGraphicsPushContext(bitmapContext);
UIFont *tFont = [UIFont systemFontOfSize:40];
[[UIColor whiteColor] set];
[@"Test String 1234567890" drawAtPoint:CGPointMake(0, 0) withFont:tFont];
[@"日本語もOK!" drawAtPoint:CGPointMake(0, 44) withFont:tFont];
UIGraphicsPopContext();
// イメージを取り出す
CGImageRef image = CGBitmapContextCreateImage(bitmapContext);
CGContextRelease(bitmapContext);
// テクスチャの生成
GLuint texture;
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,
imageRect.size.width, imageRect.size.height, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
CGImageRelease(image);
return texture;
}