Basic DX question

Started by
4 comments, last by Evil Steve 16 years, 6 months ago
I'm working with some TransformedColoredTextured vertices which i store in a vertex buffer and draw as a triangle strip. It works perfectly in windowed mode but when in full screen mode my primitives aren't rendered to screen. I have tried fiddling with some presentparameters but no luck and I'm out of ideas as to what causes this to happen. Here is my initialize device code:

PresentParameters presentParams = new PresentParameters();
presentParams.Windowed = this.isWindowed;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;

if ( !this.isWindowed )
{
    presentParams.BackBufferFormat = Microsoft.DirectX.Direct3D.Manager.Adapters[ 0 ].CurrentDisplayMode.Format;
    presentParams.BackBufferCount = 1;
    presentParams.BackBufferWidth = Microsoft.DirectX.Direct3D.Manager.Adapters[ 0 ].CurrentDisplayMode.Width;
    presentParams.BackBufferHeight = Microsoft.DirectX.Direct3D.Manager.Adapters[ 0 ].CurrentDisplayMode.Height;
    presentParams.FullScreenRefreshRateInHz = Microsoft.DirectX.Direct3D.Manager.Adapters[ 0 ].CurrentDisplayMode.RefreshRate;
    presentParams.PresentationInterval = PresentInterval.Immediate;
}

this.device = new Microsoft.DirectX.Direct3D.Device( 
    0,
    DeviceType.Hardware,
    this,
    CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice,
    presentParams
);

this.device.RenderState.CullMode = Cull.None;
this.device.RenderState.Lighting = false;
this.device.RenderState.FillMode = FillMode.Solid;
Should be very straight forward. And the render section:

device.Transform.World = this.world;
device.Transform.View = this.view;
device.Transform.Projection = this.projection;

device.SetTexture( 0, this.texture);

device.VertexFormat = CustomVertex.TransformedColoredTextured.Format;
device.SetStreamSource( 0, this.vertexBuffer, 0, CustomVertex.TransformedColoredTextured.StrideSize );

device.DrawPrimitives( PrimitiveType.TriangleList, IndexOffset, NumberOfPrimitives);
Matrices are defined as

this.world = Matrix.Identity;
this.view = Matrix.LookAtLH( new Vector3( 0, 0, 10 ), new Vector3( 0, 0, 0 ), new Vector3( 0, 1, 0 ) );
this.projection = Matrix.PerspectiveFovLH( ( float ) Math.PI / 4.0f, ( float ) this.Width / ( float ) this.Height, 0.1f, 10.0f ); 
Should also be straight forward. Anyone have any ideeas as to what can be the cause of it?
Advertisement
Quote:Original post by Annoyed
I have tried fiddling with some presentparameters but no luck and I'm out of ideas as to what causes this to happen.


Fiddling is generally an unsuccessful approach in 3D graphics because there are too many variables controlling the rendering. Or as my friend Russ Fish put it "graphics is hard because there are too many ways to code up a black screen".

Direct3D encapsulates a device that is a giant state machine. You set some state and render your geometry with the corresponding state. I'm willing to bet that you are rendering your primitives to the screen in exclusive mode, but that you're rendering black primitives on a black background, or your primitives are being rendered but aren't visible by the camera (i.e. they're outside the view frustum).

Take the time to understand the device and how it works instead of just "fiddling" with random values for the parameters controlling the presentation and the device rendering state. Look at what the samples in the SDK do, as they all handle transitions from windowed to exclusive and back again without problems.

You could also do worse than to read my book, and while it will take some time, you'll find it worthwhile.

My free book on Direct3D: "The Direct3D Graphics Pipeline"
My blog on programming, vintage computing, music, politics, etc.: Legalize Adulthood!

It's 99% likely it's not in your rendering code, since it works in windowed mode. Try setting the PresentationParameters.DeviceWindowHandle to a valid handle.
Chris ByersMicrosoft DirectX MVP - 2005
Also: enable unmanaged debugging or use dbmon to capture the debug output stream and see if there are any messages from the debug runtime.

My free book on Direct3D: "The Direct3D Graphics Pipeline"
My blog on programming, vintage computing, music, politics, etc.: Legalize Adulthood!

Quote:Original post by Supernat02
It's 99% likely it's not in your rendering code, since it works in windowed mode. Try setting the PresentationParameters.DeviceWindowHandle to a valid handle.



thanks, that was just the info I needed.
Changing the intitialization from:

this.device = new Microsoft.DirectX.Direct3D.Device(     0,    DeviceType.Hardware,    this,    CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice,    presentParams);


To:
this.device = new Microsoft.DirectX.Direct3D.Device(     0,    DeviceType.Hardware,    this.Handle,    CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice,    presentParams);



Where 'this.Handle' is of course the window handle. I had this weird idea that managed DX means that those things are taken care of >.<
I'd recommend using the debug runtimes; they'll pick up this sort of bug and spit out an error to the debug output window. You can enable the debug runtimes via the DirectX control panel, which is in the start menu -> DirectX SDK directory (Or in the Windows control pannel in older SDKs).

This topic is closed to new replies.

Advertisement