zoukankan      html  css  js  c++  java
  • iOS-OpenGLES 简单渲染

     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;

  • 相关阅读:
    在Windows平台上安装Node.js及NPM模块管理
    MySQL远程访问授权
    JSON (仅限本地)
    Json 调用 天气API 实例
    JS调用腾讯接口获取天气
    jsonp 调用天气API
    兼容性
    MySql like模糊查询使用详解
    编绎报错,解决方法objc_msgSend too many arguments to function call,expected 0, have3 (转)
    OC中ARC forbids explicit message send of release错误(转)
  • 原文地址:https://www.cnblogs.com/hxwj/p/4664036.html
Copyright © 2011-2022 走看看