Jump to content
  • Advertisement
Sign in to follow this  
johnnyBravo

How to render to 2 squares?

This topic is 4993 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

Hi, say I got my window to which Im rendering a small cube spinning around a large cube which is sitting on the origin. I want to draw a square on the top left of my screen which would show the camera view from the small square's position looking at the larger square. How would I render twice, once to the normal window, and once to square in the top left of the screen? thanks ....Sorry for my bad explanation.

Share this post


Link to post
Share on other sites
Advertisement
At the beginning of the draw phase you clear the backbuffer and render your full scene showing both cubes. Then use the IDirect3DDevice9::SetViewport method to define a rectangle at the top left of the screen. Setup the matrices and render your scene from the small cube's perspective, then set the viewport back to the entire backbuffer.

Viewports can be used similarly to simulate a rear-view mirror in a driving game.

If you want to use a more complex viewport than a rectangle, then you can try using a stencil buffer.

Good luck.

Share this post


Link to post
Share on other sites
hey so you mean i do:

//box perspective
setviewport()
clear()
beginscene()
drawmystuff()
endscene()


//normal perspective
setviewport()
clear()
beginscene()
drawmystuff()
endscene()


I've tried a number of different combinations of the following, but no matter what i do, the moving cube seems to smudge all over the screen, as if its not being cleared or something.

Any idea on what I am doing wrong?

Thanks

Share this post


Link to post
Share on other sites
OK, a code example:


VOID ViewPort(D3DXVECTOR3 pCenter)
{
D3DVIEWPORT9 View2;

View2.X = ...;
View2.Y = ...;
View2.Width = ...;
View2.Height = ...;
View2.MinZ = ...;
View2.MaxZ = ...;

pDevice->SetViewport( &View2 );

pDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0),1.0f,0);

if( SUCCEEDED(pDevice->BeginScene()))
{
D3DXVECTOR3 pEye = pCenter;
D3DXVECTOR3 pLookAt(0.0f,0.0f,0.0f);
D3DXVECTOR3 pUp(0.0f,1.0f,0.0f);

D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH(&matView,&pEye,&pLookAt,&pUp);
pDevice->SetTransform(D3DTS_VIEW,&matVisao);

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH(&matProj, ... , ... , ... , ... );
pDevice->SetTransform(D3DTS_PROJECTION,&matProj);

// Set the world matrix for the large cube
.
.
.
pDevice->SetTransform(D3DTS_WORLD,&matWorld);
LargeCube->Draw();

pDevice->EndScene();
}
}


VOID Render()
{
D3DVIEWPORT9 View1;

View1.X = ...;
View1.Y = ...;
View1.Width = ...;
View1.Height = ...;
View1.MinZ = ...;
View1.MaxZ = ...;

pDevice->SetViewport( &View1 );

pDevice->Clear(0,NULL,D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0,0,0),1.0f,0);

if( SUCCEEDED(pDevice->BeginScene()))
{
D3DXVECTOR3 pEye (0.0f,0.0f, ... ); // for example, a static position on the z-axis
D3DXVECTOR3 pLookAt(0.0f,0.0f,0.0f);
D3DXVECTOR3 pUp(0.0f,1.0f,0.0f);

D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH(&matView,&pEye,&pLookAt,&pUp);
pDevice->SetTransform(D3DTS_VIEW,&matVisao);

D3DXMATRIXA16 matProj;
D3DXMatrixPerspectiveFovLH(&matProj, ... , ... , ... , ... );
pDevice->SetTransform(D3DTS_PROJECTION,&matProj);

// Set the world matrix for the large cube
.
.
.
pDevice->SetTransform(D3DTS_WORLD,&matWorld);
LargeCube->Draw();

// Set the world matrix for the small cube and find its center position in the world space
.
.
.
pDevice->SetTransform(D3DTS_WORLD,&matWorld);
SmallCube->Draw();

pDevice->EndScene();

ViewPort( pCenterSmallCube );
}
}

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!