Rabu, 13 Maret 2019

Shader Program not working in Cocos2d 2.2 Obj.C iOS 12

CODE:


[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 Code:


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

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



from Shader Program not working in Cocos2d 2.2 Obj.C iOS 12

Shader Program not working in Cocos2d 2.2 Obj.C iOS 12 Rating: 4.5 Diposkan Oleh: Admin

0 komentar:

Posting Komentar

Popular Posts