- GLuint positionFramebuffer, positionRenderbuffer, positionRenderTexture;
- glEnable(GL_TEXTURE_2D);
- glDisable(GL_DEPTH_TEST);
- // Offscreen position framebuffer object
- glGenFramebuffers(1, &positionFramebuffer);
- glBindFramebuffer(GL_FRAMEBUFFER, positionFramebuffer);
- glRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA8_OES, 2, 2);
- glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, positionRenderbuffer);
- // Offscreen position framebuffer texture target
- glGenTextures(1, &positionRenderTexture);
- glBindTexture(GL_TEXTURE_2D, positionRenderTexture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_FLOAT, X);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, positionRenderTexture, 0);
- // and read back
- // Update uniform values
- static const GLfloat squareVertices[] = {
- -1.0f, -1.0f,
- 1.0f, -1.0f,
- -1.0f, 1.0f,
- 1.0f, 1.0f,
- };
- static const GLfloat textureVertices[] = {
- 1.0f, 1.0f,
- 1.0f, 0.0f,
- 0.0f, 1.0f,
- 0.0f, 0.0f,
- };
- GLfloat thresholdColor[3];
- thresholdColor[0] = 0.89f;
- thresholdColor[1] = 0.78f;
- thresholdColor[2] = 0.0f;
- GLfloat thresholdSensitivity = 0.7f;
- glUniform1i(uniforms[UNIFORM_VIDEOFRAME], 0);
- glUniform4f(uniforms[UNIFORM_INPUTCOLOR], thresholdColor[0], thresholdColor[1], thresholdColor[2], 1.0f);
- glUniform1f(uniforms[UNIFORM_THRESHOLD], thresholdSensitivity);
- // Update attribute values.
- glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, squareVertices);
- glEnableVertexAttribArray(ATTRIB_VERTEX);
- glVertexAttribPointer(ATTRIB_TEXTUREPOSITON, 2, GL_FLOAT, 0, 0, textureVertices);
- glEnableVertexAttribArray(ATTRIB_TEXTUREPOSITON);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glReadPixels(0, 0, rows, cols,GL_RGBA,GL_FLOAT,output);
- for (int i=0; i<rows*cols; i++) {
- NSLog(@"O[%d]=%f", i, output[i]);
- }