コード例 #1
0
ファイル: Player.cpp プロジェクト: Angeldude/essentialmath
//-------------------------------------------------------------------------------
// Utility function to load texture
//-------------------------------------------------------------------------------
static IvTexture* CreateTextureFromFile(const char* file)
{
    IvTexture* tex = nullptr;

    // Load the image into this texture
    IvImage* image = IvImage::CreateFromFile(file);
    if (image)
    {
        if (image->GetBytesPerPixel() == 4)
        {
            tex = IvRenderer::mRenderer->GetResourceManager()->CreateTexture(
                kRGBA32TexFmt, image->GetWidth(), image->GetHeight(), nullptr, kDefaultUsage);

            unsigned char* pixels = (unsigned char*)(tex->BeginLoadData(0));
            CopyAndPremulAlpha(pixels, image->GetPixels(), image->GetWidth(), image->GetHeight());
            tex->EndLoadData(0);
        }
        else
        {
            tex = IvRenderer::mRenderer->GetResourceManager()->CreateTexture(
                kRGB24TexFmt, image->GetWidth(), image->GetHeight(), image->GetPixels(), kImmutableUsage);
        }

        delete image;
        image = 0;
    }

    tex->SetMagFiltering(kBilerpTexMagFilter);
    tex->SetMinFiltering(kBilerpTexMinFilter);
    tex->SetAddressingU(kWrapTexAddr);
    tex->SetAddressingV(kWrapTexAddr);

    return tex;
}
コード例 #2
0
ファイル: Player.cpp プロジェクト: dtbinh/essentialmath
//-------------------------------------------------------------------------------
// @ Player::Player()
//-------------------------------------------------------------------------------
// Constructor
//-------------------------------------------------------------------------------
Player::Player()
{
    mRotate.Identity();
    mScale = 1.0f;
    mTranslate.Zero();

    mPlaneIndices = nullptr;

    mPlaneVerts = nullptr;

    mColorTexture = nullptr;
    mNormalTexture = nullptr;

    // Load the color and normal textures
    IvImage* image = IvImage::CreateFromFile("brickwork-texture.tga");
    if (image)
    {
        mColorTexture = IvRenderer::mRenderer->GetResourceManager()->CreateTexture(
            (image->GetBytesPerPixel() == 4) ? kRGBA32TexFmt : kRGB24TexFmt,
            image->GetWidth(), image->GetHeight(), image->GetPixels(), kImmutableUsage);

        delete image;
        image = 0;
    }
    mColorTexture->SetMagFiltering(kBilerpTexMagFilter);
    mColorTexture->SetMinFiltering(kBilerpTexMinFilter);
    mColorTexture->SetAddressingU(kWrapTexAddr);
    mColorTexture->SetAddressingV(kWrapTexAddr);

    image = IvImage::CreateFromFile("brickwork_normal-map.tga");
    if (image)
    {
        mNormalTexture = IvRenderer::mRenderer->GetResourceManager()->CreateTexture(
            (image->GetBytesPerPixel() == 4) ? kRGBA32TexFmt : kRGB24TexFmt,
            image->GetWidth(), image->GetHeight(), image->GetPixels(), kImmutableUsage);

        delete image;
        image = 0;
    }
    mNormalTexture->SetMagFiltering(kBilerpTexMagFilter);
    mNormalTexture->SetMinFiltering(kBilerpTexMinFilter);
    mNormalTexture->SetAddressingU(kWrapTexAddr);
    mNormalTexture->SetAddressingV(kWrapTexAddr);

    mShader = IvRenderer::mRenderer->GetResourceManager()->CreateShaderProgram(
        IvRenderer::mRenderer->GetResourceManager()->CreateVertexShaderFromFile(
        "normalShader"),
        IvRenderer::mRenderer->GetResourceManager()->CreateFragmentShaderFromFile(
        "normalShader"));

    mShader->GetUniform("NormalTexture")->SetValue(mNormalTexture);
    mShader->GetUniform("ColorTexture")->SetValue(mColorTexture);

    mLightPos = IvVector3(-0.8f, 0.8f, 0.8f);
    mLightPos.Normalize();

    IvRenderer::mRenderer->SetShaderProgram(mShader);

    CreatePlane();
}   // End of Player::Player()