|
|

楼主 |
发表于 2005-11-2 17:00:00
|
显示全部楼层
Re:画三角形时,为何会出现多余的线条?
代码是这里下载的
http://www.c-unit.com/downloads/CU_MDX_Camera.zip
按F6就可以切换WireFrame与SolidFrame模式
查看了IndexBuffer的程序部分没有问题
组成IndexBuffer的代码是TriangleStripPlane类的GenerateIndices方法
Device初始化的代码在Graphics类的Initialize方法与BuildPresentParameters方法
/// <summary>
/// Initializes Direct3D.
/// </summary>
/// <param name="windowed">True for windowed mode. False for fullscreen mode.</param>
/// <param name="control">Render window.</param>
public void Initialize( bool windowed, Control control )
{
m_windowed = windowed;
m_renderWindow = control;
m_displayMode = Manager.Adapters[0].CurrentDisplayMode;
m_caps = Manager.GetDeviceCaps( 0, DeviceType.Hardware );
// Check for hardware T&L
CreateFlags flags;
if ( m_caps.DeviceCaps.SupportsHardwareTransformAndLight )
{
flags = CreateFlags.HardwareVertexProcessing;
}
else
{
flags = CreateFlags.SoftwareVertexProcessing;
}
// Check for pure device
if ( (m_caps.DeviceCaps.SupportsPureDevice) && ((flags & CreateFlags.HardwareVertexProcessing) != 0) )
{
flags |= CreateFlags.PureDevice;
}
BuildPresentParameters();
try
{
m_device = new Device( 0, DeviceType.Hardware, m_renderWindow, flags, m_pp );
}
catch ( DirectXException )
{
throw new DirectXException( "Unable to create the Direct3D device." );
}
// Cancel automatic device reset on resize
m_device.DeviceResizing += new System.ComponentModel.CancelEventHandler( CancelResize );
}
/// <summary>
/// Builds the PresentParameters class.
/// </summary>
public void BuildPresentParameters()
{
m_pp = new PresentParameters();
Format adaptorFormat = (Windowed) ? m_displayMode.Format : Format.X8R8G8B8;
if ( Manager.CheckDeviceFormat( 0, DeviceType.Hardware, adaptorFormat, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D24S8 ) )
{
m_pp.AutoDepthStencilFormat = DepthFormat.D24S8;
}
else if ( Manager.CheckDeviceFormat( 0, DeviceType.Hardware, adaptorFormat, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D24X8 ) )
{
m_pp.AutoDepthStencilFormat = DepthFormat.D24X8;
}
else if ( Manager.CheckDeviceFormat( 0, DeviceType.Hardware, adaptorFormat, Usage.DepthStencil, ResourceType.Surface, DepthFormat.D16 ) )
{
m_pp.AutoDepthStencilFormat = DepthFormat.D16;
}
else
{
throw new Direct3DXException( "Unable to find a supported depth stencil format" );
}
m_pp.BackBufferWidth = (Windowed) ? 0 : m_displayMode.Width;
m_pp.BackBufferHeight = (Windowed) ? 0 : m_displayMode.Height;
m_pp.BackBufferFormat = adaptorFormat;
m_pp.BackBufferCount = 1;
m_pp.MultiSample = MultiSampleType.None;
m_pp.MultiSampleQuality = 0;
m_pp.SwapEffect = SwapEffect.Discard;
m_pp.DeviceWindow = m_renderWindow;
m_pp.Windowed = Windowed;
m_pp.EnableAutoDepthStencil = true;
m_pp.PresentFlag = PresentFlag.DiscardDepthStencil;
m_pp.FullScreenRefreshRateInHz = (Windowed) ? 0 : m_displayMode.RefreshRate;
m_pp.PresentationInterval = PresentInterval.Immediate;
}
|
|