从着色器渲染无效

时间:2014-09-18 07:35:09

标签: ios opengl-es

除了清除的颜色之外不会渲染任何

  glUseProgram(_rectificationShader.program);

  // do other things like assigning attributes

  glGenFramebuffers(1, &_internalFramebuffer);
  glBindFramebuffer(GL_FRAMEBUFFER, _internalFramebuffer);

  glActiveTexture(GL_TEXTURE0);
  glGenTextures(1, &_referenceTexture);
  glBindTexture(GL_TEXTURE_2D, _referenceTexture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RED_EXT, referenceImage.cols, referenceImage.rows, 0, GL_RED_EXT, GL_UNSIGNED_BYTE, referenceImageData);
  GLKMatrix3 homography1 = [Utility cvHomographyToOpenGL:H1];
  glUniformMatrix4fv(_rectificationShader.rectificationMatrix, 1, 0, homography1.m);
  glUniform1i(_rectificationShader.tex, GL_TEXTURE0);

  glActiveTexture(GL_TEXTURE1);
  glGenTextures(1, &_referenceRectifiedTexture);
  glBindTexture(GL_TEXTURE_2D, _referenceRectifiedTexture);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RED_EXT, width, height, 0, GL_RED_EXT, GL_UNSIGNED_BYTE, NULL);
  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _referenceRectifiedTexture, 0);
  GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);

  if (status != GL_FRAMEBUFFER_COMPLETE) {
    NSLog(@"failed to make complete framebuffer object %x", status);
    return NO;
  }

  glClearColor(0.5,0.5,0.5,1);
  glClear(GL_COLOR_BUFFER_BIT);
  glDrawArrays(GL_POINTS, 0, imageArea);

着色器(为调试而简化):

// Vertex Shader

static const char* rectificationVS = STRINGIFY
(
 attribute highp vec2 position;
 varying highp vec2 texCoords;

 void main(void)
 {
   gl_Position = vec4(position, 0, 1);
   texCoords = position.xy * vec2(0.5) + vec2(0.5);
 }

 );

// Fragment Shader

static const char* rectificationFS = STRINGIFY
(
 varying highp vec2 texCoords;
 uniform lowp sampler2D tex;

 void main(void)
 {
   gl_FragColor = vec4(1);
 }

 );

将位置输入到顶点着色器并从(-1,-1)变为(1,1)。有什么我想念的吗?如果我改变了清晰的颜色,我可以看到导出图像的变化(代码省略)。

0 个答案:

没有答案