• 13
• 18
• 19
• 27
• 10

Can't get 'scissor test' effect by changing the viewport and projection matrix

This topic is 2624 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

I am trying to clip rendering to a small portion of the screen. I first tried using the scissor rectangle to achieve this however, I seem to be doing something wrong and posted it and the code in my other thread: Is there any way to clip text using ID3DXFont.

As an alternative, I have tried adjusting my viewport and projection matrix. However, the results are the same: Text which was supposed to be outside the rectangle is still rendered.

Code:

 public void Render() { adjustDrawArea(new Rectangle(new Point(100, 100), new Size(20, 20))); renderer.DrawText("Hello World", new Point(75, 75)); // Clearly not inside the new viewport so it shouldn't be visible right? returnDrawArea(); } Matrix originalProjection; Viewport originalViewport; void adjustDrawArea(Rectangle area) { Matrix adjustedProjection = Matrix.PerspectiveFovLH((float)(3.14159 / 4), (float)(area.Width / area.Height), 1f, 2f); Viewport adjustedViewport = new Viewport(area.X, area.Y, area.Width, area.Height); originalProjection = device.GetTransform(TransformState.Projection); originalViewport = device.Viewport; device.SetTransform(TransformState.Projection, adjustedProjection); device.Viewport = adjustedViewport; } void returnDrawArea() { device.SetTransform(TransformState.Projection, originalProjection); device.Viewport = originalViewport; }