현재 "Beginning C# Programming"을 통해 작업하고 있으며 텍스처를 그릴 때 7 장에서 문제가 발생했습니다.텍스처가 렌더링 될 때 회색으로 나타납니다.
나는 데모 CD에서와 같은 코드를 사용했으며, 텍스처의 경로를 절대로 변경해야했지만 렌더링 할 때 회색으로 표시됩니다.
로드 된 텍스처를 파일에 쓰도록 프로그램을 디버깅했습니다. 문제가 없습니다. 그 후에 뭔가 잘못 될 것입니다.
public void InitializeGraphics()
{
// set up the parameters
Direct3D.PresentParameters p = new Direct3D.PresentParameters();
p.SwapEffect = Direct3D.SwapEffect.Discard;
...
graphics = new Direct3D.Device(0, Direct3D.DeviceType.Hardware, this,
Direct3D.CreateFlags.SoftwareVertexProcessing, p);
...
// set up various drawing options
graphics.RenderState.CullMode = Direct3D.Cull.None;
graphics.RenderState.AlphaBlendEnable = true;
graphics.RenderState.AlphaBlendOperation = Direct3D.BlendOperation.Add;
graphics.RenderState.DestinationBlend = Direct3D.Blend.InvSourceAlpha;
graphics.RenderState.SourceBlend = Direct3D.Blend.SourceAlpha;
...
}
public void InitializeGeometry()
{
...
texture = Direct3D.TextureLoader.FromFile(
graphics, "E:\\Programming\\SharpDevelop_Projects\\AdvancedFrameworkv2\\texture.jpg", 0, 0, 0, 0, Direct3D.Format.Unknown,
Direct3D.Pool.Managed, Direct3D.Filter.Linear,
Direct3D.Filter.Linear, 0);
...
}
protected virtual void Render()
{
graphics.Clear(Direct3D.ClearFlags.Target, Color.White , 1.0f, 0);
graphics.BeginScene();
// set the texture
graphics.SetTexture(0, texture);
// set the vertex format
graphics.VertexFormat = Direct3D.CustomVertex.TransformedTextured.Format;
// draw the triangles
graphics.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, vertexes);
graphics.EndScene();
graphics.Present();
...
}
내가 잘못 여기에 무슨 일이 일어나고 있는지 알아낼 수 없습니다 : 여기
코드의 일부 조각입니다. 분명히 창에 텍스쳐를로드하면 괜찮습니다. 그래서 책에있는 코드 예제에서 뭔가 잘못되었습니다. 그것은 실제로 작동하지 않으며 아마도 내 환경에 뭔가 잘못된 것이있을 것입니다.
텍스처에 알파 채널이 있습니까? graphics.GraphicsDevice.RenderState.AlphaBlendEnable = true; ? – Jay
예 ... "graphics.RenderState.AlphaBlendEnable = true;". 나는 이것을 가능하게하는 옵션을 주석 처리하려고했지만 아무 소용이 없었다. – CdrTomalak
아마도 렌더의 명령문 순서 ... http://www.toymaker.info/Games/html/render_states.html – Jay