如何在iPhone上生成Perlin Noise
我想在iPhone上创建一个动画的perlin噪音,所以我最终可以这样做:
http://dl.dropbox.com/u/1977230/example.png
我看了看,但找不到任何类似或实际显示Perlin噪音的方法. 我被告知要看OpenGL ES,但即使是搜索Perlin噪音或熔岩/等离子效应的例子也不会产生任何结果. 我真的很感激这方面的一些帮助. 多谢你们, 解决方法
好吧,首先研究Perlin Noise算法本身.
http://en.wikipedia.org/wiki/Perlin_noise看起来是最好的起飞地点.
一旦你获得了你的这种效果的RGBA数据,就会开始讨厌. 基本上有两种选择. >创建一个UIView子类并覆盖draw:(CGRect)方法.明智地使用Converting RGB data into a bitmap in Objective-C++ Cocoa从您的数据创建CGImage,并将该图像绘制到绘图中的当前上下文. CGContextDrawImage(UIGraphicsGetCurrentContext(),<#CGRect rect#>,<#CGImageRef image#>); 如果这是静止图像,你没问题.如果它是动画,这可能不是最好的解决方案. 该示例可以通过以下方式轻松扩展: 有这些定义: GLuint spriteTexture; GLubyte *spriteData; // the perlin noise will be here size_t width,height; 然后在ESRenderer init方法中为纹理创建空间: - (id) init { .... width = 512; // make sure the texture size is the power of 2 height = 512; glGenTextures(1,&spriteTexture); glBindTexture(GL_TEXTURE_2D,spriteTexture); glTexImage2D(GL_TEXTURE_2D,GL_RGBA,width,height,GL_UNSIGNED_BYTE,spriteData); //free(spriteData); // free this if not used any more glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); 如果定期更新噪声,请在render方法中更新纹理 - (void) render { ..... glBindTexture(GL_TEXTURE_2D,spriteTexture); glTexImage2D(GL_TEXTURE_2D,spriteData); 啊,我想念好的旧视频是在$A000天:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |