0

我是 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);

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

任何人都可以建议我的好方法。如果我做错了请指出。

提前致谢。

4

1 回答 1

0

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

于 2012-08-20T13:00:03.013 回答