Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
着色器程序在Cocos2d 2.2 Obj.C iOS 12中不工作_Ios_Iphone_Xcode_Cocos2d Iphone - Fatal编程技术网

着色器程序在Cocos2d 2.2 Obj.C iOS 12中不工作

着色器程序在Cocos2d 2.2 Obj.C iOS 12中不工作,ios,iphone,xcode,cocos2d-iphone,Ios,Iphone,Xcode,Cocos2d Iphone,代码: 如何使用COCOS2D2.2 Obj.C项目修复iOS12中的着色器代码?如果我在iOS 7模拟器中运行,它工作得很好。相同的代码在iOS 12中不工作,修复了Cocos2d中的着色器问题 在上面的代码中,主要问题是CGFloat…将其转换为所有顶点的float 我还从Cocos2d-x获取了与着色器相关的文件,并将其转换为Cocos2d的obj.C 现在,所有着色器在Cocos2d v2.2 Obj.C iOS 12和iPhoneX/XR/XSMax中都能完美工作 快乐编码!干杯:)

代码:


如何使用COCOS2D2.2 Obj.C项目修复iOS12中的着色器代码?如果我在iOS 7模拟器中运行,它工作得很好。相同的代码在iOS 12中不工作,修复了Cocos2d中的着色器问题

在上面的代码中,主要问题是CGFloat…将其转换为所有顶点的float

我还从Cocos2d-x获取了与着色器相关的文件,并将其转换为Cocos2d的obj.C

现在,所有着色器在Cocos2d v2.2 Obj.C iOS 12和iPhoneX/XR/XSMax中都能完美工作

快乐编码!干杯:)

  [lightRender beginWithClear:0 g:0 b:0 a:0];

    self.shaderProgram = [[CCShaderCache sharedShaderCache] programForKey:kCCShader_PositionColor];

    CC_NODE_DRAW_SETUP();

    CGPoint vertices[3];
    ccColor4F colors[3];

    CGPoint mid = BODY_POSITION(cursor.body);

    float radius = LIGHT_RANGE * lightRadius;             // - (CCRANDOM_0_1() * LIGHT_RANGE * .015);

    float initialAlpha = .7f;

    for (int i = 0; i < LIGHT_PRECISION; i++)
    {
        int nVertices = 0;
        float angle = 2*M_PI/LIGHT_PRECISION * i;
        float nextAngle = 2*M_PI/LIGHT_PRECISION * (i+1);
        int n = i + 1;
        if (n == LIGHT_PRECISION)
            n = 0;

        vertices[nVertices] = ccpAdd(mid, ccp(cosf(angle) * radius * lightLength[i], sinf(angle) * radius * lightLength[i]));
        colors[nVertices++] = (ccColor4F){1, 1, .9, initialAlpha * (1 - lightLength[i])};
        vertices[nVertices] = ccpAdd(mid, ccp(cosf(nextAngle) * radius * lightLength[n], sinf(nextAngle) * radius * lightLength[n]));
        colors[nVertices++] = (ccColor4F){1, 1, .9, initialAlpha * (1 - lightLength[n])};
        vertices[nVertices] = mid;
        colors[nVertices++] = (ccColor4F){1, 1, .8, initialAlpha};

        ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position  | kCCVertexAttribFlag_Color);

        glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vertices);
        glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_FLOAT, GL_FALSE, 0, colors);
        glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
        glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)nVertices);
    }

    [lightRender end];
#define CC_NODE_DRAW_SETUP()                                                                    \
do {                                                                                            \
    ccGLEnable( _glServerState );                                                               \
    NSAssert1(_shaderProgram, @"No shader program set for node: %@", self);                     \
    [_shaderProgram use];                                                                       \
    [_shaderProgram setUniformsForBuiltins];                                    \
} while(0)