0

对不起我的英语我想在干净的 C 上绘制纹理,没有目标 c!有必要为ios / android编写一个库

我画

- (BOOL)createFramebuffer{
glGenFramebuffersOES(1, &viewFramebuffer);
glGenRenderbuffersOES(1, &viewRenderbuffer);

glBindFramebufferOES(GL_FRAMEBUFFER_OES, viewFramebuffer);
glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);

[context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];//a string
glFramebufferRenderbufferOES(GL_FRAMEBUFFER_OES, GL_COLOR_ATTACHMENT0_OES, GL_RENDERBUFFER_OES, viewRenderbuffer);

glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_WIDTH_OES, &backingWidth);
glGetRenderbufferParameterivOES(GL_RENDERBUFFER_OES, GL_RENDERBUFFER_HEIGHT_OES, &backingHeight);

if(glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES) != GL_FRAMEBUFFER_COMPLETE_OES) {
    NSLog(@"failed to make complete framebuffer object %x", glCheckFramebufferStatusOES(GL_FRAMEBUFFER_OES));
    return NO;
}

return YES;
}

- (void)drawView {


[EAGLContext setCurrentContext:context];//a string

glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, spriteTexture);

Byte *byteData = (Byte*)malloc(3686400);
memcpy(byteData, [texData bytes]+kon, 3686400);
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 1280, 720, GL_RGBA, GL_UNSIGNED_BYTE, byteData);
free(byteData);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

glBindRenderbufferOES(GL_RENDERBUFFER_OES, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER_OES];//a string
}

如何摆脱与目标 c 相关的这些行?

1 [context renderbufferStorage:GL_RENDERBUFFER_OES fromDrawable:(id<EAGLDrawable>)self.layer];
2 [EAGLContext setCurrentContext:context];
3 [context presentRenderbuffer:GL_RENDERBUFFER_OES];</code>
4

1 回答 1

1

你不能,并且仍然在 iOS 中将这个渲染到屏幕上。EAGLContext 是一个 Objective-C 对象,用于管理您的 OpenGL ES 上下文,您需要与它交互才能渲染和显示您的场景。

但是,您可以将对此的访问包装在一个函数中,该函数根据您的目标平台更改其内容。编译器条件可以帮助您做到这一点。

于 2013-02-12T16:06:55.987 回答