【问题标题】:How to give animation for the texture in open gl iphone?如何在opengl iphone中为纹理提供动画?
【发布时间】:2012-08-16 07:35:14
【问题描述】:

我是 iphone 开发新手。目前我正在开发一个使用 opengl 的项目,我需要为视图的一部分设置动画。为此,我拍摄了屏幕截图,然后创建了纹理。

这是我的代码

glEnable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glBlendFunc(GL_ONE, GL_SRC_COLOR);

UIGraphicsBeginImageContext(self.introductionTextLabel.frame.size);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

GLuint      texture[1];
glGenTextures(1, &texture[0]);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);

GLuint width = CGImageGetWidth(viewImage.CGImage);
GLuint height = CGImageGetHeight(viewImage.CGImage);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
void *imageData = malloc( height * width * 4 );
CGContextRef contextTexture = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big );

CGColorSpaceRelease( colorSpace );
CGContextClearRect( contextTexture, CGRectMake( 0, 0, width, height ) );
CGContextTranslateCTM( contextTexture, 0, height - height );
CGContextDrawImage( contextTexture, CGRectMake( 0, 0, width, height ), viewImage.CGImage );

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData);


CGContextRelease(contextTexture);

free(imageData);

我进行了很多搜索,但找不到为纹理提供动画的好方法。

谁能给我推荐一个好方法。如果我做错了,请指出。

提前致谢。

【问题讨论】:

    标签: iphone opengl-es-2.0 xcode4.3


    【解决方案1】:

    我建议您修改纹理的唯一方法是使用glTexImage2D() 进行全帧更新,使用glTexSubImage2D() 进行部分更新。当然,如果您将使用预加载和压缩类型的纹理会更好...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 2012-01-12
      相关资源
      最近更新 更多