cocos2dx android 环境报错 记录
2015-07-09 13:43
716 查看
最近 在 给 公司 做 一些 shader 特效 的 demo,所以 移植到 android 环境下 看效果,在 移植 过程中 遇到 一些 错误,希望 作为 备忘录 以及 供其他 网友 参考。
1.cocos2d-x发生undefined reference
to `XX'错误
解决方案:cocos2dx 增加 自定义类,在 android 环境 编译 ,需要 在 安卓 工程目录下的 /jni/Android.mk 里 添加 自定义类的 目录
参考网址:http://blog.csdn.net/kafeidev/article/details/9157895
还有据说 是 一劳永逸的 办法: http://blog.csdn.net/gf771115/article/details/34414449(没试过)
2.'nullptr' was not declared in this scope错误
解决方案:这是由于 ndk 不支持 c++ 11,所以 需要 将 其 改 为 Null
3.max is not
declared in thisscope
解决方案: 好像 没有 max 函数 ,#include <cmath> 然后 使用 fmax 就ok 了
4. shader 报错,在 vs 里 不报错,在 eclipse 里 编译 报错。。。
之前 错误代码:
<pre name="code" class="cpp">//varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform float u_radius;
uniform vec2 u_touchPos;
uniform vec2 u_bgSize;
uniform sampler2D CC_Texture0;
int isInCircle(){
vec2 pos = u_bgSize * v_texCoord;
float dis = distance(pos,u_touchPos);
if(dis >= u_radius || u_radius == 0)
return 1;
else
return 0;
}
void main()
{
vec4 texColor = texture2D(CC_Texture0, v_texCoord);
int isIn = isInCircle();
gl_FragColor = texColor * isIn;
}
主要 错误 原因 是 shader 是 强类型操作,不支持 不同类型 在一起 运算(包括 判等)
错误 主要 表现在
1. isIncircle 函数,返回 int 结果 却与 浮点类型的 texColor进行 操作
2. isIncircle 函数内部,, if(dis >= u_radius || u_radius == 0) 这一句,u_radius 是 一个 float 类型,结果 却 与 整形 值0 进行判等
下面 贴出 我修改过的代码:
//varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform float u_radius;
uniform vec2 u_touchPos;
uniform vec2 u_bgSize;
uniform sampler2D CC_Texture0;
float isInCircle(){
vec2 pos = u_bgSize * v_texCoord;
float dis = distance(pos,u_touchPos);
if(dis >= u_radius || u_radius == 0.0)
return 1.0;
else
return 0.0;
}
void main()
{
vec4 texColor = texture2D(CC_Texture0, v_texCoord);
float isIn = isInCircle();
gl_FragColor = texColor * isIn;
}
再次 鄙视一下 WINDOWS 平台,真 坑爹。。。。
5.cocos2dx 的 分辨率 模式 总是 让人 很蛋疼。。总会 出 各种 坐标 问题
这点 可能 是我 自己的 原因,对 cocos2dx 的 设计分辨率 了解 不清。
其实 这 跟 自己 不懂 coocs2dx 底层 原理 有 很大的 关系。
幸好 现在 公司 项目 要 用到openGl,正好 可以 恶补一下。
1.cocos2d-x发生undefined reference
to `XX'错误
解决方案:cocos2dx 增加 自定义类,在 android 环境 编译 ,需要 在 安卓 工程目录下的 /jni/Android.mk 里 添加 自定义类的 目录
参考网址:http://blog.csdn.net/kafeidev/article/details/9157895
还有据说 是 一劳永逸的 办法: http://blog.csdn.net/gf771115/article/details/34414449(没试过)
2.'nullptr' was not declared in this scope错误
解决方案:这是由于 ndk 不支持 c++ 11,所以 需要 将 其 改 为 Null
3.max is not
declared in thisscope
解决方案: 好像 没有 max 函数 ,#include <cmath> 然后 使用 fmax 就ok 了
4. shader 报错,在 vs 里 不报错,在 eclipse 里 编译 报错。。。
之前 错误代码:
<pre name="code" class="cpp">//varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform float u_radius;
uniform vec2 u_touchPos;
uniform vec2 u_bgSize;
uniform sampler2D CC_Texture0;
int isInCircle(){
vec2 pos = u_bgSize * v_texCoord;
float dis = distance(pos,u_touchPos);
if(dis >= u_radius || u_radius == 0)
return 1;
else
return 0;
}
void main()
{
vec4 texColor = texture2D(CC_Texture0, v_texCoord);
int isIn = isInCircle();
gl_FragColor = texColor * isIn;
}
主要 错误 原因 是 shader 是 强类型操作,不支持 不同类型 在一起 运算(包括 判等)
错误 主要 表现在
1. isIncircle 函数,返回 int 结果 却与 浮点类型的 texColor进行 操作
2. isIncircle 函数内部,, if(dis >= u_radius || u_radius == 0) 这一句,u_radius 是 一个 float 类型,结果 却 与 整形 值0 进行判等
下面 贴出 我修改过的代码:
//varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform float u_radius;
uniform vec2 u_touchPos;
uniform vec2 u_bgSize;
uniform sampler2D CC_Texture0;
float isInCircle(){
vec2 pos = u_bgSize * v_texCoord;
float dis = distance(pos,u_touchPos);
if(dis >= u_radius || u_radius == 0.0)
return 1.0;
else
return 0.0;
}
void main()
{
vec4 texColor = texture2D(CC_Texture0, v_texCoord);
float isIn = isInCircle();
gl_FragColor = texColor * isIn;
}
再次 鄙视一下 WINDOWS 平台,真 坑爹。。。。
5.cocos2dx 的 分辨率 模式 总是 让人 很蛋疼。。总会 出 各种 坐标 问题
这点 可能 是我 自己的 原因,对 cocos2dx 的 设计分辨率 了解 不清。
其实 这 跟 自己 不懂 coocs2dx 底层 原理 有 很大的 关系。
幸好 现在 公司 项目 要 用到openGl,正好 可以 恶补一下。
相关文章推荐
- C++爱好者博客
- 使用匿名名称空间需要注意事项
- Qt出现错误“undefined reference to `vtable for 错误
- android ndk添加打印 解决undefined reference to __android_log_print'问题
- uboot_1.1.6学习1_undefined reference to "raise"
- 编译器错误:/tmp/ccyOgqYQ.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0' collect2: ld r
- NDK编译C++库,
- Linux上C语言标准数学函数库的引用
- error: undefined reference to 'typeinfo for FileDialogDelegate'
- 编译内核出现问题: undefined reference to `__gnu_mcount_nc'
- linux keyring使用方法 密钥保留服务
- linux编译undefined reference to "xxxxx"
- g++编译时对'xxxx'未定义的引用问题(undefined reference to)
- UBUNTU16.04 caffe 配置问题
- include/opencv2/core/cvstd.hpp:647: undefined reference to `cv::String::deallocate()'
- glib交叉编译
- Android studio中JNI-NDK开发打印LOG出现 undefined reference to `__android_log_print' 解决
- pow函数gcc编译提示 undefined reference to `power' 的解决办法
- undefined reference问题排查
- ubuntu下安装gdal及安装好后出现 undefined reference to `问题