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

This topic is 2808 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; } 

##### Share on other sites
First of all: Can you show us what's happening in renderer.DrawText() ? ID3DXSprite changes render states. Furthermore the transformation (normally) gets changed to a orthographic projection. Not sure about viewport/scissoring (as suggested in the other thread), the link does not say anything about them, but they probably get changed, too. A look at PIX should clarify that.

You can use ID3DXSprite with the D3DXSPRITE_DONOTMODIFY_RENDERSTATE to preserve states and D3DXSPRITE_OBJECTSPACE to let you manually choose a transformation. Anyway: If you're using ID3DXFont without a custom sprite, I think you should do so now, otherwise you don't have any influence at all, since ID3DXFont will use one of its own internally (hidden from you).

By the way: For rendering text you probably want a ortho-projection.

1. 1
2. 2
Rutin
21
3. 3
4. 4
frob
17
5. 5

• 9
• 12
• 9
• 33
• 13
• ### Forum Statistics

• Total Topics
632594
• Total Posts
3007261

×