viewport help please...

Started by
5 comments, last by Namethatnobodyelsetook 18 years, 6 months ago
the viewport object that is located in the current device has a maxz value that I can't seem to directly set. Is there a way to set this? Thanks, Devin
Advertisement
These are set with pDevice->SetViewport().

Either query the current viewport, with GetViewport(), modify it, and set it back, or just create a temporary viewport like so:

D3DVIEWPORT9 vp;

vp.X = 0;
vp.Y = 0;
vp.Width = backbufferwidth; // same values you put in parameters sent to create device
vp.Height = backbufferheight;
vp.MinZ = 0;
vp.MaxZ = 1;

pDevice->SetViewport(&vp);

Z is still clipped and clamped as usual, but the final value is scaled to be between MinZ and MaxZ before testing and writing to the Z buffer. 0 and 1 are the standard settings. Setting both to 0 will cause any draws to appear in front of anything else. Unless you need the 0 stored in the Z buffer, it's probably quicker to just disable Z in this case. Setting both to 1 will cause all draws to appear behind anything else.
Thanks. Only one problem. My device doesn't seem to have SetViewport in it. Could it be somewhere else?
If you're using managed code, you'll need to set the viewport property of the device:
Device.Viewport = vp;
Sirob Yes.» - status: Work-O-Rama.
When I do that it crashes. Any idea why?
Quote:Original post by devronious
When I do that it crashes. Any idea why?

- Which compiler, .NET runtime and MDX runtime?
- Post the code.

D3D likes to crash when setting a viewport when (x+width > backbufferwidth) or (y+height > backbufferheight). Are you sure you're passing valid sizes? Obviously when using a rendertarget the limits are the size of the render target, not the back buffer.

I'm not sure how D3D reacts to odd MinZ, MaxZ values, like values >1, <0, or Min>Max.

D3D might to extra validation if you turn on the debug runtimes (via control panel). With any luck, your output window should give details of the crash.

This topic is closed to new replies.

Advertisement