Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (void)prepareOpenGL
- {
- GLint swapInt = 1;
- stimGLContext = [self openGLContext];
- [stimGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
- // Create a display link capable
- CVDisplayLinkCreateWithCGDisplay(self.displayID, &displayLink);
- // Set the renderer output callback function
- CVDisplayLinkSetOutputCallback(
- displayLink,
- &MyDisplayLinkCallback,
- (__bridge void *)(self));
- // Set the display link for the current renderer
- CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
- CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
- CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(
- displayLink,
- cglContext,
- cglPixelFormat);
- // Activate the display link
- CVDisplayLinkStart(displayLink);
- }
- // Renderer output callback function
- static CVReturn MyDisplayLinkCallback(
- CVDisplayLinkRef displayLink,
- const CVTimeStamp* now,
- const CVTimeStamp* outputTime,
- CVOptionFlags flagsIn,
- CVOptionFlags* flagsOut,
- void* displayLinkContext)
- {
- CVReturn result = [(__bridge StimulusGLView*)displayLinkContext getFrameForTime:outputTime];
- return result;
- }
- - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime
- {
- /* We are on a secondary "CVDisplayLink" thread here. */
- NSOpenGLContext* context = [self openGLContext];
- [context makeCurrentContext];
- CGLLockContext([context CGLContextObj]);
- [self draw] ;
- CGLFlushDrawable([context CGLContextObj]);
- CGLUnlockContext([context CGLContextObj]);
- return kCVReturnSuccess;
- }
- - (void)draw
- {
- // Clear out and show a solid blue background
- glClearColor((GLclampf)0, (GLclampf), (GLclampf).8, 0);
- glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
- ... more glXxxxx() drawing statements follow here
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement