Jump to content
  • Advertisement
Sign in to follow this  
emforce

split screen rendering problems

This topic is 3322 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 guys thanks to the help of SiCrane i managed to create 2 view ports but i dont know how to make it so that the same image renders in both vp right now i have if you cant see this image its basically a window with a box rendered on a grid on the left side and just clear color on the right side which as you can(hopefully) see only one viewport is rendered too. how do i change this? thanks

Share this post


Link to post
Share on other sites
Advertisement
I can't see the image, but you just need to set the second viewport after rendering the first tme, then render the scene a second time before ending the scene. You are essentially rendering the scene twice, once to each viewport.

Share this post


Link to post
Share on other sites
ok i still cant get it to work. heres my source code





#include "d3dApp.h"
#include "PeaksAndValleys.h"
#include "Waves.h"
#include "Light.h"
#include "Box.h"

class FogApp : public D3DApp
{
public:
FogApp(HINSTANCE hInstance);
~FogApp();

void initApp();
void onResize();
void updateScene(float dt);
void drawScene();


private:
void buildFX();
void buildVertexLayouts();

private:

Box mBox;
PeaksAndValleys mLand;
Waves mWaves;

Light mParallelLight;

// translate water tex-coords.
D3DXVECTOR2 mWaterTexOffset;

ID3D10RasterizerState* mNoCullRS;
ID3D10RasterizerState* mNoCullRS1;
ID3D10BlendState* mTransparentBS;

ID3D10Effect* mFX;
ID3D10EffectTechnique* mTech;
ID3D10ShaderResourceView* mGrassMapRV;
ID3D10ShaderResourceView* mBoxMapRV;
ID3D10ShaderResourceView* mWaterMapRV;
ID3D10ShaderResourceView* mDefaultSpecMapRV;

ID3D10EffectMatrixVariable* mfxWVPVar;
ID3D10EffectMatrixVariable* mfxWorldVar;
ID3D10EffectVariable* mfxEyePosVar;
ID3D10EffectVariable* mfxLightVar;
ID3D10EffectShaderResourceVariable* mfxDiffuseMapVar;
ID3D10EffectShaderResourceVariable* mfxSpecMapVar;
ID3D10EffectMatrixVariable* mfxTexMtxVar;

ID3D10InputLayout* mVertexLayout;

D3DXMATRIX mCrateWorld;
D3DXMATRIX mLandWorld;
D3DXMATRIX mWavesWorld;

D3DXMATRIX mView;
D3DXMATRIX mProj;
D3DXMATRIX mWVP;

D3DXVECTOR3 mEyePos;
float mRadius;
float mTheta;
float mPhi;

float mSpeed;

};

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,
PSTR cmdLine, int showCmd)
{
// Enable run-time memory check for debug builds.
#if defined(DEBUG) | defined(_DEBUG)
_CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );
#endif


FogApp theApp(hInstance);

theApp.initApp();

return theApp.run();
}

FogApp::FogApp(HINSTANCE hInstance)
: D3DApp(hInstance), mFX(0), mTech(0), mfxWVPVar(0), mfxWorldVar(0), mfxEyePosVar(0),
mfxLightVar(0), mfxDiffuseMapVar(0), mfxSpecMapVar(0), mfxTexMtxVar(0),
mVertexLayout(0), mGrassMapRV(0), mBoxMapRV(0), mWaterMapRV(0), mDefaultSpecMapRV(0),
mEyePos(0.0f, 0.0f, 0.0f), mRadius(75.0f), mTheta(0.0f), mPhi(PI*0.4f)
{
D3DXMatrixTranslation(&mCrateWorld, 8.0f, 0.0f, -15.0f);
D3DXMatrixIdentity(&mLandWorld);
D3DXMatrixIdentity(&mWavesWorld);
D3DXMatrixIdentity(&mView);
D3DXMatrixIdentity(&mProj);
D3DXMatrixIdentity(&mWVP);
}

FogApp::~FogApp()
{
if( md3dDevice )
md3dDevice->ClearState();

ReleaseCOM(mFX);
ReleaseCOM(mVertexLayout);
ReleaseCOM(mGrassMapRV);
ReleaseCOM(mBoxMapRV);
ReleaseCOM(mWaterMapRV);
ReleaseCOM(mDefaultSpecMapRV);

ReleaseCOM(mNoCullRS);
ReleaseCOM(mNoCullRS1);
ReleaseCOM(mTransparentBS);
}

void FogApp::initApp()
{
D3DApp::initApp();

mClearColor = D3DXCOLOR(0.7f, 0.7f, 0.7f, 1.0f);

mBox.init(md3dDevice, 5.0f);
mLand.init(md3dDevice, 129, 129, 1.0f);

// No wave damping.
mWaves.init(md3dDevice, 257, 257, 0.0f, 0.0f, 0.0f, 0.0f);

mBox.init(md3dDevice, 5.0f);
mLand.init(md3dDevice, 129, 129, 1.0f);


// Generate some waves at start up.
for(int k = 0; k < 30; ++k)
{
DWORD i = 5 + rand() % 250;
DWORD j = 5 + rand() % 250;

float r = RandF(0.5f, 1.25f);

mWaves.disturb(i, j, r);
}


buildFX();
buildVertexLayouts();


HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice,
L"grass.dds", 0, 0, &mGrassMapRV, 0 ));

HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice,
L"WireFence.dds", 0, 0, &mBoxMapRV, 0 ));

HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice,
L"water2a.dds", 0, 0, &mWaterMapRV, 0 ));

HR(D3DX10CreateShaderResourceViewFromFile(md3dDevice,
L"defaultspec.dds", 0, 0, &mDefaultSpecMapRV, 0 ));

mWaterTexOffset = D3DXVECTOR2(0.0f, 0.0f);

mParallelLight.dir = D3DXVECTOR3(0.57735f, -0.57735f, 0.57735f);
mParallelLight.ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);
mParallelLight.diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
mParallelLight.specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);




//box
D3D10_RASTERIZER_DESC rsDesc;
ZeroMemory(&rsDesc, sizeof(D3D10_RASTERIZER_DESC));
rsDesc.FillMode = D3D10_FILL_SOLID;
rsDesc.CullMode = D3D10_CULL_NONE;
HR(md3dDevice->CreateRasterizerState(&rsDesc, &mNoCullRS));


//Land
D3D10_RASTERIZER_DESC rsDesc1;
ZeroMemory(&rsDesc1, sizeof(D3D10_RASTERIZER_DESC));
rsDesc1.FillMode = D3D10_FILL_WIREFRAME;
rsDesc1.CullMode = D3D10_CULL_NONE;
HR(md3dDevice->CreateRasterizerState(&rsDesc1, &mNoCullRS1));

D3D10_BLEND_DESC blendDesc = {0};
blendDesc.AlphaToCoverageEnable = false;
blendDesc.BlendEnable[0] = true;
blendDesc.SrcBlend = D3D10_BLEND_SRC_ALPHA;
blendDesc.DestBlend = D3D10_BLEND_INV_SRC_ALPHA;
blendDesc.BlendOp = D3D10_BLEND_OP_ADD;
blendDesc.SrcBlendAlpha = D3D10_BLEND_ONE;
blendDesc.DestBlendAlpha = D3D10_BLEND_ZERO;
blendDesc.BlendOpAlpha = D3D10_BLEND_OP_ADD;
blendDesc.RenderTargetWriteMask[0] = D3D10_COLOR_WRITE_ENABLE_ALL;

HR(md3dDevice->CreateBlendState(&blendDesc, &mTransparentBS));
}

void FogApp::onResize()
{
D3DApp::onResize();

float aspect = (float)mClientWidth/mClientHeight;
D3DXMatrixPerspectiveFovLH(&mProj, 0.25f*PI, aspect, 1.0f, 1000.0f);
}

void FogApp::updateScene(float dt)
{
D3DApp::updateScene(dt);

float t = 0;


float acceleration = 0;
float velocity = 0;
float position = 0;
float force = 10;
float mass = 1;

while ( t <= 10 )
{
position = position + velocity * dt;
velocity = velocity + ( force / mass ) * dt;
acceleration = velocity / t;
t = t + dt;
}


static float x1;
static float y1;
static float z1;

static float xt;
static float yt;
static float zt;
mSpeed = 1.0f/ 10;

// Update angles based on input to orbit camera around scene.
if(GetAsyncKeyState('A') & 0x8000) mTheta -= 2.0f*dt;
if(GetAsyncKeyState('D') & 0x8000) mTheta += 2.0f*dt;
if(GetAsyncKeyState('W') & 0x8000) mPhi -= 2.0f*dt;
if(GetAsyncKeyState('S') & 0x8000) mPhi += 2.0f*dt;
if(GetAsyncKeyState('Z') & 0x8000) mRadius -= 15.0f*dt;
if(GetAsyncKeyState('X') & 0x8000) mRadius += 15.0f*dt;
if(GetAsyncKeyState(VK_UP) & 0x8000) z1 += acceleration/100;
if(GetAsyncKeyState(VK_DOWN) & 0x8000) z1 -= velocity/100;
if(GetAsyncKeyState(VK_LEFT) & 0x8000) x1 -= velocity/100;
if(GetAsyncKeyState(VK_RIGHT) & 0x8000) x1 += velocity/100;


// Restrict the angle mPhi.
if( mPhi < 0.1f ) mPhi = 0.1f;
if( mPhi > PI-0.1f) mPhi = PI-0.1f;

y1 = 5.0f;
D3DXMatrixTranslation(&mCrateWorld, x1, y1, z1);


//D3DXMatrixTranslation(&m, xt, yt, zt);
// Convert Spherical to Cartesian coordinates: mPhi measured from +y
// and mTheta measured counterclockwise from -z.
mEyePos.x = mRadius*sinf(mPhi)*sinf(mTheta);
mEyePos.z = -mRadius*sinf(mPhi)*cosf(mTheta);
mEyePos.y = mRadius*cosf(mPhi);

// Build the view matrix.
D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);
D3DXMatrixLookAtLH(&mView, &mEyePos, &target, &up);


// Animate water texture as a function of time.
mWaterTexOffset.y += 0.1f*dt;
mWaterTexOffset.x = 0.25f*sinf(4.0f*mWaterTexOffset.y);


mWaves.update(dt);
}

void FogApp::drawScene()
{
D3DApp::drawScene();
D3DApp::drawScene();


// Restore default states, input layout and primitive topology
// because mFont->DrawText changes them. Note that we can
// restore the default states by passing null.
md3dDevice->OMSetDepthStencilState(0, 0);
float blendFactor[] = {0.0f, 0.0f, 0.0f, 0.0f};
md3dDevice->OMSetBlendState(0, blendFactor, 0xffffffff);
md3dDevice->IASetInputLayout(mVertexLayout);
md3dDevice->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

// Set per frame constants.
mfxEyePosVar->SetRawValue(&mEyePos, 0, sizeof(D3DXVECTOR3));
mfxLightVar->SetRawValue(&mParallelLight, 0, sizeof(Light));

// Scale texture coordinates by 5 units to map [0,1]-->[0,5]
// so that the texture repeats five times in each direction.
D3DXMATRIX S;
D3DXMatrixScaling(&S, 5.0f, 5.0f, 1.0f);
D3DXMATRIX landTexMtx = S;

// Don't modify box tex-coords.
D3DXMATRIX boxTexMtx;
D3DXMatrixIdentity(&boxTexMtx);

// Scale and translate the texture.
D3DXMATRIX T;
D3DXMatrixTranslation(&T, mWaterTexOffset.x, mWaterTexOffset.y, 0.0f);
D3DXMATRIX waterTexMtx = S*T;


D3D10_TECHNIQUE_DESC techDesc;
mTech->GetDesc( &techDesc );

for(UINT i = 0; i < techDesc.Passes; ++i)
{
ID3D10EffectPass* pass = mTech->GetPassByIndex(i);

//
// Set land specific constants.
//
mWVP = mLandWorld*mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mfxWorldVar->SetMatrix((float*)&mLandWorld);
mfxTexMtxVar->SetMatrix((float*)&landTexMtx);
mfxDiffuseMapVar->SetResource(mGrassMapRV);
mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
md3dDevice->RSSetState(mNoCullRS1);
pass->Apply(0);
mLand.draw();
md3dDevice->RSSetState(0);
// Set box specific constants.
//
mWVP = mCrateWorld*mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mfxWorldVar->SetMatrix((float*)&mCrateWorld);
mfxTexMtxVar->SetMatrix((float*)&boxTexMtx);
mfxDiffuseMapVar->SetResource(mBoxMapRV);
mfxSpecMapVar->SetResource(mDefaultSpecMapRV);

// Since the gate texture has transparent regions, we can
// see through it, and thus see the backsides of the triangles.
// Therefore, we don't want to backface cull in this case.
md3dDevice->RSSetState(mNoCullRS);
pass->Apply(0);
mBox.draw();
md3dDevice->RSSetState(0); // restore default

//
// Set water specific constants.
//
mWVP = mWavesWorld*mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mfxWorldVar->SetMatrix((float*)&mWavesWorld);
mfxTexMtxVar->SetMatrix((float*)&waterTexMtx);
mfxDiffuseMapVar->SetResource(mWaterMapRV);
mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
pass->Apply(0);
md3dDevice->OMSetBlendState(mTransparentBS, blendFactor, 0xffffffff);
mWaves.draw();
}

for(UINT i = 0; i < techDesc.Passes; ++i)
{
ID3D10EffectPass* pass = mTech->GetPassByIndex(i);

//
// Set land specific constants.
//
mWVP = mLandWorld*mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mfxWorldVar->SetMatrix((float*)&mLandWorld);
mfxTexMtxVar->SetMatrix((float*)&landTexMtx);
mfxDiffuseMapVar->SetResource(mGrassMapRV);
mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
md3dDevice->RSSetState(mNoCullRS1);
pass->Apply(0);
mLand.draw();
md3dDevice->RSSetState(0);
// Set box specific constants.
//
mWVP = mCrateWorld*mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mfxWorldVar->SetMatrix((float*)&mCrateWorld);
mfxTexMtxVar->SetMatrix((float*)&boxTexMtx);
mfxDiffuseMapVar->SetResource(mBoxMapRV);
mfxSpecMapVar->SetResource(mDefaultSpecMapRV);

// Since the gate texture has transparent regions, we can
// see through it, and thus see the backsides of the triangles.
// Therefore, we don't want to backface cull in this case.
md3dDevice->RSSetState(mNoCullRS);
pass->Apply(0);
mBox.draw();
md3dDevice->RSSetState(0); // restore default

//
// Set water specific constants.
//
mWVP = mWavesWorld*mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mfxWorldVar->SetMatrix((float*)&mWavesWorld);
mfxTexMtxVar->SetMatrix((float*)&waterTexMtx);
mfxDiffuseMapVar->SetResource(mWaterMapRV);
mfxSpecMapVar->SetResource(mDefaultSpecMapRV);
pass->Apply(0);
md3dDevice->OMSetBlendState(mTransparentBS, blendFactor, 0xffffffff);
mWaves.draw();
}

// We specify DT_NOCLIP, so we do not care about width/height of the rect.
RECT R = {5, 5, 0, 0};
md3dDevice->RSSetState(0);
mFont->DrawText(0, mFrameStats.c_str(), -1, &R, DT_NOCLIP, WHITE);

RECT R1 = {mClientWidth/2 + 5, 5, 0, 0};
md3dDevice->RSSetState(0);
mFont->DrawText(0, mFrameStats.c_str(), -1, &R1, DT_NOCLIP, WHITE);

mSwapChain->Present(0, 0);
}

void FogApp::buildFX()
{
DWORD shaderFlags = D3D10_SHADER_ENABLE_STRICTNESS;
#if defined( DEBUG ) || defined( _DEBUG )
shaderFlags |= D3D10_SHADER_DEBUG;
shaderFlags |= D3D10_SHADER_SKIP_OPTIMIZATION;
#endif

ID3D10Blob* compilationErrors = 0;
HRESULT hr = 0;
hr = D3DX10CreateEffectFromFile(L"fog.fx", 0, 0,
"fx_4_0", shaderFlags, 0, md3dDevice, 0, 0, &mFX, &compilationErrors, 0);
if(FAILED(hr))
{
if( compilationErrors )
{
MessageBoxA(0, (char*)compilationErrors->GetBufferPointer(), 0, 0);
ReleaseCOM(compilationErrors);
}
DXTrace(__FILE__, (DWORD)__LINE__, hr, L"D3DX10CreateEffectFromFile", true);
}

mTech = mFX->GetTechniqueByName("FogTech");

mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix();
mfxWorldVar = mFX->GetVariableByName("gWorld")->AsMatrix();
mfxEyePosVar = mFX->GetVariableByName("gEyePosW");
mfxLightVar = mFX->GetVariableByName("gLight");
mfxDiffuseMapVar = mFX->GetVariableByName("gDiffuseMap")->AsShaderResource();
mfxSpecMapVar = mFX->GetVariableByName("gSpecMap")->AsShaderResource();
mfxTexMtxVar = mFX->GetVariableByName("gTexMtx")->AsMatrix();
}

void FogApp::buildVertexLayouts()
{
// Create the vertex input layout.
D3D10_INPUT_ELEMENT_DESC vertexDesc[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D10_INPUT_PER_VERTEX_DATA, 0},
{"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 24, D3D10_INPUT_PER_VERTEX_DATA, 0},
};

// Create the input layout
D3D10_PASS_DESC PassDesc;
mTech->GetPassByIndex(0)->GetDesc(&PassDesc);
HR(md3dDevice->CreateInputLayout(vertexDesc, 3, PassDesc.pIAInputSignature,
PassDesc.IAInputSignatureSize, &mVertexLayout));
}









#include "d3dApp.h"
#include <sstream>

LRESULT CALLBACK
MainWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static D3DApp* app = 0;

switch( msg )
{
case WM_CREATE:
{
// Get the 'this' pointer we passed to CreateWindow via the lpParam parameter.
CREATESTRUCT* cs = (CREATESTRUCT*)lParam;
app = (D3DApp*)cs->lpCreateParams;
return 0;
}
}

// Don't start processing messages until after WM_CREATE.
if( app )
return app->msgProc(msg, wParam, lParam);
else
return DefWindowProc(hwnd, msg, wParam, lParam);
}

D3DApp::D3DApp(HINSTANCE hInstance)
{
mhAppInst = hInstance;
mhMainWnd = 0;
mAppPaused = false;
mMinimized = false;
mMaximized = false;
mResizing = false;

mFrameStats = L"";

md3dDevice = 0;
mSwapChain = 0;
mDepthStencilBuffer = 0;
mRenderTargetView = 0;
mDepthStencilView = 0;
mFont = 0;

mMainWndCaption = L"D3D10 Application";
md3dDriverType = D3D10_DRIVER_TYPE_HARDWARE;
mClearColor = D3DXCOLOR(0.0f, 0.0f, 1.0f, 1.0f);
mClientWidth = 800;
mClientHeight = 600;
}

D3DApp::~D3DApp()
{
ReleaseCOM(mRenderTargetView);
ReleaseCOM(mDepthStencilView);
ReleaseCOM(mSwapChain);
ReleaseCOM(mDepthStencilBuffer);
ReleaseCOM(md3dDevice);
ReleaseCOM(mFont);
}

HINSTANCE D3DApp::getAppInst()
{
return mhAppInst;
}

HWND D3DApp::getMainWnd()
{
return mhMainWnd;
}

int D3DApp::run()
{
MSG msg = {0};

mTimer.reset();

while(msg.message != WM_QUIT)
{
// If there are Window messages then process them.
if(PeekMessage( &msg, 0, 0, 0, PM_REMOVE ))
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
// Otherwise, do animation/game stuff.
else
{
mTimer.tick();

if( !mAppPaused )
updateScene(mTimer.getDeltaTime());
else
Sleep(50);

drawScene();
}
}
return (int)msg.wParam;
}

void D3DApp::initApp()
{
initMainWindow();
initDirect3D();

D3DX10_FONT_DESC fontDesc;
fontDesc.Height = 24;
fontDesc.Width = 0;
fontDesc.Weight = 0;
fontDesc.MipLevels = 1;
fontDesc.Italic = false;
fontDesc.CharSet = DEFAULT_CHARSET;
fontDesc.OutputPrecision = OUT_DEFAULT_PRECIS;
fontDesc.Quality = DEFAULT_QUALITY;
fontDesc.PitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
wcscpy(fontDesc.FaceName, L"Times New Roman");

D3DX10CreateFontIndirect(md3dDevice, &fontDesc, &mFont);
}

void D3DApp::onResize()
{
// Release the old views, as they hold references to the buffers we
// will be destroying. Also release the old depth/stencil buffer.

ReleaseCOM(mRenderTargetView);
ReleaseCOM(mDepthStencilView);
ReleaseCOM(mDepthStencilBuffer);


// Resize the swap chain and recreate the render target view.

HR(mSwapChain->ResizeBuffers(1, mClientWidth, mClientHeight, DXGI_FORMAT_R8G8B8A8_UNORM, 0));
ID3D10Texture2D* backBuffer;
HR(mSwapChain->GetBuffer(0, __uuidof(ID3D10Texture2D), reinterpret_cast<void**>(&backBuffer)));
HR(md3dDevice->CreateRenderTargetView(backBuffer, 0, &mRenderTargetView));
ReleaseCOM(backBuffer);


// Create the depth/stencil buffer and view.

D3D10_TEXTURE2D_DESC depthStencilDesc;

depthStencilDesc.Width = mClientWidth;
depthStencilDesc.Height = mClientHeight;
depthStencilDesc.MipLevels = 1;
depthStencilDesc.ArraySize = 1;
depthStencilDesc.Format = DXGI_FORMAT_D24_UNORM_S8_UINT;
depthStencilDesc.SampleDesc.Count = 1; // multisampling must match
depthStencilDesc.SampleDesc.Quality = 0; // swap chain values.
depthStencilDesc.Usage = D3D10_USAGE_DEFAULT;
depthStencilDesc.BindFlags = D3D10_BIND_DEPTH_STENCIL;
depthStencilDesc.CPUAccessFlags = 0;
depthStencilDesc.MiscFlags = 0;

HR(md3dDevice->CreateTexture2D(&depthStencilDesc, 0, &mDepthStencilBuffer));
HR(md3dDevice->CreateDepthStencilView(mDepthStencilBuffer, 0, &mDepthStencilView));


// Bind the render target view and depth/stencil view to the pipeline.

md3dDevice->OMSetRenderTargets(1, &mRenderTargetView, mDepthStencilView);


// Set the viewport transform.
D3D10_VIEWPORT vp[2];


vp[0].TopLeftX = 0;
vp[0].TopLeftY = 0;
vp[0].Width = mClientWidth/2;
vp[0].Height = mClientHeight;
vp[0].MinDepth = 0.0f;
vp[0].MaxDepth = 1.0f;

md3dDevice->RSSetViewports(1, vp);

vp[1].TopLeftX = mClientWidth/2;
vp[1].TopLeftY = 0;
vp[1].Width = mClientWidth/2;
vp[1].Height = mClientHeight;
vp[1].MinDepth = 0.0f;
vp[1].MaxDepth = 1.0f;


md3dDevice->RSSetViewports(1, vp);


}

void D3DApp::updateScene(float dt)
{
// Code computes the average frames per second, and also the
// average time it takes to render one frame.

static int frameCnt = 0;
static float t_base = 0.0f;

frameCnt++;

// Compute averages over one second period.
if( (mTimer.getGameTime() - t_base) >= 1.0f )
{
float fps = (float)frameCnt; // fps = frameCnt / 1
float mspf = 1000.0f / fps;

std::wostringstream outs;
outs.precision(6);
outs << L"FPS: " << fps << L"\n"
<< "Milliseconds: Per Frame: " << mspf;
mFrameStats = outs.str();

// Reset for next average.
frameCnt = 0;
t_base += 1.0f;
}
}

void D3DApp::drawScene()
{
md3dDevice->ClearRenderTargetView(mRenderTargetView, mClearColor);
md3dDevice->ClearDepthStencilView(mDepthStencilView, D3D10_CLEAR_DEPTH|D3D10_CLEAR_STENCIL, 1.0f, 0);
}

LRESULT D3DApp::msgProc(UINT msg, WPARAM wParam, LPARAM lParam)
{
switch( msg )
{
// WM_ACTIVATE is sent when the window is activated or deactivated.
// We pause the game when the window is deactivated and unpause it
// when it becomes active.
case WM_ACTIVATE:
if( LOWORD(wParam) == WA_INACTIVE )
{
mAppPaused = true;
mTimer.stop();
}
else
{
mAppPaused = false;
mTimer.start();
}
return 0;

// WM_SIZE is sent when the user resizes the window.
case WM_SIZE:
// Save the new client area dimensions.
mClientWidth = LOWORD(lParam);
mClientHeight = HIWORD(lParam);
if( md3dDevice )
{
if( wParam == SIZE_MINIMIZED )
{
mAppPaused = true;
mMinimized = true;
mMaximized = false;
}
else if( wParam == SIZE_MAXIMIZED )
{
mAppPaused = false;
mMinimized = false;
mMaximized = true;
onResize();
}
else if( wParam == SIZE_RESTORED )
{

// Restoring from minimized state?
if( mMinimized )
{
mAppPaused = false;
mMinimized = false;
onResize();
}

// Restoring from maximized state?
else if( mMaximized )
{
mAppPaused = false;
mMaximized = false;
onResize();
}
else if( mResizing )
{
// If user is dragging the resize bars, we do not resize
// the buffers here because as the user continuously
// drags the resize bars, a stream of WM_SIZE messages are
// sent to the window, and it would be pointless (and slow)
// to resize for each WM_SIZE message received from dragging
// the resize bars. So instead, we reset after the user is
// done resizing the window and releases the resize bars, which
// sends a WM_EXITSIZEMOVE message.
}
else // API call such as SetWindowPos or mSwapChain->SetFullscreenState.
{
onResize();
}
}
}
return 0;

// WM_EXITSIZEMOVE is sent when the user grabs the resize bars.
case WM_ENTERSIZEMOVE:
mAppPaused = true;
mResizing = true;
mTimer.stop();
return 0;

// WM_EXITSIZEMOVE is sent when the user releases the resize bars.
// Here we reset everything based on the new window dimensions.
case WM_EXITSIZEMOVE:
mAppPaused = false;
mResizing = false;
mTimer.start();
onResize();
return 0;

// WM_DESTROY is sent when the window is being destroyed.
case WM_DESTROY:
PostQuitMessage(0);
return 0;

// The WM_MENUCHAR message is sent when a menu is active and the user presses
// a key that does not correspond to any mnemonic or accelerator key.
case WM_MENUCHAR:
// Don't beep when we alt-enter.
return MAKELRESULT(0, MNC_CLOSE);

// Catch this message so to prevent the window from becoming too small.
case WM_GETMINMAXINFO:
((MINMAXINFO*)lParam)->ptMinTrackSize.x = 200;
((MINMAXINFO*)lParam)->ptMinTrackSize.y = 200;
return 0;
}

return DefWindowProc(mhMainWnd, msg, wParam, lParam);
}


void D3DApp::initMainWindow()
{
WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = MainWndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = mhAppInst;
wc.hIcon = LoadIcon(0, IDI_APPLICATION);
wc.hCursor = LoadCursor(0, IDC_ARROW);
wc.hbrBackground = (HBRUSH)GetStockObject(NULL_BRUSH);
wc.lpszMenuName = 0;
wc.lpszClassName = L"D3DWndClassName";

if( !RegisterClass(&wc) )
{
MessageBox(0, L"RegisterClass FAILED", 0, 0);
PostQuitMessage(0);
}

// Compute window rectangle dimensions based on requested client area dimensions.
RECT R = { 0, 0, mClientWidth, mClientHeight };
AdjustWindowRect(&R, WS_OVERLAPPEDWINDOW, false);
int width = R.right - R.left;
int height = R.bottom - R.top;

mhMainWnd = CreateWindow(L"D3DWndClassName", mMainWndCaption.c_str(),
WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, width, height, 0, 0, mhAppInst, this);
if( !mhMainWnd )
{
MessageBox(0, L"CreateWindow FAILED", 0, 0);
PostQuitMessage(0);
}

ShowWindow(mhMainWnd, SW_SHOW);
UpdateWindow(mhMainWnd);
}

void D3DApp::initDirect3D()
{
// Fill out a DXGI_SWAP_CHAIN_DESC to describe our swap chain.

DXGI_SWAP_CHAIN_DESC sd;
sd.BufferDesc.Width = mClientWidth;
sd.BufferDesc.Height = mClientHeight;
sd.BufferDesc.RefreshRate.Numerator = 60;
sd.BufferDesc.RefreshRate.Denominator = 1;
sd.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;

// No multisampling.
sd.SampleDesc.Count = 1;
sd.SampleDesc.Quality = 0;

sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
sd.BufferCount = 1;
sd.OutputWindow = mhMainWnd;
sd.Windowed = true;
sd.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
sd.Flags = 0;


// Create the device.

UINT createDeviceFlags = 0;
#if defined(DEBUG) || defined(_DEBUG)
createDeviceFlags |= D3D10_CREATE_DEVICE_DEBUG;
#endif

HR( D3D10CreateDeviceAndSwapChain(
0, //default adapter
md3dDriverType,
0, // no software device
createDeviceFlags,
D3D10_SDK_VERSION,
&sd,
&mSwapChain,
&md3dDevice) );


// The remaining steps that need to be carried out for d3d creation
// also need to be executed every time the window is resized. So
// just call the onResize method here to avoid code duplication.

onResize();
}






so am i missing something. I set the second viewport and i rendered the scene a second time. But what am i doing wrong? please be nice i am only 15 :S

[Edited by - emforce on August 16, 2009 2:22:50 PM]

Share this post


Link to post
Share on other sites
Your code doesn't make any kinda sense.....
Create two separate viewport variables in your render function, and set first the first one, render your scene, then the second one, and render your scene again. You must change viewport everytime you want to draw into another, unless you use the geometry shader, as stated by the documentation: RSSetViewports.
When you get to issues this advanced you can't just hack them to correctness, there are way too many variables. I've seen your other posts and you keep changing your code seemingly without any plan or reason behind it. This particular case should be solvable without too much problems, but I recommend following a few tutorials and studying the basics until you really understand _why_ things work. It will greatly increase your efficiency later on.

Share this post


Link to post
Share on other sites
ahh right i got it to work but now the screen is flashes both view ports on and off very quickly. is there a way i could interpolate(i think this is the right word) between the screens? And yeh i am reading up on this every night so i dont yet have full understanding.

Share this post


Link to post
Share on other sites
so do you mean something like this?



drawScene();

vp[0].TopLeftX = 0;
vp[0].TopLeftY = 0;
vp[0].Width = mClientWidth/2;
vp[0].Height = mClientHeight;
vp[0].MinDepth = 0.0f;
vp[0].MaxDepth = 1.0f;

md3dDevice->RSSetViewports(1, &vp[0]);

drawScene();

vp[1].TopLeftX = mClientWidth/2;
vp[1].TopLeftY = 0;
vp[1].Width = mClientWidth/2;
vp[1].Height = mClientHeight;
vp[1].MinDepth = 0.0f;
vp[1].MaxDepth = 1.0f;


md3dDevice->RSSetViewports(1, &vp[1]);

mSwapChain->Present(0, 0);




but when i try this it doesn't work i just get one view port rendered

Share this post


Link to post
Share on other sites
but when i do that only one side gets rendered.

but just to make sure you mean like this?



vp[0].TopLeftX = 0;
vp[0].TopLeftY = 0;
vp[0].Width = mClientWidth/2;
vp[0].Height = mClientHeight;
vp[0].MinDepth = 0.0f;
vp[0].MaxDepth = 1.0f;

md3dDevice->RSSetViewports(1, &vp[0]);

drawScene();
vp[1].TopLeftX = mClientWidth/2;
vp[1].TopLeftY = 0;
vp[1].Width = mClientWidth/2;
vp[1].Height = mClientHeight;
vp[1].MinDepth = 0.0f;
vp[1].MaxDepth = 1.0f;


md3dDevice->RSSetViewports(1, &vp[1]);
drawScene();

mSwapChain->Present(0, 0);


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!