zoukankan      html  css  js  c++  java
  • OpenGL2 CoreImage初探与Model封装

    首先OpenGL2框架的使用需要  

    #import <GLKit/GLKit.h>

    OpenGL 调用的是GPU,而不是CPU所以,在不断改变属性的时候不会出现卡顿。

    大概的调用方法分为 :

    //    1.首先GLK 需要一个渲染环境 先创建一个EAGLContext渲染环境, GLKView 初始化的时候需要使用

    //    2.初始化 GLKView 对象,将GLKView绑定并且添加到View

    //    3.GLKView中渲染是通过 CIContext  CIContext drawImage inRect fromRect

    //    4.最后通过GLKView展现出来 [mglkView display];

    然后代码: 这是写在Model里的代码,因为在Model里无法直接获取View,所以需要通过 UIApplication 获取到当前的View

    -(void)openGLCreateGLKViewWithImage:(UIImage *)image FilterName:(NSString *)filterName Rect:(CGRect)rect
    {
        // 获取当前的View
        UIWindow *window = [[UIApplication sharedApplication] keyWindow];
        if(window.windowLevel != UIWindowLevelNormal)
        {
            NSArray *windows = [[UIApplication sharedApplication] windows];
            for(UIWindow *tmpWin in windows)
            {
                if(tmpWin.windowLevel == UIWindowLevelNormal)
                {
                    window = tmpWin;
                    break;
                }
            }
        }
        
        NSArray *viewsArray = [window subviews];
        UIView *frontView;
        if ([viewsArray count]>0) {
            frontView = [viewsArray objectAtIndex:0];
        }
        
        mrect = rect;
        EAGLContext *ueaglContext = [[EAGLContext alloc]initWithAPI:kEAGLRenderingAPIOpenGLES2]; // 首先是渲染环境
        
        mglkView = [[GLKView alloc]initWithFrame:rect context:ueaglContext];
        [mglkView bindDrawable]; // 绑定 mglkView
        if (frontView) {
            [frontView addSubview:mglkView]; // 将GLKView的对象添加到当前View里面
        }
        
        mcontext = [CIContext contextWithEAGLContext:ueaglContext options:@{kCIContextWorkingColorSpace :[NSNull null]}];
        mimage = [[CIImage alloc]initWithImage:image];
        mfilter = [CIFilter filterWithName:filterName];
    }
    

    上面是初始化对象的代码, 然后下面的方法是给对象设置属性

    -(void)openGLdrawImageWithValue:(CGFloat)value key:(NSString *)keyName
    {
        [mfilter setValue:@(value) forKey:keyName]; //keyName 可以通过 NSlog(mfilter.attributes) 查询  设置
        [mfilter setValue:mimage forKey:kCIInputImageKey];    // 设置滤镜的输入CIImage CIFilter的图片输入格式是 CIImage
        [mcontext drawImage:[mfilter valueForKey:kCIOutputImageKey]
                     inRect:CGRectMake(0, 0, mglkView.drawableWidth, mglkView.drawableHeight)
                   fromRect:[mimage extent]];    // 通过 CIContext绘制,将图片展现在GLKView的对象中
        [mglkView display]; // 最后 display
    }
    

      

  • 相关阅读:
    比较全的JS checkbox全选、取消全选、删除功能代码
    JS下高效拼装字符串的几种方法比较与测试代码
    jQuery操作 input type=checkbox的实现代码
    禁用和选中所有页面上的复选框。
    jquery实现radio按纽全不选和checkbox全选的实例
    Javascript的四种继承方式
    javascript绑定时间 含(IE)
    input中如何输入逆写的中文句子
    清除浮动
    关于iOS9中的App Transport Security相关说明及适配(转)
  • 原文地址:https://www.cnblogs.com/stuwan/p/4986307.html
Copyright © 2011-2022 走看看