Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Mac OpenGL 3.2 white screen

  1. #1
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    6

    Mac OpenGL 3.2 white screen

    Hi Forum,

    i try to set the Pixel Format for my NSOpenGLView.
    But I only get a white screen.

    Code :
    #import <Cocoa/Cocoa.h>
     
    #import <OpenGL/gl.h>
    #import <OpenGL/OpenGL.h>
    #import <QuartzCore/CVDisplayLink.h>
     
    @interface OpenGLView : NSOpenGLView
    {
        CVDisplayLinkRef dlDisplayLink;
    }

    Code :
    #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

    The screen should be blue. glCloarColor(0.0, 0.0, 1.0, 1.0)

  2. #2
    Member Regular Contributor
    Join Date
    Aug 2008
    Posts
    381
    You appear to be using double buffering, but you seem to never swap buffers.

    I'm using Windows + have no objective c experience, but searching the internet I found this link: https://developer.apple.com/library/...LFlushDrawable , so looking at your code, perhaps instead of glFlush() you need to use something like:
    Code :
    CGLFlushDrawable([[self openGLContext] CGLContextObj]);

  3. #3
    Junior Member Newbie
    Join Date
    Jul 2012
    Posts
    6
    Thank you very much!!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •