Hallo Entwickler,
damit ich OpenGL 3.2 nutzen kann, habe das das Pixel Format verändert.
Seitdem bekomme ich keine Bildschirmausgabe mehr (nur ein weißes Fenster).
Das OpenGLView wurde im IB erstellt und platziert.
Alles anzeigen
Das Fenster sollte doch wenigstens blau sein (wegen glClearColor(0.0, 0.0, 0.0, 1.0, 1.0)).
damit ich OpenGL 3.2 nutzen kann, habe das das Pixel Format verändert.
Seitdem bekomme ich keine Bildschirmausgabe mehr (nur ein weißes Fenster).
Das OpenGLView wurde im IB erstellt und platziert.
Quellcode
- #import "OpenGLView.h"
- @interface OpenGLView()
- - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime;
- @end
- @implementation OpenGLView
- - (void) awakeFromNib
- {
- NSOpenGLPixelFormatAttribute pfaAttributes[] = {NSOpenGLPFADoubleBuffer, NSOpenGLPFADepthSize, 24, NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, 0};
- @autoreleasepool
- {
- NSOpenGLPixelFormat *pfPixelFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:pfaAttributes];
- NSOpenGLContext* glcContext = [[NSOpenGLContext alloc] initWithFormat:pfPixelFormat shareContext:nil];
- [self setPixelFormat:pfPixelFormat];
- [self setOpenGLContext:glcContext];
- }
- }
- - (void)prepareOpenGL
- {
- [super prepareOpenGL];
- [[self openGLContext] makeCurrentContext];
- GLint iSwap = 1;
- [[self openGLContext] setValues:&iSwap forParameter:NSOpenGLCPSwapInterval];
- glClearColor(0.0, 0.0, 1.0, 1.0); // Bild blau
- glViewport(0, 0, (GLsizei) self.bounds.size.width, (GLsizei) self.bounds.size.height);
- [[self openGLContext] setValues:&iSwap forParameter:NSOpenGLCPSwapInterval];
- CVDisplayLinkCreateWithActiveCGDisplays(&dlDisplayLink);
- CVDisplayLinkSetOutputCallback(dlDisplayLink, &DisplayLinkCallback, (__bridge void *) self);
- CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
- CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
- CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(dlDisplayLink, cglContext, cglPixelFormat);
- CVDisplayLinkStart(dlDisplayLink);
- }
- - (void)reshape
- {
- [super reshape];
- CGLLockContext([[self openGLContext] CGLContextObj]);
- glViewport(0, 0, (GLsizei) self.bounds.size.width, (GLsizei) self.bounds.size.height);
- CGLUnlockContext([[self openGLContext] CGLContextObj]);
- }
- - (void)renderScene
- {
- [[self openGLContext] makeCurrentContext];
- CGLLockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
- // Render - Start
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glFlush();
- // Render - Ende
- CGLUnlockContext((CGLContextObj)[[self openGLContext] CGLContextObj]);
- }
- static CVReturn DisplayLinkCallback(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
Das Fenster sollte doch wenigstens blau sein (wegen glClearColor(0.0, 0.0, 0.0, 1.0, 1.0)).