SharePtr<CMaterial> CFontManager::CreateDefaultMaterial(bool bBitmapFont)
{
    if(!m_pProgramFreetypeText)
    {
        SharePtr<CShader> pVS = CResourceManager::GetInstance()->
            GetResource<CShader>(_T("TextShader.vs"));
        SharePtr<CShader> pPS = CResourceManager::GetInstance()->
            GetResource<CShader>(_T("TextShader.ps"));
        BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!"));
        m_pProgramFreetypeText = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID());
    }
    if(!m_pProgramBitmapText)
    {
        SharePtr<CShader> pVS = CResourceManager::GetInstance()->
            GetResource<CShader>(_T("PointTexShader.vs"));
        SharePtr<CShader> pPS = CResourceManager::GetInstance()->
            GetResource<CShader>(_T("PointTexShader.ps"));
        BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!"));
        m_pProgramBitmapText = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID());
    }
    SharePtr<CMaterial> material = new CMaterial();
    material->GetRenderState()->SetBoolState(CBoolRenderStateParam::eBSP_ScissorTest, false);
    material->GetRenderState()->SetBoolState(CBoolRenderStateParam::eBSP_Blend, true);
    material->GetRenderState()->SetBlendFuncSrcFactor(GL_SRC_ALPHA);
    material->GetRenderState()->SetBlendFuncTargetFactor(GL_ONE_MINUS_SRC_ALPHA);
    material->GetRenderState()->SetShaderProgram(bBitmapFont ? m_pProgramBitmapText->ID() : m_pProgramFreetypeText->ID());

    return material;
}
Exemple #2
0
SharePtr<CMaterial> CSystem::CreateDefaultMaterial()
{
    if(!m_pProgram)
    {
        InitShader();
    }
    BEATS_ASSERT(m_pProgram);
    SharePtr<CMaterial> material = new CMaterial(true);
    material->GetRenderState()->SetBoolState(GL_DEPTH_TEST, false);
    material->GetRenderState()->SetBoolState(GL_BLEND, true);
    material->GetRenderState()->SetBlendFuncSrcFactor(GL_SRC_ALPHA);
    material->GetRenderState()->SetBlendFuncTargetFactor(GL_ONE_MINUS_SRC_ALPHA);
    material->GetRenderState()->SetShaderProgram(m_pProgram->ID());
    return material;
}
SharePtr<CMaterial> CComponentGraphic_GL::CreateMaterial(const TString &textureFileName)
{
    SharePtr<CMaterial> material = new CMaterial(true);
    material->GetRenderState()->SetBoolState(GL_DEPTH_TEST, true);
    material->GetRenderState()->SetBoolState(GL_ALPHA_TEST, true);
    material->GetRenderState()->SetAlphaFunc(GL_GREATER);
    material->GetRenderState()->SetAlphaRef(0);
    material->GetRenderState()->SetBoolState(GL_BLEND, true);
    material->GetRenderState()->SetBlendFuncSrcFactor(GL_SRC_ALPHA);
    material->GetRenderState()->SetBlendFuncTargetFactor(GL_ONE_MINUS_SRC_ALPHA);
    SharePtr<CShader> pVS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.vs"), false);
    SharePtr<CShader> pPS = CResourceManager::GetInstance()->GetResource<CShader>(_T("PointTexShader.ps"), false);
    BEATS_ASSERT(pVS && pPS, _T("Load Shader Failed!"));
    CShaderProgram *program = CRenderManager::GetInstance()->GetShaderProgram(pVS->ID(), pPS->ID());
    material->GetRenderState()->SetShaderProgram(program->ID());
    SharePtr<CTexture> texture = CResourceManager::GetInstance()->GetResource<CTexture>(textureFileName, false);
    BEATS_ASSERT(texture, _T("Create Component Texture Failed!"));
    material->SetTexture(0, texture);
    return material;
}