Sign in to follow this  
WuTz

Very very crazy problem :(

Recommended Posts

WuTz    100
Hello! I have a big problem with my engine, and I can't go on, if I don't fix it. :( I made two screenshots of it: http://i47.tinypic.com/6rpkkj.jpg and for a very extrem example: http://i47.tinypic.com/6xyoie.jpg As you see, the contents of the right viewport (Swapchain) are resized with the main viewport. Any Ideas why?? I don't know :( What code do you may need to help me?

Share this post


Link to post
Share on other sites
Tom KQT    1704
Check your projection matrix.
If you're using for example the D3DXMatrixPerspectiveFovLH function to create the projection matrix, there's "Aspect" parameter which can be responsible for this behaviour when not set correctly.

Share this post


Link to post
Share on other sites
WuTz    100
I create the Proj matrix every frame. For debugging.
This is the function:


void DXSubWindows::OnResizedChain()
{
D3D10_TEXTURE2D_DESC BackBufferDesc;

BackBuffer->GetDesc(&BackBufferDesc);

float fAspect = static_cast<float>(BackBufferDesc.Width ) / static_cast<float>( BackBufferDesc.Height );
D3DXMatrixPerspectiveFovLH( &Proj, FOV , fAspect, 0.5f, 1000.0f );

}


(How do I made those codeboxes???)

This is the rendereing code:


D3DXVECTOR3 OldLoc;
D3DXVECTOR3 OldRot;
WActor* A=(WActor *)PreviewActor;

OldLoc=A->Location;
OldRot=A->Rotation;

A->bContentMarkMode=false;
A->SetLocation(D3DXVECTOR3(-11,9,50));
A->SetRotation(D3DXVECTOR3(timeGetTime()*0.001,0,0));
//PreviewActor->SetLocation(TheScene->CurCam->Location);
SetMatrices(A);
A->PreRenderContentMark();
A->Render();
ResetMatrices(A);


The Func "SetMatrices()" sets the proj matrix into the Actor.
"PreRenderContentMark()" passes them to the mesh:


void WActor::PreRenderContentMark()
{
Foreach(Components,WComponent *)
(*Out)->View=ViewMatrix;
(*Out)->Proj=ProjMatrix;
(*Out)->PreRenderContentMark();

FE_End
}


They are passed to the shader here:


void WMesh::PreRenderContentMark()
{
ForeachV(MyMesh.Materials,WShader *,Out)
CheckNULL((*Out)->ViewVariable)CheckNULL(View)(*Out)->ViewVariable->SetMatrix( ( float* )View );
CheckNULL((*Out)->ProjectionVariable)CheckNULL(Projection)(*Out)->ProjectionVariable->SetMatrix( ( float* )Projection );
CheckNULL((*Out)->TimeVariable)(*Out)->TimeVariable->SetFloat(DXUTGetTime());
FE_End
}


And as you see, the Tree-Mesh at the seconf picture is scaled to the left/Right
AspectRation can't do that, right?

Maybe you have some codesamples for me, which show how to create a swapchain right...

Share this post


Link to post
Share on other sites
Buckeye    10747
To perhaps clarity what Tom KQT said: Do you set the viewport and projection matrix for each view you render? The viewport and proj matrix will not be the same for the two views.

Share this post


Link to post
Share on other sites
WuTz    100
Yes, of course!
The code I posted was from the Problem-Viewport at the right side. You can see
how the Proj matrix is passed to the shader.

And I checked the adresses, when the matrices get set to the shader.
They are all passed right.

I'm gonna despair of that crap :(
Is there any other solution for a second viewport than a swap chain?

Oh, and: I can draw text on the right viewport. Without any problems...
And: I tried already to NOT set the new proj matrix, and to leave the old one.
Then, nothing is drawn/Outside the screen. So, what could it be?

EDIT: Ah. What do you mean with "Do you set the [[[[viewport]]] and projection matrix for each view you render?"

Viewport matrix? Or what? View-Matrix? Jup, I set it.

Share this post


Link to post
Share on other sites
WuTz    100
Yeah, thanks! :)
Here is a link to our ModDB page:

http://www.moddb.com/engines/wtech/news/wtech-completely-rewritten

I linked directly to the interrestin stuff, because
currently it is full of the crap of my first try.
Read the newspage and you will know, WHY I had to make it "sick". :)

It is VERY important, that we can fix that problem, because all development had
to stop because of this. :(

Well not all, but I can't make anything big anymore :(

Please help! Maybe with some samplecode how to create a swapchian! Maybe I
did something wrong...

Share this post


Link to post
Share on other sites
Evil Steve    2017
Try printing out the aspect ratio passed to your projection matrix - the bug you're seeing is almost definitely caused by using the wrong aspect ratio - E.g. Using the aspect ratio of the left viewport in the right viewport.

Share this post


Link to post
Share on other sites
WuTz    100
So... I made a test. The AspectRatio is NOT the problem. Both
are different.
I found out, that even sprites are clipped out!
I mean they are clipped at the size from the main viewport.
They are resizing to, and the clipping-border is EXACTLY sized like
the Main-Viewport.

Do you need a screenshot of that?

And the more important thing:
Do you know how to solve that?? :(

I'll give you ANY code you need. Just ask which code!

:( :( :(

Share this post


Link to post
Share on other sites
bennyboy2    100
I'm with Evil Steve.

When I have this kind of problem, and I do very often, I get down to crunching my own numbers. Put hard-coded values in every relevant place and see how it affects your output.

Share this post


Link to post
Share on other sites
WuTz    100
Ok. I hardcoded the AspectRatio to 1, but it doesn't helps.
And I made a new screenshot, which shows everything you need to know:

http://i48.tinypic.com/2hmes5u.jpg

Maybe you know NOW, what could be wrong...

Share this post


Link to post
Share on other sites
Evil Steve    2017
Have you tried using Pix to check that the projection matrix you think is being set, and you're definitely not setting the same projection matrix on both swapchains?

It still looks like an aspect ratio problem because in your latest screenshot they both have the same aspect ratio. If the bug was still there, they'd look different at the same aspect ratio surely?

Share this post


Link to post
Share on other sites
WuTz    100
Oh no!
Sorry, I set them both to 1.
I'll make a new one :)

PIX doesn't works. I don't know why. It says, that the Backbuffer isn't matching
the Window, but when I start without PIX everything is OK. I may open another thread because of that.

Look:
http://i49.tinypic.com/33ygn4p.jpg

The left is set to 1 and the right is set to 3.

Uhm. Look at the clipping border. How could the Aspect ratio do THIS?

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by WuTz
Look:
http://i49.tinypic.com/33ygn4p.jpg

The left is set to 1 and the right is set to 3.

Uhm. Look at the clipping border. How could the Aspect ratio do THIS?
What clipping border? The aspect ratio in the right-hand window is clearly the same as the aspect ratio on the left, which means the wrong projection matrix is being set for it.

Share this post


Link to post
Share on other sites
WuTz    100
They are NOT the same. I just HARDCODED them accidentally in that Screenshot.
But I made a NEW ONE! Look at my last posting! I set the leftone to 1 and the rightone to 3 in that shot. And (1 != 3) :)

I made one more shot, to show you the clipping:

BEFORE (To big to clip):
http://i48.tinypic.com/5dp4zb.jpg

AFTER (Clipping the text):
http://i45.tinypic.com/34q8dja.jpg

EDIT:
I checked this:
V((*Out)->ProjectionVariable->SetMatrix( ( float* )Projection ));

It returns S_OK, and the adress of the Matrix-Pointer is the right one. :(
When nothing goes anymore, I may could send you the engine. But actually we don't want to give it around...

Share this post


Link to post
Share on other sites
Evil Steve    2017
I still don't see what you mean - Do you mean that the text isn't being scaled? If so, and you're using ID3DXFont, that's because ID3DXSprite (Which ID3DXFont) uses sets its own projection matrix when you draw using it.

I'm sure you're setting a different aspect ratio, but that aspect ratio is not in the projection matrix that is applied at the time the tree is rendered in the second window.

EDIT: Are you sure the projection matrix isn't being set again at some later point?

Share this post


Link to post
Share on other sites
WuTz    100
When you look at the second screenshot, you see, that the MainViewport is
veryvery small. And when you look at the right viewport, you see, that the
text isn't fully drawn. Don't think, that I reduced the Text! It is still the same text as in the "BEFORE"-Screenshot, in both viewports.

And see: The Main viewport has the SAME size as the drawn text in the right viewport! Thats what I mean with clipping. When I resize the Main viewport,
the clipping of the text moves with the size of the MainViewport.

It has the same X and the same Y size. Can THAT be done with the AspectRatio???

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by WuTz
When you look at the second screenshot, you see, that the MainViewport is
veryvery small. And when you look at the right viewport, you see, that the
text isn't fully drawn. Don't think, that I reduced the Text! It is still the same text as in the "BEFORE"-Screenshot, in both viewports.

And see: The Main viewport has the SAME size as the drawn text in the right viewport! Thats what I mean with clipping. When I resize the Main viewport,
the clipping of the text moves with the size of the MainViewport.
I see. Are the viewport extents also definitely being set?

When you use ID3DXSprite, it grabs the current viewport and uses that to set up a projection matrix. In the screenshots you've posted, it looks like ID3DXSprite thinks the viewport is smaller than it actually is. If that's the case, then the aspect ratio is probably also incorrect.

Share this post


Link to post
Share on other sites
WuTz    100
Hm. What do you mean with "Viewport extends"?

When you tell me, how I can do those small Codeboxes with syntax highlighting,
I'll give you the full codepath of setting up the viewport and the rendering of it.
I tried [/code], but it that wasn't was I wanted.

Where is the aspect ratio storred in the Matrix? I could check it then :)

Share this post


Link to post
Share on other sites
Evil Steve    2017
Quote:
Original post by WuTz
Hm. What do you mean with "Viewport extends"?
The parameters passed to SetViewport() (I don't know if that's the actual function name in D3D10, it is in D3D9)

Quote:
Original post by WuTz
When you tell me, how I can do those small Codeboxes with syntax highlighting,
I'll give you the full codepath of setting up the viewport and the rendering of it.
I tried [/code], but it that wasn't was I wanted.
[ source ] [ /source ] is what you want.

Quote:
Original post by WuTz
Where is the aspect ratio storred in the Matrix? I could check it then :)
The Docs for D3DXMatrixPerspectiveFovLH show that
_11 = xScale
_22 = yScale
xScale = yScale / aspect ratio

So, aspect = yScale / xScale, which means
aspect = _22 / _11.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this