Shader程序在Cocos2d 2.2 Obj.C iOS 12中不起作用 [英] Shader Program not working in Cocos2d 2.2 Obj.C iOS 12

查看:136
本文介绍了Shader程序在Cocos2d 2.2 Obj.C iOS 12中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

代码:

  [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];

CC_NODE_DRAW_SETUP代码:

CC_NODE_DRAW_SETUP Code:

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

如何使用Cocos2d 2.2在iOS12中修复着色器代码Obj.C项目?如果我在iOS 7模拟器中运行,它可以完美运行..相同的代码在iOS 12中不起作用

How to fix shader code in iOS12 with Cocos2d 2.2 Obj.C project ? If I run in iOS 7 simulator it works perfect..same code not working in iOS 12

推荐答案

Cocos2d中的固定着色器问题。

Fixed Shaders Problem in Cocos2d.

在上面的代码中,主要问题是CGFloat ...将其转换为所有顶点都浮动。

In Above code, main problem is CGFloat...converted it to float for all vertices.

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

Also I took shaders related files from Cocos2d-x and converted it to obj.C for Cocos2d.

现在,所有着色器在Cocos2d v2.2 Obj.C iOS 12中都可以正常工作。 iPhoneX / XR / XSMax也是如此。

Now all shaders working Perfect in Cocos2d v2.2 Obj.C iOS 12, iPhoneX/XR/XSMax also..

快乐编码!干杯:)

这篇关于Shader程序在Cocos2d 2.2 Obj.C iOS 12中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆