LoginSignup
3
2

More than 3 years have passed since last update.

iOSアプリ開発:OpenGLで使う画像

Last updated at Posted at 2015-12-08

※個人で管理しているHPに引っ越ししました。
リンク切れ等考慮して本ページは残しておきますが、今後はHPのほうで更新します。

現象

数年前開発してた頃は、iOSでのOpenGLを使う際画像は2の冪乗じゃないと駄目!と思ってました。
この頃はAppleが公開してたサンプルのimageUtil.mを使ってテストしてました。

調査

調べてみると、今はGLKitのGLKTextureLoaderを使えば2の冪乗じゃなくても使えました。

対応

このように実装すると、textureInfoに様々な情報が設定され、glBindTextureで使える情報も得られます。

Test.m
// Load texture
NSString* filePath = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"png"];
GLKTextureInfo* textureInfo =
    [GLKTextureLoader textureWithContentsOfFile:filePath options:nil error:nil];
if (textureInfo) {
    NSLog(@"Texture Loaded. name = %d size = (%d x %d)", textureInfo.name, textureInfo.width, textureInfo.height);
}
glBindTexture(GL_TEXTURE, textureInfo.name);
3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2