Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I posted this on StackOverlow, but of course it should be posted here.

I am maintaining a multiplatform codebase for Xbox360 and WinXP. I am seeing an issue on the XP side that appears to be related to D3DRS_VIEWPORTENABLE on the Xbox360 version not having an equivalent on WinXP D3D9. This article had an interesting idea, but the only way to construct an identity matrix is to supply negative numbers to D3DVIEWPORT9::X and D3DVIEWPORT9::Height, but they are unsigned numbers. (I tried to put in negative numbers anyway, but nothing interesting happened.)

So, how does one emulate the behavior of D3DRS_VIEWPORTENABLE under WinXP/D3D9?

(For clarity, the result I'm seeing is that a 2d screen-aligned quad works fine on Xbox360 but is offset/stretched on WinXP. In fact, the (0, 0) starts in the center of the screen on WinXP instead of in the lower-left corner like on the Xbox360 as a result of applying the viewport transform.)

Update: I didn't have an Xbox360 devkit at the time I wrote up this question, but I've since gotten one. I commented out the disabling of the D3DRS_VIEWPORTENABLE state, and the exact same behavior resulted on the Xbox360 as on the WinXP build. So, there must be some DirectX magic to bridge the gap here for emulating D3DRS_VIEWPORTENABLE being turned off on WinXP.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

Just set up your projection matrix to reverse any offset+scale done by the viewport?

share|improve this answer
    
In my case, it turned out the vertex shader wasn't using the whole matrix "chain", but your idea applied to the vertex shader's actual calculations did work. (i.e. reversing out the viewport matrix calculations so that, when combined with the inevitable viewport matrix, was effectively the identity matrix) –  Jim Buck Jan 17 '11 at 9:11
add comment

The viewport transform transforms co-ordinates into normalized device co-ordinates. They're kind of similar to texels, with 0,0 in the center and the corners being various permutations of 1 and -1.

However, you can observe that in ID3DXSprite, there is an option to render in screen-space co-ordinates. You could render to a texture, and then present it to the screen in a custom way by rendering it with ID3DXSprite.

D3D9 generates the Viewport transform with the following formula: alt text

If you know that you want an identity transform, you could solve to find it using this, or alter the projection matrix to counteract it's effects. I wish I could be of more use but I couldn't find any documentation on D3DRS_VIEWPORTENABLE for the 360- I only code for D3D9 on Windows.

share|improve this answer
    
I forgot to actually create the link in my OP, but this is the article that mentions exactly as your describe with the identity matrix for the viewport transform: gamedev.net/topic/502536-enablingdisabling-viewport . The only problem is that it's impossible to setup an identity matrix since it requires to pass in negative values to a function that only takes unsigned values. –  Jim Buck Jan 15 '11 at 0:03
    
@Jim Buck: You could, however, multiply the projection matrix by it's inverse, since you know the matrix you're producing. –  DeadMG Jan 15 '11 at 8:56
    
Yeah, I'm going to try that tonight to see if it solves the issue in the current codebase (as per bluescrn's answer and your comment). –  Jim Buck Jan 15 '11 at 19:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.