2013-05-25 2 views
0

친애하는 Stackoverflowers,Fragmentshader 및 프레임 버퍼 단색

최근

내가 OpenTK와 C#으로 GLSL 및 OpenGL을 사용하여, 쉐이더의 세계에 첫 아기 단계를 만들어왔다, 그리고 나는 것 몇 가지 문제가 발견했습니다 해결할 수 없게된다.

그럼 내가 어떤 종류를 추가하고 싶었 :

나는 나에게 다음과 같은 결과 (삼각형 돌고 단지 녹색과 붉은 빛을)주는 하나 개의 쉐이더 프로그램과 잘 작동 일부 빠른 실험 쉐이더 진형 이것에 빛을 내고 조각 쉐이더를 텍스처에 적용해야한다고 들었습니다. 그래서 나는 장면을 프레임 버퍼로 설정했다. 그런 다음 프레임 버퍼 텍스처를 바인딩하고 쿼드를 그렸습니다. 이것은 나에게 이전에 있었던 것과 같은 장면을 보여 주었다. 그런 다음 새 프래그먼트 쉐이더를 사용하기 위해 버퍼에 쓴 후 쿼드를 작성하기 전에 새 쉐이더 프로그램을 새 프로그램으로 교체합니다. 이제 문제는 내가하는 화면이 단색 만 제공한다는 것입니다. 원하는대로 조작하지 않아도됩니다.

이 내 그림 코드 :

//vertex shader 
#version 330 

layout (location = 0) in vec3 Position; 
varying vec2 texCoord; 

void main() 
{ 
    gl_Position = vec4(Position.x, Position.y, Position.z, 1.0); 
    texCoord = gl_TexCoord[0].st; 
} 

//fragment shader 
#version 330 

uniform sampler2D tex; 
out vec4 FragColor; 
varying vec2 texCoord; 

void main() 
{ 
    vec4 color = texture2D(tex, texCoord); 
    color.r += 0.5f; 
    FragColor = color; 
} 

이 대신 기존의 이미지를 붉은 색조를주는, 단색 빨강 색 결과 :

protected override void OnRenderFrame(FrameEventArgs e) 
    { 
     GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, fboID); 
     GL.UseProgram(shaderProgramHandle); 
     GL.PushAttrib(AttribMask.ViewportBit); 
     { 
      GL.Viewport(0, 0, 600, 600); 

      // clear the screen in green, to make it very obvious what the clear affected. only the FBO, not the real framebuffer 
      GL.ClearColor(0.0f, 0.0f, 0.0f, 1.0f); 
      GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit); 

      GL.PushAttrib(AttribMask.ColorBufferBit); 

      // make sure no lingering textures are bound to draw vertices clearly. 
      GL.BindTexture(TextureTarget.Texture2D, 0); 

      GL.EnableVertexAttribArray(0); 
      GL.BindBuffer(BufferTarget.ArrayBuffer, vbo); 
      GL.VertexAttribPointer(0, 3, VertexAttribPointerType.Float, false, 0, 0); 
      GL.DrawArrays(BeginMode.Triangles, 0, 3); 

      GL.DisableVertexAttribArray(0); 

      GL.Begin(BeginMode.Points); 
      GL.Vertex3(lmp); 
      GL.Vertex3(lmp2); 
      GL.End(); 

      GL.PopAttrib(); 
     } 
     GL.PopAttrib(); 

     GL.Ext.BindFramebuffer(FramebufferTarget.FramebufferExt, 0); 

     angle += 0.01f; 
     angle2 -= 0.017f; 
     lmp = new Vector3((float)(2f * Math.Cos(angle)), (float)(Math.Sin(angle) * 2f), 0f); 
     lmp2 = new Vector3((float)(2f * Math.Cos(angle2)), (float)(Math.Sin(angle2) * 2f), 0f); 
     GL.Uniform3(uniformLmp, lmp); 
     GL.Uniform3(uniformLmp2, lmp2); 

     GL.UseProgram(secondProgram); 
     GL.Enable(EnableCap.Texture2D); 
     GL.ActiveTexture(TextureUnit.Texture0); 
     GL.BindTexture(TextureTarget.Texture2D, fboTex); 
     GL.Uniform1(GL.GetUniformLocation(secondProgram, "tex"), fboTex); 

     GL.Clear(ClearBufferMask.ColorBufferBit); 

     GL.Begin(BeginMode.TriangleStrip); 

     GL.TexCoord2(.0f, .0f); 
     GL.Vertex3(-1f, -1f, 0f); 

     GL.TexCoord2(1.0f, .0f); 
     GL.Vertex3(1f, -1f, 0f); 

     GL.TexCoord2(.0f, 1.0f); 
     GL.Vertex3(-1f, 1f, 0f); 

     GL.TexCoord2(1.0f, 1.0f); 
     GL.Vertex3(1f, 1f, 0f); 

     GL.End(); 
     GL.Disable(EnableCap.Texture2D); 
     GL.UseProgram(0); 

     SwapBuffers(); 
    } 

그리고이 내 쉐이더입니다.

아무도이 문제를 발견 할 수 있습니까?

+0

'color.r + = 0.5f;'줄을 제거하면 이미지가 올바르게 표시됩니까? OpenGL과 GLSL을 배운다면 3.2 이상의 핵심 기능을 배우고 더 이상 사용되지 않는 부분은 피하도록 제안합니다 (예 :'varying'가 사용되지 않음) –

답변

0

내가 이렇게이 이상한 행동을 설명, 그것은 단지 (0,0)에서 샘플을 만들고,이 내 UV의 좌표는 쉐이더에 전달되지 않았 음을 의미

GL.EnableClientState(ArrayCap.TextureCoordArray); 

를 잊어 버린 것으로 나타났다.