通过 OpenGL ES 显示视频的方法:
(注意, 这里需要用到 <<iPhone 开发基础教程>> 12 章中的示例代码中的两个类: OpenGLES2DView, Texture2D, 具体请参考相关的资料)
由于时间关系, 记录比较简单 (可通过 anyou@qq.com 联系我)
1 - (void) draw {
2
3 if (fBitmapBuffer == nil) {
4 return;
5 }
6
7 glLoadIdentity();
8 glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
9 glClear(GL_COLOR_BUFFER_BIT);
10
11 if (self.sprite) {
12 [self.sprite release];
13 self.sprite = nil;
14 }
15
16 char* bitmap = [self getBitmapBuffer];
17
18 if (self.sprite == nil) {
19 CGSize size = CGSizeMake(self.width, self.height);
20 self.sprite = [[Texture2D alloc] initWithData:bitmap
21 pixelFormat:kTexture2DPixelFormat_RGBA8888
22 pixelsWide:512 pixelsHigh:512 contentSize:size];
23 }
24
25 if (self.sprite) {
26 glEnable(GL_TEXTURE_2D);
27 int width = self.bounds.size.width;
28 //int height = self.bounds.size.height;
29 if (width <= 320) {
30 //[self.sprite drawAtPoint:CGPointMake(170, 224)];
31 [self.sprite drawInRect:CGRectMake(0, 0, 320, 240)];
32
33 } else {
34 [self.sprite drawInRect:CGRectMake(0, 0, 320, 240)];
35 }
36
37 }
38
39 glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
40 [context presentRenderbuffer:GL_RENDERBUFFER_OES];
41 }