2013-05-27 1 views
2

저는 .NET 용 OpenTK 라이브러리를 사용하여 OpenGL과 함께 작업하면서 내 엔진을 작성했습니다. 나는 3 개의 다른 물체, 하나의 방사 큐브 및 2 개의 인접한 큐브를 배치했다. 개체의 윗부분에서 쿼드의 색을 바꿀 때까지 모든 것이 잘 작동하는 것처럼 보였습니다. (가) 배면의 블록은 앞의 블록상에서 렌더링되는 왼쪽OpenGL의 삼각형이 자신 앞에있는 삼각형의 꼭대기에 렌더링되지 않게하는 방법

Rendering Error

내가 녹색 상단 큐브 렌더링하고있다. 카메라가 올바르게 렌더되는 다른면을 보도록 설정되어있을 때, 내가 잘못하고있는 부분을 찾을 수없는 것 같습니다.

다음은 생략 관련 또는 무관 무관 방법, 특성 및 속성이 클래스 코드이다

GameState.cs

class GameState : State 
{ 
    // TEMP: Test Block 
    SimpleBlock block; 

    int i = 0; 
    public override void Render() 
    { 
     base.Render(); 

     // Set OpenGL Settings 
     GL.Viewport(0, 0, 1024, 768); 
     GL.Enable(EnableCap.CullFace); 

     // Reset the Matrices 
     Matrices.ClearMatrices(); 

     // Set Camera Settings (Field of view in radians) 
     Matrices.ProjectionMatrix = Matrix4.CreatePerspectiveFieldOfView((float)Math.PI/2, (1024.0f/768.0f), 1, 1000); 

     // Create the Camera 
     // this has to be in reverse 
     Matrix4 viewMatrix = Matrix4.CreateRotationX((float)Math.PI/8); 
     viewMatrix = viewMatrix.Translate(0, -2, -4); 

     // Multiply it with the ModelView (Which at this point is set to a value that we can just use = and it has the same result) 
     Matrices.ModelViewMatrix = viewMatrix; 

     // Render the Block 
     Matrices.Push(); 

     Matrices.ModelViewMatrix = Matrices.ModelViewMatrix.Translate(2, 0, 0); 
     Matrices.ModelViewMatrix = Matrices.ModelViewMatrix.Translate(0.5f, 0, 0.5f); 
     Matrices.ModelViewMatrix = Matrices.ModelViewMatrix.Rotate(0, i/40.0f, 0); 
     block.Render(); 

     Matrices.Pop(); 

     // Render the Block Again Twice 
     Matrices.Push(); 

     Matrices.ModelViewMatrix = Matrices.ModelViewMatrix.Translate(-2, 0, 0); 
     Matrices.ModelViewMatrix = Matrices.ModelViewMatrix.Translate(0.5f, 0, 0.5f); 
     block.Render(); 

     Matrices.ModelViewMatrix = Matrices.ModelViewMatrix.Translate(0, 0, -1); 
     block.Render(); 

     Matrices.Pop(); 

     // Increment Rotation Test Variable 
     i++; 
    } 
} 

SimpleBlock.cs는

class SimpleBlock : IBlock 
{ 
    public void Render() 
    { 
     // Send the Shader Parameters to the GPU 
     Shader.Bind(); 
     Shader.SendMatrices(); 

     // Begin Rendering the Polys 
     GL.Begin(BeginMode.Triangles); 

     // Front Quad 
     Shader.SetColor(Color4.SaddleBrown); 
     GL.Normal3(0, 0, 1); 
     GLUtils.QuadVertices(
      new Vector3(-0.5f, 1, 0.5f), 
      new Vector3(-0.5f, 0, 0.5f), 
      new Vector3(0.5f, 1, 0.5f), 
      new Vector3(0.5f, 0, 0.5f)); 

     // Right Quad 
     GL.Normal3(1, 0, 0); 
     GLUtils.QuadVertices(
      new Vector3(0.5f, 1, 0.5f), 
      new Vector3(0.5f, 0, 0.5f), 
      new Vector3(0.5f, 1, -0.5f), 
      new Vector3(0.5f, 0, -0.5f)); 

     // Back Quad 
     GL.Normal3(0, 0, -1); 
     GLUtils.QuadVertices(
      new Vector3(0.5f, 1, -0.5f), 
      new Vector3(0.5f, 0, -0.5f), 
      new Vector3(-0.5f, 1, -0.5f), 
      new Vector3(-0.5f, 0, -0.5f)); 

     // Left Quad 
     GL.Normal3(-1, 0, 0); 
     GLUtils.QuadVertices(
      new Vector3(-0.5f, 1, -0.5f), 
      new Vector3(-0.5f, 0, -0.5f), 
      new Vector3(-0.5f, 1, 0.5f), 
      new Vector3(-0.5f, 0, 0.5f)); 

     // Bottom Quad 
     GL.Normal3(0, -1, 0); 
     GLUtils.QuadVertices(
      new Vector3(-0.5f, 0, 0.5f), 
      new Vector3(-0.5f, 0, -0.5f), 
      new Vector3(0.5f, 0, 0.5f), 
      new Vector3(0.5f, 0, -0.5f)); 

     // Top Quad 
     Shader.SetColor(Color4.Green); 
     GL.Normal3(0, 1, 0); 
     GLUtils.QuadVertices(
      new Vector3(-0.5f, 1, -0.5f), 
      new Vector3(-0.5f, 1, 0.5f), 
      new Vector3(0.5f, 1, -0.5f), 
      new Vector3(0.5f, 1, 0.5f)); 

     // Done! 
     GL.End(); 
    } 
} 

BasicFragment.glfs

#version 130 

// MultiColor Attribute 
in vec4 multiColor; 

// Output color 
out vec4 gl_FragColor; 

void main() 
{ 
    // Set fragment 
    gl_FragColor = multiColor; 
} 

BasicVertex.glvs

#version 130 

// Transformation Matrices 
uniform mat4 ProjectionMatrix; 
uniform mat4 ModelViewMatrix; 

// Vertex Position Attribute 
in vec3 VertexPos; 

// MultiColor Attributes 
in vec4 MultiColor; 
out vec4 multiColor; 

void main() 
{ 
    // Process Colors 
    multiColor = MultiColor; 

    // Process Vertex 
    gl_Position = ProjectionMatrix * ModelViewMatrix * vec4(VertexPos.x, VertexPos.y, VertexPos.z, 1); 
} 

MainWindow.cs 당신이 깊이 테스트를 가능하게하는 것을 잊지 않았다 것 같다

// Extends OpenTK's GameWindow Class 
class MainWindow : GameWindow 
{ 
    public MainWindow() 
     : base(1024, 768, new GraphicsMode(32, 0, 0, 4)) 
    { 
     this.Title = "Trench Wars"; 
     this.WindowBorder = WindowBorder.Fixed; 
     this.ClientSize = new Size(1024, 768); 

     // Set VSync On 
     this.VSync = VSyncMode.Adaptive; 
    } 

    protected override void OnRenderFrame(FrameEventArgs e) 
    { 
     base.OnRenderFrame(e); 

     // Clear Screen 
     GL.ClearColor(Color4.CornflowerBlue); 
     GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); 

     // Do State-Specific Rendering 
     StateEngine.Render(); 

     // Pull a Wicked Bluffing move in Poker 
     GL.Flush(); 

     // Swap Buffers 
     this.SwapBuffers(); 
    } 
} 
+0

문제를 더 명확하게 설명해 주시겠습니까? 나는 이해하지 못한다. 그것은 이미지에서 잘 보인다. – Nicola

+0

저는 녹색 꼭대기가있는 완벽한 큐브를 렌더링하고 있습니다. 왼쪽에있는 블록이 앞에있는 블록 위에 렌더링되고 있습니다. (이것을 아래에 추가하겠습니다) –

+0

렌더링 할 프레임 버퍼에 문제가있을 수 있습니까? – Grimmy

답변

1

. 도형을 렌더링하기 전에 glEnable(GL_DEPTH_TEST)을 친구 (또는 사용중인 언어 바인딩이 GL.Enable(EnableCap.DepthTest); 인 경우)로 지정하십시오.

+0

"GL.Enable (EnableCap.CullFace);"에 추가, 변경하지 않았습니다. –

+0

버텍스 쉐이더에서 깊이 정보로 무엇인가를해야합니까? 왜냐하면 내가 지금 그렇게하지 않기 때문이야. –

+0

@KelvinBongers : 아니요, 필요한 쉐이더는 없습니다. 그러나 깊이 구성 요소없이 창을 만들었을 수도 있습니다. 또한 코드에서 프레임 버퍼를 지우는 호출이 표시되지 않습니다. 질문을 창 만들기에 사용하는 코드로 업데이트하고 색상 및 깊이 버퍼를 지우는 glClear 호출이 있는지 확인하십시오. – datenwolf

관련 문제