本文整理汇总了C++中IDirect3DDevice9::SetRenderState方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DDevice9::SetRenderState方法的具体用法?C++ IDirect3DDevice9::SetRenderState怎么用?C++ IDirect3DDevice9::SetRenderState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirect3DDevice9
的用法示例。
在下文中一共展示了IDirect3DDevice9::SetRenderState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void StateManager9::setDepthFunc(bool depthTest, GLenum depthFunc)
{
if (depthTest)
{
IDirect3DDevice9 *device = mRenderer9->getDevice();
device->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
device->SetRenderState(D3DRS_ZFUNC, gl_d3d9::ConvertComparison(depthFunc));
}
else
{
mRenderer9->getDevice()->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
}
mCurDepthStencilState.depthTest = depthTest;
mCurDepthStencilState.depthFunc = depthFunc;
}
示例2: ZeroMemory
bool GPUContextDX9::initialize()
{
_window = DX9Window::create();
if( _window == NULL )
{
DX9WARN << "Could not create offscreen window.";
return false;
}
HWND windowHandle = _window->getWindowHandle();
_direct3D = Direct3DCreate9( D3D_SDK_VERSION );
if( _direct3D == NULL )
{
DX9WARN << "Could not create Direct3D interface.";
return false;
}
D3DPRESENT_PARAMETERS deviceDesc;
ZeroMemory( &deviceDesc, sizeof(deviceDesc) );
deviceDesc.Windowed = TRUE;
deviceDesc.SwapEffect = D3DSWAPEFFECT_DISCARD;
deviceDesc.BackBufferFormat = D3DFMT_UNKNOWN;
deviceDesc.EnableAutoDepthStencil = FALSE;
deviceDesc.AutoDepthStencilFormat = D3DFMT_D24S8;
HRESULT result = _direct3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, windowHandle,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &deviceDesc, &_device );
if( FAILED(result) )
{
DX9WARN << "Could not create Direct3D device.";
return false;
}
// create vertex buffer
static const int kMaxVertexCount = 64;
result = _device->CreateVertexBuffer(
kMaxVertexCount*sizeof(DX9Vertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &_vertexBuffer, NULL );
DX9AssertResult( result, "CreateVertexBuffer failed" );
result = _device->CreateVertexDeclaration( kDX9VertexElements, &_vertexDecl );
DX9AssertResult( result, "CreateVertexDeclaration failed" );
// TIM: set up initial state
result = _device->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
GPUAssert( !FAILED(result), "SetRenderState failed" );
_passthroughVertexShader = createVertexShader( kPassthroughVertexShaderSource );
_passthroughPixelShader = createPixelShader( kPassthroughPixelShaderSource );
for( size_t i = 0; i < kMaximumOutputCount; i++ )
_boundOutputs[i] = NULL;
for( size_t t = 0; t < kMaximumSamplerCount; t++ )
_boundTextures[t] = NULL;
return true;
}
示例3:
void StateManager9::setStencilOpsBack(GLenum stencilBackFail,
GLenum stencilBackPassDepthFail,
GLenum stencilBackPassDepthPass,
bool frontFaceCCW)
{
IDirect3DDevice9 *device = mRenderer9->getDevice();
device->SetRenderState(!frontFaceCCW ? D3DRS_STENCILFAIL : D3DRS_CCW_STENCILFAIL,
gl_d3d9::ConvertStencilOp(stencilBackFail));
device->SetRenderState(!frontFaceCCW ? D3DRS_STENCILZFAIL : D3DRS_CCW_STENCILZFAIL,
gl_d3d9::ConvertStencilOp(stencilBackPassDepthFail));
device->SetRenderState(!frontFaceCCW ? D3DRS_STENCILPASS : D3DRS_CCW_STENCILPASS,
gl_d3d9::ConvertStencilOp(stencilBackPassDepthPass));
mCurDepthStencilState.stencilBackFail = stencilBackFail;
mCurDepthStencilState.stencilBackPassDepthFail = stencilBackPassDepthFail;
mCurDepthStencilState.stencilBackPassDepthPass = stencilBackPassDepthPass;
}
示例4: SetUpLights
static void SetUpLights(){
IDirect3DDevice9 *pDevice = _pGraphics->GetD3DDevice();
D3DXVECTOR3 dir(1.0f, -1.0f, 1.0f);
D3DXCOLOR col(1.0f, 1.0f, 1.0f, 1.0f);
D3DLIGHT9 light;
light.Type = D3DLIGHT_DIRECTIONAL;
light.Ambient = col * 0.4f;
light.Diffuse = col;
light.Specular = col * 0.6f;
light.Direction = dir;
pDevice->SetLight(0, &light);
pDevice->LightEnable(0, true);
//pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE );
pDevice->SetRenderState(D3DRS_LIGHTING, TRUE);
//pDevice->SetRenderState(D3DRS_AMBIENT, 0xFFFFFFFF);
pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
pDevice->SetRenderState(D3DRS_SPECULARENABLE, true);
}
示例5: Render
HRESULT APPLICATION::Render()
{
// Clear the viewport
m_pDevice->Clear(0L, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffffffff, 1.0f, 0L );
// Begin the scene
if(SUCCEEDED(m_pDevice->BeginScene()))
{
//Set camera
D3DXMATRIX view, proj;
D3DXMatrixLookAtLH(&view, &D3DXVECTOR3(0.0f, 10.0f, -50.0f), &D3DXVECTOR3(0.0f, 3.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
D3DXMatrixOrthoLH(&proj, 10.0f, 9.0f, 0.1f, 1000.0f);
m_pDevice->SetTransform(D3DTS_VIEW, &view);
m_pDevice->SetTransform(D3DTS_PROJECTION, &proj);
if(m_wireframe)m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_WIREFRAME);
else m_pDevice->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
m_farmer1.Render();
m_farmer2.RenderProgressive();
//Number of polygons
char number[50];
std::string text = itoa(m_farmer2.GetNumProgressiveFaces(), number, 10);
text += " polygons (UP/DOWN Arrow)";
RECT r[] = {{170, 520, 0, 0}, {530, 520, 0, 0}, {470, 540, 0, 0}, {130, 540, 0, 0}};
m_pFont->DrawText(NULL, "Original", -1, &r[0], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000);
m_pFont->DrawText(NULL, "Progressive Mesh", -1, &r[1], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000);
m_pFont->DrawText(NULL, text.c_str(), -1, &r[2], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000);
m_pFont->DrawText(NULL, "(W)ireframe On/Off", -1, &r[3], DT_LEFT| DT_TOP | DT_NOCLIP, 0xff000000);
// End the scene.
m_pDevice->EndScene();
m_pDevice->Present(0, 0, 0, 0);
}
return S_OK;
}
示例6: DrawRay
void CubeMesh::DrawRay(const D3DXVECTOR2& screenPos,
const D3DXMATRIX& matWorld, const D3DXMATRIX& matView, const D3DXMATRIX& matProj)
{
HRESULT hr = S_FALSE;
GraphicsDevice* pGDevice = GraphicsDevice::getInstance();
IDirect3DDevice9* pDevice = pGDevice->m_pD3DDevice;
Ray ray = CalcPickingRay((int)screenPos.x, (int)screenPos.y,
pGDevice->mCubeViewport, matView, matProj );
PCVertex rayLine[] = {
{D3DXVECTOR3(0.0f,0.0f,0.0f), D3DCOLOR_ARGB(255,255,0,0)},
{ray.Origin + 1000*ray.Direction, D3DCOLOR_ARGB(255,255,0,0)},
};
PCVertex intersectPoint[] = {
{p, D3DCOLOR_ARGB(255,0,0,255)},
{p+D3DXVECTOR3(0.5f,0.0f,0.0f), D3DCOLOR_ARGB(255,0,0,255)},
{p+D3DXVECTOR3(0.0f,0.5f,0.0f), D3DCOLOR_ARGB(255,0,0,255)},
{p+D3DXVECTOR3(0.0f,0.0f,0.5f), D3DCOLOR_ARGB(255,0,0,255)},
{p+D3DXVECTOR3(-0.5f,0.0f,0.0f), D3DCOLOR_ARGB(255,0,0,255)},
{p+D3DXVECTOR3(0.0f,-0.5f,0.0f), D3DCOLOR_ARGB(255,0,0,255)},
{p+D3DXVECTOR3(0.0f,0.0f,-0.5f), D3DCOLOR_ARGB(255,0,0,255)},
};
pGDevice->SetViewport(pGDevice->mCubeViewport);
pDevice->SetVertexShader(NULL);
pDevice->SetPixelShader(NULL);
V(pDevice->SetTransform(D3DTS_WORLD, &matWorld));
V(pDevice->SetTransform(D3DTS_VIEW, &matView));
V(pDevice->SetTransform(D3DTS_PROJECTION, &matProj));
V(pDevice->SetRenderState(D3DRS_LIGHTING, FALSE));
V(pDevice->SetRenderState(D3DRS_ZENABLE, FALSE));
V(pDevice->SetFVF(D3DFVF_XYZ | D3DFVF_DIFFUSE));
V(pDevice->DrawPrimitiveUP(D3DPT_LINELIST, 1, rayLine, sizeof(PCVertex)));
V(pDevice->DrawPrimitiveUP(D3DPT_POINTLIST, 7, intersectPoint, sizeof(PCVertex)));
V(pDevice->SetFVF(NULL));
V(pDevice->SetRenderState(D3DRS_ZENABLE, TRUE));
V(pDevice->SetRenderState(D3DRS_LIGHTING, TRUE));
pGDevice->ResetViewport();
}
示例7:
//Function to check if the renderer is Direct 3D (If not, it's OpenGL)
bool GameDebugger::IsD3D(ALLEGRO_DISPLAY* mydisplay)
{
IDirect3DDevice9 * whatisthis = al_get_d3d_device(mydisplay);
if(!whatisthis)
return false;
HRESULT isDirect3D = NULL;
isDirect3D = whatisthis->SetRenderState(D3DRS_LIGHTING,false);
if(isDirect3D == D3D_OK)
return true;
return false;
}
示例8: setCommonBlitState
void Blit::setCommonBlitState()
{
IDirect3DDevice9 *device = getDevice();
device->SetDepthStencilSurface(NULL);
device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
device->SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED);
device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE);
device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
device->SetSamplerState(0, D3DSAMP_SRGBTEXTURE, FALSE);
device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
RECT scissorRect = {0}; // Scissoring is disabled for flipping, but we need this to capture and restore the old rectangle
device->SetScissorRect(&scissorRect);
}
示例9: InitRenderEffect
void UIRender::InitRenderEffect()
{
IDirect3DDevice9* pIDevice = UIDXInit::GetSingleton()->_pIDevice;
// 关闭灯光
pIDevice->SetRenderState( D3DRS_LIGHTING, false );
// 开启颜色alpha透明
pIDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, true );
pIDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
pIDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
// 高斯光栅 会产生颜色渐变效果
pIDevice->SetRenderState( D3DRS_SHADEMODE, D3DSHADE_GOURAUD );
// 不采用反面拣选
pIDevice->SetRenderState( D3DRS_CULLMODE, D3DCULL_NONE );
// 确定可视柱体
// 设置摄像头位置
UICamera::GetSingleton()->SetCameraView();
// 设置剪裁面宽高比、摄像头上下视角、前后剪裁面与摄像头距离
UICamera::GetSingleton()->SetPerspective( (float)( UIDXInit::GetSingleton()->GetPresentWidth() )/UIDXInit::GetSingleton()->GetPresentHeight() );
}
示例10: vEyePt
bool CScreen::SetDefaultGraphicsSettings3D()
{
HRESULT hr;
D3DXMATRIX identityTransform, projTransform;
D3DXMatrixIdentity(&identityTransform);
D3DXMatrixPerspectiveFovLH(&projTransform, D3DX_PI / 4, 1.0f, 1.0f, 100.0f);
D3DXVECTOR3 vEyePt(-10.0f, -10.0f, 10.0f);
D3DXVECTOR3 vLookatPt(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 vUpVec(0.0f, 0.0f, 1.0f);
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH(&matView, &vEyePt, &vLookatPt, &vUpVec);
D3DCOLORVALUE lightColor = {1.0f, 1.0f, 1.0f, 1.0f};
D3DXVECTOR3 lightDir(-1.0f, 0.7f, -0.2f);
D3DLIGHT9 light;
setupDirectionalLight(light, lightColor, lightDir);
D3DMATERIAL9 mtrl;
ZeroMemory( &mtrl, sizeof( D3DMATERIAL9 ) );
mtrl.Diffuse = lightColor;
mtrl.Ambient = lightColor;
mtrl.Ambient.g = 0.0f;
CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance();
IDirect3DDevice9 *pDevice = pGraphicsManager->GetDevice();
CCamera * pCamera = CCamera::GetInstance();
hr = pDevice->SetTransform(D3DTS_WORLD, &identityTransform);
if(FAILED(hr))
{
LogErrorHr("Failed to set world transform", hr);
return false;
}
D3DXMATRIX camViewMat = pCamera->GetViewMatrix();
hr = pDevice->SetTransform(D3DTS_VIEW, &camViewMat);
if(FAILED(hr))
{
LogErrorHr("Failed to set view transform", hr);
return false;
}
D3DXMATRIX camProjMat = pCamera->GetProjectionMatrix();
hr = pDevice->SetTransform(D3DTS_PROJECTION, &camProjMat);
if(FAILED(hr))
{
LogErrorHr("Failed to set projection transform", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
if(FAILED(hr))
{
LogErrorHr("Failed to set cull mode render state", hr);
return false;
}
hr = pDevice->SetLight(0, &light);
if(FAILED(hr))
{
LogErrorHr("Failed to set light 0", hr);
return false;
}
hr = pDevice->SetMaterial(&mtrl);
if(FAILED(hr))
{
LogErrorHr("Failed to set material", hr);
return false;
}
hr = pDevice->LightEnable(0, TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to enable light", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_AMBIENT, 0x00202020);
if(FAILED(hr))
{
LogErrorHr("Failed to set ambient color", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to enable z", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_ZWRITEENABLE , TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to set z write enabled", hr);
return false;
//.........这里部分代码省略.........
示例11: Restore
void CState::Restore()
{
// viewport
m_D3DDev->SetViewport(&m_Vp);
// render states
m_D3DDev->SetRenderState(D3DRS_ZENABLE, m_Z);
m_D3DDev->SetRenderState(D3DRS_CULLMODE, m_CullMode);
m_D3DDev->SetRenderState(D3DRS_ALPHATESTENABLE, m_AlphaTest);
m_D3DDev->SetRenderState(D3DRS_ALPHABLENDENABLE, m_AlphaBlend);
m_D3DDev->SetRenderState(D3DRS_BLENDOP, m_BlendOp);
m_D3DDev->SetRenderState(D3DRS_SRCBLEND, m_SrcBlend);
m_D3DDev->SetRenderState(D3DRS_DESTBLEND, m_DstBlend);
m_D3DDev->SetRenderState(D3DRS_CLIPPLANEENABLE, m_ClipPlane);
m_D3DDev->SetRenderState(D3DRS_FILLMODE, m_FillMode);
m_D3DDev->SetRenderState(D3DRS_LASTPIXEL, m_LastPixel);
m_D3DDev->SetRenderState(D3DRS_FOGENABLE, m_Fog);
m_D3DDev->SetRenderState(D3DRS_STENCILENABLE, m_Stencil);
m_D3DDev->SetRenderState(D3DRS_COLORWRITEENABLE, m_ColorWrite);
m_D3DDev->SetRenderState(D3DRS_SCISSORTESTENABLE, m_Scissor);
if( m_Caps.PrimitiveMiscCaps & D3DPMISCCAPS_SEPARATEALPHABLEND )
m_D3DDev->SetRenderState(D3DRS_SEPARATEALPHABLENDENABLE, m_SeparateAlphaBlend);
//if( m_Caps.LineCaps & D3DLINECAPS_ANTIALIAS )
m_D3DDev->SetRenderState(D3DRS_ANTIALIASEDLINEENABLE, m_AntiAliasedLine);
// primitive
m_D3DDev->SetFVF(m_FVF);
m_D3DDev->SetStreamSource(0, m_StreamData, m_StreamOffset, m_StreamStride);
if( m_StreamData )
m_StreamData->Release();
m_D3DDev->SetVertexShader(m_VertexShader);
if( m_VertexShader )
m_VertexShader->Release();
// texture
m_D3DDev->SetTexture(0, m_Tex);
if( m_Tex )
m_Tex->Release();
m_D3DDev->SetPixelShader(m_PixelShader);
if( m_PixelShader )
m_PixelShader->Release();
// texture stage states
m_D3DDev->SetTextureStageState(0, D3DTSS_COLOROP, m_ColorOp);
m_D3DDev->SetTextureStageState(0, D3DTSS_COLORARG1, m_ColorArg1);
m_D3DDev->SetTextureStageState(0, D3DTSS_COLORARG2, m_ColorArg2);
m_D3DDev->SetTextureStageState(0, D3DTSS_ALPHAOP, m_AlphaOp);
m_D3DDev->SetTextureStageState(0, D3DTSS_ALPHAARG1, m_AlphaArg1);
m_D3DDev->SetTextureStageState(0, D3DTSS_TEXCOORDINDEX, m_TexCoordIndex);
m_D3DDev->SetTextureStageState(0, D3DTSS_TEXTURETRANSFORMFLAGS, m_TexTransfFlags);
m_D3DDev->SetSamplerState(0, D3DSAMP_ADDRESSU, m_AddressU);
m_D3DDev->SetSamplerState(0, D3DSAMP_ADDRESSV, m_AddressV);
m_D3DDev->SetSamplerState(0, D3DSAMP_MAGFILTER, m_MagFilter);
m_D3DDev->SetSamplerState(0, D3DSAMP_MINFILTER, m_MinFilter);
m_D3DDev->SetSamplerState(0, D3DSAMP_MIPFILTER, m_MipFilter);
}
示例12:
bool CScreen::SetDefaultGraphicsSettings2D()
{
HRESULT hr;
CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance();
IDirect3DDevice9 *pDevice = pGraphicsManager->GetDevice();
D3DXMATRIX identityTransform, projTransform;
D3DXMatrixIdentity(&identityTransform);
D3DXMatrixOrthoLH(&projTransform, 100.0f * pGraphicsManager->GetAspectRatio(), 100.0f, -1.0f, 1.0f);
hr = pDevice->SetTransform(D3DTS_WORLD, &identityTransform);
if(FAILED(hr))
{
LogErrorHr("Failed to set world transform", hr);
return false;
}
hr = pDevice->SetTransform(D3DTS_VIEW, &identityTransform);
if(FAILED(hr))
{
LogErrorHr("Failed to set view transform", hr);
return false;
}
hr = pDevice->SetTransform(D3DTS_PROJECTION, &projTransform);
if(FAILED(hr))
{
LogErrorHr("Failed to set projection transform", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
if(FAILED(hr))
{
LogErrorHr("Failed to set cull mode render state", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to enable z", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_ZWRITEENABLE, TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to set z write enabled", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_LIGHTING, FALSE);
if(FAILED(hr))
{
LogErrorHr("Failed to set lighting to false", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
if(FAILED(hr))
{
LogErrorHr("Failed to set alpha blending to true", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
if(FAILED(hr))
{
LogErrorHr("Failed to set alpha source render state", hr);
return false;
}
hr = pDevice->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
if(FAILED(hr))
{
LogErrorHr("Failed to set alpha dest render state", hr);
return false;
}
return true;
}
示例13: WinMain
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int){
Application app("Okienko");
// Inicjalizacja Direct3D
IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);
// Parametry urzadzenia
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferHeight = app.get_height();
d3dpp.BackBufferWidth = app.get_width();
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
// Tworzenie urzadzenia
IDirect3DDevice9* dev;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, app.window_handle(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &dev);
app.init_font(dev, "Courier New");
dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // Brak obcinania scian
dev->SetRenderState(D3DRS_LIGHTING, false); // Brak swiatla
// Inicjalizacja kamery
// D3DXVECTOR3 eye(0, 5, -10);
D3DXVECTOR3 target(0, 0, 0);
D3DXVECTOR3 up(0, 1, 0);
D3DXMATRIXA16 view;
D3DXMATRIX mProjection;
D3DXMatrixPerspectiveFovLH(&mProjection, D3DX_PI * 0.5f, app.get_width()/(float)app.get_height(), 1, 50);
dev->SetTransform(D3DTS_PROJECTION, &mProjection);
// Model pudelka
Vertex box[] = {
// X Y Z Color
{ 1, 1, 1, D3DCOLOR_XRGB(255, 255, 255)},
{-1, 1, 1, D3DCOLOR_XRGB(0, 255, 255)},
{-1, 1, -1, D3DCOLOR_XRGB(0, 255, 0)},
{ 1, 1, -1, D3DCOLOR_XRGB(255, 255, 0)},
{ 1, -1, 1, D3DCOLOR_XRGB(255, 0, 255)},
{-1, -1, 1, D3DCOLOR_XRGB(0, 0, 255)},
{-1, -1, -1, D3DCOLOR_XRGB(0, 0, 0)},
{ 1, -1, -1, D3DCOLOR_XRGB(255, 0, 0)},
box[0], box[4], box[1], box[5], box[2], box[6], box[3], box[7], box[0], box[4]
};
int box_size = (16 + 2) * sizeof(Vertex);
// Tworzenie bufora wierzcholkow
IDirect3DVertexBuffer9* box_buffer;
dev->CreateVertexBuffer(box_size, 0, Vertex_Format, D3DPOOL_MANAGED, &box_buffer, NULL);
VOID* pVoid;
box_buffer->Lock(0, box_size, (void**)&pVoid, 0);
memcpy(pVoid, box, box_size);
box_buffer->Unlock();
dev->SetFVF(Vertex_Format);
dev->SetStreamSource(0, box_buffer, 0, sizeof(Vertex));
float radius = 3;
while(app.running()){
float alfa = app.get_alfa();
float beta = app.get_beta();
// Aktualizujemy kamere
D3DXVECTOR3 eye(
radius * cos(alfa) * sin(beta),
radius * cos(beta),
radius * sin(alfa) * sin(beta)
);
D3DXMatrixLookAtLH(&view, &eye, &target, &up);
dev->SetTransform(D3DTS_VIEW, &view);
// Rysujemy pudeleczko
dev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
dev->BeginScene();
for(int i = 0; i < 2; i++) dev->DrawPrimitive(D3DPT_TRIANGLEFAN, i*4, 2);
dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 8);
app.print(10, 10, "Mysz X = %d", app.get_mouse_x());
app.print(10, 24, "Mysz Y = %d", app.get_mouse_y());
dev->EndScene();
dev->Present(NULL, NULL, NULL, NULL);
}
// Zwalniamy zasoby
box_buffer->Release();
dev->Release();
d3d->Release();
//.........这里部分代码省略.........
示例14: createCleanState
void DevState::createCleanState() {
if (dwMyThread != 0) {
ods("D3D9: CreateCleanState from other thread.");
}
Stash<DWORD> stashThread(&dwMyThread, GetCurrentThreadId());
if (pSB)
pSB->Release();
pSB = NULL;
IDirect3DStateBlock9* pStateBlock = NULL;
dev->CreateStateBlock(D3DSBT_ALL, &pStateBlock);
if (! pStateBlock)
return;
pStateBlock->Capture();
dev->CreateStateBlock(D3DSBT_ALL, &pSB);
if (! pSB) {
pStateBlock->Release();
return;
}
D3DVIEWPORT9 vp;
dev->GetViewport(&vp);
dev->SetVertexShader(NULL);
dev->SetPixelShader(NULL);
dev->SetFVF(D3DFVF_TLVERTEX);
dev->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
dev->SetRenderState(D3DRS_SHADEMODE, D3DSHADE_GOURAUD);
dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // 0x16
dev->SetRenderState(D3DRS_WRAP0, FALSE); // 0x80
dev->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
dev->SetRenderState(D3DRS_SRCBLEND, D3DBLEND_ONE);
dev->SetRenderState(D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
dev->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE);
dev->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_GREATER);
dev->SetRenderState(D3DRS_ZENABLE, FALSE);
dev->SetRenderState(D3DRS_ZWRITEENABLE, FALSE);
dev->SetRenderState(D3DRS_ZFUNC, D3DCMP_ALWAYS);
dev->SetRenderState(D3DRS_COLORVERTEX, FALSE);
dev->SetTextureStageState(0, D3DTSS_ALPHAOP, D3DTOP_MODULATE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE);
dev->SetTextureStageState(0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE);
dev->SetRenderState(D3DRS_LIGHTING, FALSE);
pSB->Capture();
pStateBlock->Apply();
pStateBlock->Release();
}
示例15: float
// parameters should be validated/clamped by caller
EGLint SwapChain9::swapRect(EGLint x, EGLint y, EGLint width, EGLint height)
{
if (!mSwapChain)
{
return EGL_SUCCESS;
}
IDirect3DDevice9 *device = mRenderer->getDevice();
// Disable all pipeline operations
device->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
device->SetRenderState(D3DRS_FILLMODE, D3DFILL_SOLID);
device->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE);
device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
device->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE);
device->SetRenderState(D3DRS_STENCILENABLE, FALSE);
device->SetRenderState(D3DRS_CLIPPLANEENABLE, 0);
device->SetRenderState(D3DRS_COLORWRITEENABLE, D3DCOLORWRITEENABLE_ALPHA | D3DCOLORWRITEENABLE_BLUE | D3DCOLORWRITEENABLE_GREEN | D3DCOLORWRITEENABLE_RED);
device->SetRenderState(D3DRS_SRGBWRITEENABLE, FALSE);
device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
device->SetPixelShader(NULL);
device->SetVertexShader(NULL);
device->SetRenderTarget(0, mBackBuffer);
device->SetDepthStencilSurface(NULL);
device->SetTexture(0, mOffscreenTexture);
device->SetTextureStageState(0, D3DTSS_COLOROP, D3DTOP_SELECTARG1);
device->SetTextureStageState(0, D3DTSS_COLORARG1, D3DTA_TEXTURE);
device->SetTextureStageState(1, D3DTSS_COLOROP, D3DTOP_DISABLE);
device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_POINT);
device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_CLAMP);
device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_CLAMP);
device->SetFVF(D3DFVF_XYZRHW | D3DFVF_TEX1);
D3DVIEWPORT9 viewport = {0, 0, mWidth, mHeight, 0.0f, 1.0f};
device->SetViewport(&viewport);
float x1 = x - 0.5f;
float y1 = (mHeight - y - height) - 0.5f;
float x2 = (x + width) - 0.5f;
float y2 = (mHeight - y) - 0.5f;
float u1 = x / float(mWidth);
float v1 = y / float(mHeight);
float u2 = (x + width) / float(mWidth);
float v2 = (y + height) / float(mHeight);
float quad[4][6] = {{x1, y1, 0.0f, 1.0f, u1, v2},
{x2, y1, 0.0f, 1.0f, u2, v2},
{x2, y2, 0.0f, 1.0f, u2, v1},
{x1, y2, 0.0f, 1.0f, u1, v1}}; // x, y, z, rhw, u, v
mRenderer->startScene();
device->DrawPrimitiveUP(D3DPT_TRIANGLEFAN, 2, quad, 6 * sizeof(float));
mRenderer->endScene();
device->SetTexture(0, NULL);
RECT rect =
{
x, mHeight - y - height,
x + width, mHeight - y
};
HRESULT result = mSwapChain->Present(&rect, &rect, NULL, NULL, 0);
mRenderer->markAllStateDirty();
if (d3d9::isDeviceLostError(result))
{
return EGL_CONTEXT_LOST;
}
if (result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY || result == D3DERR_DRIVERINTERNALERROR)
{
return EGL_BAD_ALLOC;
}
ASSERT(SUCCEEDED(result));
return EGL_SUCCESS;
}