Shader Program not working in Cocos2d 2.2 Obj.C iOS 12(着色器程序在 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 Obj.C 项目修复 iOS12 中的着色器代码?如果我在 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 中的 Shaders 问题.
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..
编码愉快!干杯:)
这篇关于着色器程序在 Cocos2d 2.2 Obj.C iOS 12 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:着色器程序在 Cocos2d 2.2 Obj.C iOS 12 中不起作用
基础教程推荐
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01