Advertisement
JetForMe

Untitled

Sep 3rd, 2013
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. - (void)
  2. awakeFromNib
  3. {
  4.     [super awakeFromNib];
  5.    
  6.     //  Create a sample VBO…
  7.    
  8.     GLfloat vertices[] =
  9.     {
  10.         -0.8f, -0.8f, 0.0f, 1.0f,
  11.          0.0f,  0.8f, 0.0f, 1.0f,
  12.          0.8f, -0.8f, 0.0f, 1.0f,
  13.     };
  14.    
  15.     GLfloat colors[] =
  16.     {
  17.          1.0f,  0.0f, 0.0f, 1.0f,
  18.          0.0f,  1.0f, 0.0f, 1.0f,
  19.          0.0f,  0.0f, 1.0f, 1.0f,
  20.     };
  21.    
  22.     glGenVertexArraysAPPLE(1, &mVAO);
  23.     glBindVertexArrayAPPLE(mVAO);
  24.    
  25.     glGenBuffers(1, &mVBO);
  26.     glBindBuffer(GL_ARRAY_BUFFER, mVBO);
  27.     glBufferData(GL_ARRAY_BUFFER, sizeof (vertices), vertices, GL_STATIC_DRAW);
  28.     glVertexAttribPointer(0, 4, GL_FLOAT, GL_FALSE, 0, 0);
  29.     glEnableVertexAttribArray(0);
  30.  
  31.     glGenBuffers(1, &mColorBuffer);
  32.     glBindBuffer(GL_ARRAY_BUFFER, mColorBuffer);
  33.     glBufferData(GL_ARRAY_BUFFER, sizeof(colors), colors, GL_STATIC_DRAW);
  34.     glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, 0, 0);
  35.     glEnableVertexAttribArray(1);
  36.    
  37.     GLenum err = glGetError();
  38.     if (err != GL_NO_ERROR)
  39.     {
  40.         NSLog(@"Error creating VBO");
  41.     }
  42.    
  43.     //  Create the display link timer…
  44.    
  45.     GLint syncToVerticalRetrace = 1;
  46.     [self.openGLContext setValues: &syncToVerticalRetrace forParameter: NSOpenGLCPSwapInterval];
  47.    
  48.     CVDisplayLinkCreateWithActiveCGDisplays(&mDisplayLink);
  49.     CVDisplayLinkSetOutputCallback(mDisplayLink, RenderCVDisplay, (__bridge void*) self);
  50.    
  51.     CGLContextObj cglContext = self.openGLContext.CGLContextObj;
  52.     CGLPixelFormatObj cglPixelFormat = self.pixelFormat.CGLPixelFormatObj;
  53.     CVDisplayLinkSetCurrentCGDisplayFromOpenGLContext(mDisplayLink, cglContext, cglPixelFormat);
  54.    
  55.     CVDisplayLinkStart(mDisplayLink);
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement