Skip to main content
gamedev.net
🔒 Locked

SetViewport problem?

Started by Slug Nov 5, 2004 at 2:52 PM 2 replies 350+ views
Original Post
Slug
Slug
Anybody can tell me why the screen of my game became all weird when i set the viewport to (0,0,ScrHEIGHT,ScrHeight). i set it this way: void CTetrix3DXGameEngine::SetViewPortMatrix() { // This will hold the viewPort matrix. D3DVIEWPORT9 ViewPort; ViewPort.X = 0; ViewPort.Y = 0; ViewPort.Width = ScrHeight; ViewPort.Height = ScrHeight; ViewPort.MinZ = 0.0f; ViewPort.MaxZ = 1.0f; g_pd3dDevice->SetViewport(&ViewPort); } Why that does't work?
S1CA
S1CA
1) Use the debug Direct3D runtime with the debug output level increased to see if D3D is unhappy about anything else in your application. You may be seeing the symptom when you change the viewport, but the cause might be elsewhere.

2) Check to see whether SetViewport() succeeds (use the FAILED() or SUCCEEDED() macro to test the HRESULT it returns).

3) Step through to that line in the debugger and check that ScrHeight is really what you thought it should be at the point where you fill in the viewport structure.

4) After you change the viewport, try setting the VIEW and PROJECTION matrices again.


Could you also describe what you mean by "became all weird"? - if you just mean stretched/squashed, then be aware of the various properties of your projection matrix such as aspect ratio...
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Namethatnobodyelsetook
Namethatnobodyelsetook
I've noticed SetViewport likes to crash, rather than give an error, or clip the results, if you pass areas that are outside the actual backbuffer/rendertarget size... just in case that's what you're doing. Perhaps it does give an error, but sets the invalid state anyway, and the next clear or draw calls are what's actually crashing.

Note that SetViewport won't allow you to resize your window and/or backbuffer... that's not what it does... it lets you choose a subsection of your backbuffer/rendertarget to draw to. If you want a new back buffer size you need to Reset your device. You'll often couple that reset with a resize of your window. (Or the resize of the window triggers the Reset).

You haven't really said what you're trying to do, so I'm just tossing out ideas.
Slug
Slug
the weird think is like backgroud image mixed with garbage data

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.