Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 19th, 2012  |  syntax: None  |  size: 2.30 KB  |  hits: 5  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.     GLuint positionFramebuffer, positionRenderbuffer, positionRenderTexture;
  2.     glEnable(GL_TEXTURE_2D);
  3.         glDisable(GL_DEPTH_TEST);
  4.    
  5.         // Offscreen position framebuffer object
  6.         glGenFramebuffers(1, &positionFramebuffer);
  7.     glBindFramebuffer(GL_FRAMEBUFFER, positionFramebuffer);
  8.        
  9.     glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, 2, 2);
  10.     glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, positionRenderbuffer);    
  11.    
  12.    
  13.         // Offscreen position framebuffer texture target
  14.         glGenTextures(1, &positionRenderTexture);
  15.     glBindTexture(GL_TEXTURE_2D, positionRenderTexture);
  16.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  17.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  18.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  19.     glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  20.         glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
  21.    
  22.     glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_FLOAT, X);
  23.    
  24.         glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, positionRenderTexture, 0);    
  25.    
  26.     // and read back
  27.         // Update uniform values
  28.     static const GLfloat squareVertices[] = {
  29.         -1.0f, -1.0f,
  30.         1.0f, -1.0f,
  31.         -1.0f,  1.0f,
  32.         1.0f,  1.0f,
  33.     };
  34.    
  35.         static const GLfloat textureVertices[] = {
  36.         1.0f, 1.0f,
  37.         1.0f, 0.0f,
  38.         0.0f,  1.0f,
  39.         0.0f,  0.0f,
  40.     };
  41.    
  42.     GLfloat thresholdColor[3];
  43.     thresholdColor[0] = 0.89f;
  44.     thresholdColor[1] = 0.78f;
  45.     thresholdColor[2] = 0.0f;
  46.     GLfloat thresholdSensitivity = 0.7f;
  47.    
  48.         glUniform1i(uniforms[UNIFORM_VIDEOFRAME], 0);  
  49.         glUniform4f(uniforms[UNIFORM_INPUTCOLOR], thresholdColor[0], thresholdColor[1], thresholdColor[2], 1.0f);
  50.         glUniform1f(uniforms[UNIFORM_THRESHOLD], thresholdSensitivity);
  51.    
  52.         // Update attribute values.
  53.         glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
  54.         glEnableVertexAttribArray(ATTRIB_VERTEX);
  55.         glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices);
  56.         glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON);
  57.        
  58.     glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
  59.    
  60.    
  61.     glReadPixels(0, 0, rows, cols,GL_RGBA,GL_FLOAT,output);
  62.    
  63.     for (int i=0; i<rows*cols; i++) {
  64.         NSLog(@"O[%d]=%f", i, output[i]);
  65.     }