Jump to content
  • Advertisement
Sign in to follow this  
jdub

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!