2010-04-02 5 views
0

SlimDX 라이브러리에 익숙해지기 위해 간단한 애플리케이션을 만들고 있습니다. MDX로 작성된 코드를 발견했으며 SlimDX에서 실행되도록 변환하려고합니다. 모든 것이 검은 색으로 표시되기 때문에 빛에 문제가 있습니다. 코드는 다음과 같습니다SlimDX : Direct3D9의 번개 문제

public partial class DirectTest : Form 
{ 
    private Device device= null; 
    private float angle = 0.0f; 
    Light light = new Light(); 

    public DirectTest() 
    { 
     InitializeComponent(); 

     this.Size = new Size(800, 600); 
     this.SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.Opaque, true); 
    } 
    /// <summary> 
    /// We will initialize our graphics device here 
    /// </summary> 
    public void InitializeGraphics() 
    { 
     PresentParameters pres_params = new PresentParameters() 
     { 
      Windowed = true, 
      SwapEffect = SwapEffect.Discard 
     }; 
     device = new Device(new Direct3D(), 0, DeviceType.Hardware, this.Handle, 
        CreateFlags.SoftwareVertexProcessing, pres_params); 
    } 

    private void SetupCamera() 
    { 
     device.SetRenderState(RenderState.CullMode, Cull.None); 
     device.SetTransform(TransformState.World, Matrix.RotationAxis(new Vector3(angle/((float)Math.PI * 2.0f), 
         angle/((float)Math.PI * 4.0f), angle/((float)Math.PI * 6.0f)), 
         angle/(float)Math.PI)); 
     angle += 0.1f; 
     device.SetTransform(TransformState.Projection, Matrix.PerspectiveFovLH((float)Math.PI/
      4, this.Width/this.Height, 1.0f, 100.0f)); 
     device.SetTransform(TransformState.View, Matrix.LookAtLH(new Vector3(0, 0, 5.0f), 
      new Vector3(), new Vector3(0, 1, 0))); 
     device.SetRenderState(RenderState.Lighting, false); 
    } 

    protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) 
    { 
     device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.CornflowerBlue, 1.0f, 0); 
     SetupCamera(); 

     CustomVertex.PositionColored[] verts = new CustomVertex.PositionColored[3]; 
     verts[0].Position = new Vector3(0.0f, 1.0f, 1.0f); 
     verts[0].Normal = new Vector3(0.0f, 0.0f, -1.0f); 
     verts[0].Color = System.Drawing.Color.White.ToArgb(); 
     verts[1].Position = new Vector3(-1.0f, -1.0f, 1.0f); 
     verts[1].Normal = new Vector3(0.0f, 0.0f, -1.0f); 
     verts[1].Color = System.Drawing.Color.White.ToArgb(); 
     verts[2].Position = new Vector3(1.0f, -1.0f, 1.0f); 
     verts[2].Normal = new Vector3(0.0f, 0.0f, -1.0f); 
     verts[2].Color = System.Drawing.Color.White.ToArgb(); 

     light.Type = LightType.Point; 
     light.Position = new Vector3(); 
     light.Diffuse = System.Drawing.Color.White; 
     light.Attenuation0 = 0.2f; 
     light.Range = 10000.0f; 

     device.SetLight(0, light); 
     device.EnableLight(0, true); 

     device.BeginScene(); 

     device.VertexFormat = CustomVertex.PositionColored.format; 
     device.DrawUserPrimitives<CustomVertex.PositionColored>(PrimitiveType.TriangleList, 1, verts); 
     device.EndScene(); 

     device.Present(); 
     this.Invalidate(); 
    } 
} 

}

나는이 문제가 무엇인지에 대해 다음

[StructLayout(LayoutKind.Sequential)] 
    public struct PositionNormalColored 
    { 
     public Vector3 Position; 
     public int Color; 
     public Vector3 Normal; 
     public static readonly VertexFormat format = VertexFormat.Diffuse | VertexFormat.Position | VertexFormat.Normal; 
    } 

어떤 제안을 사용하고있는 정점 포맷? 미리 감사드립니다.

+0

SlimDX 코드도 볼 수 있습니까? 이것은 단지 MDX 인 것처럼 보입니다. –

답변

1

device.SetRenderState(RenderState.Lighting, false)으로 전화하시는 이유는 무엇입니까? 조명을 다시 켜는 부분이 보이지 않습니다.

0

보통은 구조체 (세 번째가 아니라)에서 두 번째 값이되어야합니다. 그러나 현재의 프로젝트 (조명이 잘 작동하는 TAO openGL의 포트)에서 작동하지 않습니다.