Hallo Entwickler,
wieso bekomme ich bei folgendem Code nur ein weißes Fenster?
Alles anzeigen
Im Header ist der vertexBuffer und der Display Link.
wieso bekomme ich bei folgendem Code nur ein weißes Fenster?
Quellcode
- #import "OpenGLView.h"
- @interface OpenGLView()
- - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime;
- @end
- static const GLfloat vertexBufferData[] =
- {
- -1.0, -1.0, 0.0,
- 1.0, -1.0, 0.0,
- 0.0, 1.0, 0.0
- };
- @implementation OpenGLView
- - (void)prepareOpenGL
- {
- GLint swapInt = 1;
- [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
- CVDisplayLinkCreateWithActiveCGDisplays(&displayLink);
- CVDisplayLinkSetOutputCallback(displayLink, &MyDisplayLinkCallback, (__bridge void *) self);
- CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
- CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
- CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(displayLink, cglContext, cglPixelFormat);
- CVDisplayLinkStart(displayLink);
- // Init GL
- NSRect rect = self.bounds;
- glViewport(0, 0, (GLsizei)rect.size.width, (GLsizei)rect.size.height);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0, rect.size.width / rect.size.height, 1.0, 5.0);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glEnable(GL_DEPTH_TEST);
- glCullFace(GL_BACK);
- glEnable(GL_CULL_FACE);
- // Init Buffers
- glGenBuffers(1, &vertexBuffer);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBufferData), vertexBufferData, GL_STATIC_DRAW);
- }
- - (void)reshape
- {
- NSRect rect = self.bounds;
- glViewport(0, 0, (GLsizei)rect.size.width, (GLsizei)rect.size.height); glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(45.0, rect.size.width / rect.size.height, 1.0, 5.0 ); glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- }
- - (void)renderScene
- {
- [[self openGLContext] makeCurrentContext];
- CGLLockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
- // Render - Start
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, (void*) 0);
- glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(0);
- // Render - Ende
- CGLFlushDrawable((CGLContextObj)[[self openGLContext] CGLContextObj]);
- CGLUnlockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
- }
- static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTimeStamp* now, const CVTimeStamp* outputTime, CVOptionFlags flagsIn, CVOptionFlags* flagsOut, void* displayLinkContext)
- {
- return [(__bridge OpenGLView *)displayLinkContext getFrameForTime:outputTime];
- }
- - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime
- {
- @autoreleasepool
- {
- [self renderScene];
- }
- return kCVReturnSuccess;
- }
- @end
Im Header ist der vertexBuffer und der Display Link.