iPhone OpenGL ESで文字をテクスチャにする

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
黄泉

iPhone OpenGL ESで文字をテクスチャにする

#1

投稿記事 by 黄泉 » 14年前

iPhone OpenGL ESで文字をテクスチャにする関数を作っております。
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;
}

“C言語何でも質問掲示板” へ戻る