- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在尝试重写 Apple 样本 GLCameraRipple代码,以图像为背景。实际上我正在尝试使用此代码在水图像上创建波纹效果,但代码适用于相机,相反我只想使用简单的水图像作为背景而不是相机。任何方向或任何示例代码都会有很大的帮助。提前致谢。
最佳答案
相机波纹效果的工作方式是它使三角形网格上的纹理坐标变形——所以好消息是您想要的效果与视频纹理完全不同;他们的纹理恰好是一个视频。要完成您想要的,您只需删除所有相机视频代码,并绑定(bind)您自己的纹理。
因此在 viewDidLoad 中,您将注释掉 [self setupAVCapture]
,然后继续在 SetupGL 中注释掉两个纹理制服,因为您将只使用一个(这两行是 glUniform1i(uniforms[UNIFORM_Y], 0);
, glUniform1i(uniforms[UNIFORM_UV], 1);
),然后创建并绑定(bind)你自己的纹理。
GLKit 是完成此类任务的最快方式。 GLKit 对您隐藏了很多 OpenGL 函数调用,但非常快速且有效。
//create the GLKTextureInfo object
NSError *error;
NSDictionary *options = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] forKey:GLKTextureLoaderOriginBottomLeft];
GLKTextureInfo *texture = [GLKTextureLoader textureWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"image" ofType:@"png"] options:options error:&error];
if (error) NSLog(@"Ripple FRONT TEXTURE ERROR: %@", error);
//bind the texture to texture unit 0
glActiveTexture(GL_TEXTURE0);
glBindTexture(texture.target, texture.name);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
现在您丢失了一些包含在 setupAVCapture 中的非常重要的设置。所以在viewDidLoad中把它放在上面代码之后:
if (_ripple == nil ||
texture.width != _textureWidth ||
texture.height != _textureHeight)
{
_textureWidth = texture.width;
_textureHeight = texture.height;
_ripple = [[RippleModel alloc] initWithScreenWidth:_screenWidth
screenHeight:_screenHeight
meshFactor:_meshFactor
touchRadius:5
textureWidth:_textureWidth
textureHeight:_textureHeight];
[self setupBuffers];
}
最后,您必须稍微更改片段着色器。
打开 Shader.fsh 并将主要功能更改为:
void main()
{
gl_FragColor = texture2D(SamplerY, texCoordVarying);
}
无论如何,应该这样做。试验 RippleModel 并看看您能做出什么样的古怪效果非常有趣。
关于iphone - 如何重写以图像为背景的 GLCameraRipple 样本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12372570/
我正在尝试修改 GLCameraRipple Apple 的示例应用程序,用于在后台线程上处理视频帧。在此示例中,它使用以下代码处理主线程上的每个帧: // Set dispatch to be on
我正在使用 GLCameraRipple example在我用 glTexImage2D 加载的静态图像上产生涟漪。 我使用自己的着色器,因为示例中的着色器用于从视频源中获取图像。 它响应触摸并在触摸
我正在尝试重写 Apple 样本 GLCameraRipple代码,以图像为背景。实际上我正在尝试使用此代码在水图像上创建波纹效果,但代码适用于相机,相反我只想使用简单的水图像作为背景而不是相机。任何
如何重写 Apple 的 GLCameraRipple example这样它就不需要 iOS 5.0 了吗? 我需要让它在 iOS 4.x 上运行,所以我不能使用 CVOpenGLESTextureC
我是一名优秀的程序员,十分优秀!