码迷,mamicode.com
首页 > 移动开发 > 详细

iOS-OpenGLES 简单渲染

时间:2015-07-21 14:10:21      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:

 UIImage *showImage = [UIImage imageNamed:@"demo.jpg"];
    CGRect rect = CGRectMake(00, showImage.size.width, showImage.size.height);
    //获取OpenGLES需然然的上下文
    EAGLContext *eagContext = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES2];
    //创建出渲染的buffer
    
    _glkView = [[GLKView alloc]initWithFrame:rect context:eagContext];
    [_glkView bindDrawable];//绑定绘制
    [self.view addSubview:_glkView];
    
    //创建出CoreImage用的上下文
    _ciContext = [CIContext contextWithEAGLContext:eagContext options:@{kCIContextWorkingColorSpace:[NSNull null]}];
    
    //CoreImage相关设置
    _ciImage = [[CIImage alloc]initWithImage:showImage];
    _filter = [CIFilter filterWithName:@"CISepiaTone"];
    [_filter setValue:_ciImage forKey:kCIInputImageKey];
    [_filter setValue:@(0) forKey:kCIInputIntensityKey];
    
    //开始渲染
    [_ciContext drawImage:[_filter outputImage] inRect:CGRectMake(00, _glkView.drawableWidth, _glkView.drawableHeight) fromRect:[_ciImage extent]];
    [_glkView display];//显示出来

 动态渲染,改变value值就行了

- (IBAction)sliderIsChange:(UISlider *)sender {

        [_filter setValue:_ciImage forKey:kCIInputImageKey];
        [_filter setValue:@(sender.value) forKey:kCIInputIntensityKey];
    
        //开始渲染
        [_ciContext drawImage:[_filter outputImage] inRect:CGRectMake(00, _glkView.drawableWidth, _glkView.drawableHeight) fromRect:[_ciImage extent]];
        [_glkView display];
}

 

 技术分享

补充:需倒入框架#import <GLKit/GLKit.h>

属性:

@property (weak, nonatomic) IBOutlet UISlider *slider;
@property (nonatomic,strong)GLKView *glkView; //渲染buffer视图

@property (nonatomic,strong)CIFilter *filter;
@property (nonatomic,strong)CIImage *ciImage;
@property (nonatomic,strong)CIContext *ciContext;

iOS-OpenGLES 简单渲染

标签:

原文地址:http://www.cnblogs.com/hxwj/p/4664036.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!