#include "Framework.h" #ifndef TEXTURE_SCREEN_QUAD_CPP #define TEXTURE_SCREEN_QUAD_CPP using namespace fw; template<typename Version> TextureScreenQuad<Version>::TextureScreenQuad() : MeshSceneNode("TextureScreenQuad"), m_fAlpha(1.0f), m_pRT(nullptr) { ZeroMemory(&m_aQuadVertices, sizeof(PTVertex) * 6); MeshSceneNode::SetDrawMethod(Renderable::DrawMethod::DRAW_INDEXED); MeshSceneNode::SetVertexType(VertexLayoutType::PT_VERTEX); } template<typename Version> TextureScreenQuad<Version>::~TextureScreenQuad() { SAFE_CAST_RELEASE(m_pTextureRessourceView); } template<typename Version> bool TextureScreenQuad<Version>::Initialize() { m_iScreenWidth = SYSTEM->GetRenderer()->GetViewportWidth(); m_iScreenHeight = SYSTEM->GetRenderer()->GetViewportHeight(); if (!Update()) { MessageBoxA(nullptr, "Erreur d'initialisation d'un TextureScreenQuad !", "Erreur", MB_ICONHAND | MB_OK); } return MeshSceneNode::Initialize(); } template<typename Version> void TextureScreenQuad<Version>::SetTransparency(float fValue) { m_Color.a = fValue; if (MeshSceneNode::GetShaderTechnique() != nullptr) { MeshSceneNode::GetShaderTechnique()->SetColor("Color", m_Color); } } template<typename Version> void TextureScreenQuad<Version>::SetColor(const D3DXCOLOR& color) { m_Color = color; if (MeshSceneNode::GetShaderTechnique() != nullptr) { MeshSceneNode::GetShaderTechnique()->SetColor("Color", m_Color); } } template<typename Version> bool TextureScreenQuad<Version>::OnRender(float fTimeSinceLastFrame) { if (MeshSceneNode::IsVisible()) { D3D10_RENDERER->EnableZBuffer(false); MeshSceneNode::OnRender(fTimeSinceLastFrame); D3D10_RENDERER->EnableZBuffer(true); } return true; } template<typename Version> bool TextureScreenQuad<Version>::Update() { float left, right, top, bottom; left = (float) -m_iScreenWidth / 2; right = left + (float) m_iScreenWidth; top = (float) -m_iScreenHeight / 2; bottom = top + (float) m_iScreenHeight; // Premier triangle m_aQuadVertices[0].pos = D3DXVECTOR3(left, top, 0.0f); // Top left. m_aQuadVertices[0].texture = D3DXVECTOR2(0.0f, 0.0f); m_aQuadVertices[1].pos = D3DXVECTOR3(right, bottom, 0.0f); // Bottom right. m_aQuadVertices[1].texture = D3DXVECTOR2(1.0f, 1.0f); m_aQuadVertices[2].pos = D3DXVECTOR3(left, bottom, 0.0f); // Bottom left. m_aQuadVertices[2].texture = D3DXVECTOR2(0.0f, 1.0f); // Deuxième triangle m_aQuadVertices[3].pos = D3DXVECTOR3(left, top, 0.0f); // Top left. m_aQuadVertices[3].texture = D3DXVECTOR2(0.0f, 0.0f); m_aQuadVertices[4].pos = D3DXVECTOR3(right, top, 0.0f); // Top right. m_aQuadVertices[4].texture = D3DXVECTOR2(1.0f, 0.0f); m_aQuadVertices[5].pos = D3DXVECTOR3(right, bottom, 0.0f); // Bottom right. m_aQuadVertices[5].texture = D3DXVECTOR2(1.0f, 1.0f); // On déclare les tableaux std::vector<PTVertex> vertices; // On reset les emplacements vertices.resize(6); // On affecte les valeurs std::copy(m_aQuadVertices, m_aQuadVertices + 6, vertices.begin()); unsigned short i[6] = { 0, 1, 2, 3, 4, 5 }; // On déclare les tableaux std::vector<uint16> indices; // On reset les emplacements indices.resize(6); // On affecte les valeurs std::copy(i, i + 6, indices.begin()); MeshSceneNode::BuildMesh(vertices, indices); return true; } template<typename Version> void TextureScreenQuad<Version>::SetQuadSize(fw::size_t16 iWidth, fw::size_t16 iHeight) { m_iScreenWidth = iWidth; m_iScreenHeight = iHeight; Update(); } template<typename Version> RenderTarget* TextureScreenQuad<Version>::GetRT() { return m_pRT; } template<typename Version> bool TextureScreenQuad<Version>::SetShaderTechnique(ShaderTechnique* pShader) { bool bSuccess = MeshSceneNode::SetShaderTechnique(pShader); if (m_pRT == nullptr) { m_pRT = new RenderTarget(); m_pRT->Initialize(m_iScreenWidth, m_iScreenHeight); MeshSceneNode::SetColor(D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f)); } return bSuccess; } #endif