Advertisement
Guest User

Untitled

a guest
Sep 4th, 2015
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. - (void)prepareOpenGL
  2. {
  3. GLint swapInt = 1;
  4. stimGLContext = [self openGLContext];
  5. [stimGLContext setValues:&swapInt forParameter:NSOpenGLCPSwapInterval];
  6.  
  7. // Create a display link capable
  8. CVDisplayLinkCreateWithCGDisplay(self.displayID, &displayLink);
  9.  
  10. // Set the renderer output callback function
  11. CVDisplayLinkSetOutputCallback(
  12. displayLink,
  13. &MyDisplayLinkCallback,
  14. (__bridge void *)(self));
  15.  
  16. // Set the display link for the current renderer
  17. CGLContextObj cglContext = [[self openGLContext] CGLContextObj];
  18. CGLPixelFormatObj cglPixelFormat = [[self pixelFormat] CGLPixelFormatObj];
  19. CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(
  20. displayLink,
  21. cglContext,
  22. cglPixelFormat);
  23.  
  24. // Activate the display link
  25. CVDisplayLinkStart(displayLink);
  26. }
  27.  
  28. // Renderer output callback function
  29. static CVReturn MyDisplayLinkCallback(
  30. CVDisplayLinkRef displayLink,
  31. const CVTimeStamp* now,
  32. const CVTimeStamp* outputTime,
  33. CVOptionFlags flagsIn,
  34. CVOptionFlags* flagsOut,
  35. void* displayLinkContext)
  36. {
  37. CVReturn result = [(__bridge StimulusGLView*)displayLinkContext getFrameForTime:outputTime];
  38. return result;
  39. }
  40.  
  41. - (CVReturn)getFrameForTime:(const CVTimeStamp*)outputTime
  42. {
  43. /* We are on a secondary "CVDisplayLink" thread here. */
  44.  
  45. NSOpenGLContext* context = [self openGLContext];
  46. [context makeCurrentContext];
  47. CGLLockContext([context CGLContextObj]);
  48.  
  49. [self draw] ;
  50.  
  51. CGLFlushDrawable([context CGLContextObj]);
  52. CGLUnlockContext([context CGLContextObj]);
  53.  
  54. return kCVReturnSuccess;
  55. }
  56.  
  57. - (void)draw
  58. {
  59. // Clear out and show a solid blue background
  60. glClearColor((GLclampf)0, (GLclampf), (GLclampf).8, 0);
  61. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  62.  
  63. ... more glXxxxx() drawing statements follow here
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement