Convert an UIImage in a texture

后端 未结 3 887
闹比i
闹比i 2020-12-03 06:27

In my opengl project I need to convert an UIImage in texture; what\'s the way to do it? Can you help me?

3条回答
  •  青春惊慌失措
    2020-12-03 06:58

    Another way of doing this using the GLKit framework:

    //Path to image
    NSString *path = [[NSBundle mainBundle] pathForResource:@"textureImage" ofType:@"png"];
    
    //Set eaglContext
    [EAGLContext setCurrentContext:[[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]];
    
    //Create texture
    NSError *theError;    
    GLKTextureInfo *texture = [GLKTextureLoader textureWithContentsOfFile:filePath options:nil error:&theError];
    glBindTexture(texture.target, texture.name);
    

    texture.name is The OpenGL context’s name for the texture.

提交回复
热议问题