2014/07/25

Flip texture vertically in OpenGL

This post is about OpenGL WITHOUT GLKit. I like to use GLKit, because it is very useful and helpful, but most of the code I can see in the web is written without GLKit. So I should learn such code.

And I had a trouble in setting a texture. it seemed to flip both sides. I understood it because the texture was different from what I had made with GLKit.

object before flip

↑This is a screenshot with ‘wrong’ texture, you may not understand.

At first I learned OpenGL at this nice website :
OpenGL Tutorial for iOS: OpenGL ES 2.0 | Ray Wenderlich
You can see code to set a texture in Part2. The method is
- (GLuint)setupTexture:(NSString *)fileName

But this method is not enough, if you have uv coordinate to set texture. And I found this page :

ios - In UIImage to Texture conversion, Texture is flipped vertically - Stack Overflow

This is it! I flipped the image as the answer said, the object became like this :

object after flip

↑This is what I expected.
Develop | Comments(0) | Trackback(0)
Comment

管理者のみに表示