1
我試圖在反應式本機應用程序中呈現opengl本機組件。目前我有一個空白的屏幕,我希望看到一個使用glClearColor的紅色矩形。代碼運行時沒有錯誤。 我是新來的目標c,所以有一些語法特性我可能會得到錯誤。但到目前爲止,這是我所擁有的。在反應本機中呈現開放式視圖
我定製 - 視圖 - manager.h
#import "RCTViewManager.h"
@interface myCustomViewManager : RCTViewManager
@end
我定製 - 視圖 - manager.m
#import "myCustomViewManager.h"
#import "myCustomView.h"
#import <UIKit/UIKit.h>
@implementation myCustomViewManager
RCT_EXPORT_MODULE();
- (UIView *)view
{
myCustomView * v;
v = [[myCustomView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
return v;
}
@end
我定製-view.h
#import <GLKit/GLKit.h>
#import <QuartzCore/QuartzCore.h>
#import <OpenGLES/ES2/gl.h>
#import <OpenGLES/ES2/glext.h>
@interface myCustomView : GLKView {
EAGLContext *context;
}
@end
my-custom-view.m
#import "myCustomView.h"
#import <UIKit/UIKit.h>
@implementation myCustomView
+ (Class)layerClass {
return [CAEAGLLayer class];
}
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
CAEAGLLayer *EAGLLayer = (CAEAGLLayer *) super.layer;
EAGLLayer.opaque = YES;
context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2];
if (!context || ![EAGLContext setCurrentContext:context]) {
NSLog(@"No context");
exit(1);
}
GLuint framebuffer, renderbuffer;
glGenBuffers(1, &framebuffer);
glGenBuffers(1, &renderbuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glBindRenderbuffer(GL_RENDERBUFFER, renderbuffer);
[context renderbufferStorage:GL_FRAMEBUFFER fromDrawable:EAGLLayer];
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, renderbuffer);
glViewport(0, 0, 200, 200);
[self render];
}
return self;
}
- (void)render
{
glClearColor(1.0, 0.0, 0.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
@end
任何人都可以幫忙,並幫助我得到這個呈現的東西。
感謝
亞當
乾杯是得到它的工作:) – adamdaly