Esempio n. 1
0
void render()
{
    // Clear
    oRenderer->clear(OColorHex(1d232d));

    // Draw stuff to our render target
    oRenderer->renderStates.renderTarget.push(pRenderTarget);
    oRenderer->renderStates.viewport.push({0, 0, pRenderTarget->getSize().x, pRenderTarget->getSize().y});
    oSpriteBatch->begin();
    oSpriteBatch->drawRect(pTextureFromFile, {0, 0, 128, 128});
    oSpriteBatch->drawRect(pTextureFromFile, {128, 0, 128, 128});
    oSpriteBatch->drawRect(pTextureFromFile, {0, 128, 128, 128});
    oSpriteBatch->drawRect(pTextureFromFile, {128, 128, 128, 128});
    oSpriteBatch->end();
    oRenderer->renderStates.viewport.pop();
    oRenderer->renderStates.renderTarget.pop();

    // Update our dynamic texture
    auto animValue = dynamicAnim.get();
    for (auto j = 0; j < 128; ++j)
    {
        for (auto i = 0; i < 128; ++i)
        {
            auto k = (j * 128 + i) * 4;
            dynamicData[k + 0] = j * 2 - animValue;
            dynamicData[k + 1] = j * 2 + animValue;
            dynamicData[k + 2] = j * 2;
            dynamicData[k + 3] = 255;
        }
    }
    pDynamic->setData(dynamicData);

    // Draw out resulted textures
    auto pFont = OGetFont("font.fnt");
    oSpriteBatch->begin(Matrix::CreateTranslation(80, 212, 0));
    oSpriteBatch->changeFiltering(OFilterNearest);

    oSpriteBatch->drawRect(pTextureFromFile, {0, 0, 128, 128});
    oSpriteBatch->drawRect(pTextureFromFileData, {128, 0, 128, 128});
    oSpriteBatch->drawRect(pTextureFromData, {256, 0, 128, 128});
    oSpriteBatch->drawRect(pRenderTarget, {384, 0, 128, 128});
    oSpriteBatch->drawRect(pDynamic, {512, 0, 128, 128});
    
    pFont->draw("From File", {64, 140}, OCenter);
    pFont->draw("From File Data", {64 + 128, 140}, OCenter);
    pFont->draw("From Data", {64 + 256, 140}, OCenter);
    pFont->draw("Render Target", {64 + 384, 140}, OCenter);
    pFont->draw("Dynamic", {64 + 512, 140}, OCenter);
    
    oSpriteBatch->end();
}
Esempio n. 2
0
void render()
{
    // Clear
    oRenderer->clear(OColorHex(1d232d));

    // Draw Info
    auto pFont = OGetFont("font.fnt");

    oSpriteBatch->begin();

    pFont->draw("Original: ", {10, 10});
    pFont->draw(originalText, {200, 10}, OTopLeft, Color(.7f, 1.f));

    pFont->draw("Simple Hash: ", {10, 30});
    pFont->draw(std::to_string(hash), {200, 30}, OTopLeft, Color(.7f, 1.f));

    pFont->draw("Sha1: ", {10, 50});
    pFont->draw(sha1, {200, 50}, OTopLeft, Color(.7f, 1.f));

    pFont->draw("Shitty email validation: ", {10, 70});
    Vector2 pos(200, 70);
    for (auto& email : emails)
    {
        if (email.second)
        {
            pFont->draw(email.first, pos, OTopLeft, Color(0, 1, 0, 1.f));
        }
        else
        {
            pFont->draw(email.first, pos, OTopLeft, Color(1, 0, 0, 1.f));
        }
        pos.y += 12;
    }

    oSpriteBatch->end();
}
Esempio n. 3
0
void NESEditor::render()
{
    oRenderer->clear(Color(0, 0, 0, 1));

    auto pFont = OGetFont("font.fnt");

    oSpriteBatch->begin();
    oSpriteBatch->changeFiltering(OFilterNearest);

    // Tileset
    pFont->draw("Tileset:", Vector2::Zero);
    for (size_t i = 0; i < m_tilesets[0].size(); ++i)
    {
        drawTile(static_cast<TileId>(i),
                 Vector2(static_cast<float>(i % 64 * 16), static_cast<float>(i / 64 * 16 + 16)));
    }

    // Objects
    pFont->draw("Objects:", Vector2(0, 64 + 16));
    Point pos(0, 0);
    auto maxY = pos.y;
    for (auto& object : m_objects)
    {
        oSpriteBatch->drawRect(nullptr, {
            static_cast<float>(pos.x * 16),
            static_cast<float>(64 + 32 + pos.y * 16),
            static_cast<float>(object.width * 16),
            static_cast<float>(object.height * 16)},
            Color(.25f, .25f, .25f, 1));
        oSpriteBatch->drawRect(nullptr, {
            static_cast<float>(pos.x * 16),
            static_cast<float>(64 + 32 + pos.y * 16),
            1,
            static_cast<float>(object.height * 16)},
            Color(.75f, .75f, .75f, 1));
        oSpriteBatch->drawRect(nullptr, {
            static_cast<float>((pos.x + object.width) * 16 - 1),
            static_cast<float>(64 + 32 + pos.y * 16),
            1,
            static_cast<float>(object.height * 16)},
            Color(.75f, .75f, .75f, 1));
        oSpriteBatch->drawRect(nullptr, {
            static_cast<float>(pos.x * 16),
            static_cast<float>(64 + 32 + pos.y * 16),
            static_cast<float>(object.width * 16),
            1},
            Color(.75f, .75f, .75f, 1));
        oSpriteBatch->drawRect(nullptr, {
            static_cast<float>(pos.x * 16),
            static_cast<float>(64 + 32 + (pos.y + object.height) * 16 - 1),
            static_cast<float>(object.width * 16),
            1},
            Color(.75f, .75f, .75f, 1));

        for (int y = 0; y < object.height; ++y)
        {
            for (int x = 0; x < object.width; ++x)
            {
                drawTile(object.tiles[y * object.width + x], 
                         Vector2(static_cast<float>((pos.x + x) * 16), static_cast<float>(64 + 32 + (pos.y + y) * 16)));
            }
        }
        pos.x += object.width;
        maxY = std::max(maxY, pos.y + object.height);
        if (pos.x >= 64)
        {
            pos.x = 0;
            pos.y = maxY;
        }
    }

    m_usedChr.clear();

    // Board
    for (int y = 0; y < BOARD_HEIGHT; ++y)
    {
        for (int x = 0; x < BOARD_WIDTH; ++x)
        {
            drawTile(m_board[y * BOARD_WIDTH + x],
                     Vector2(static_cast<float>(x * 16), static_cast<float>(y * 16 + 256)));
        }
    }

    // Objects on board
    for (auto& objectInstance : m_objectInstances)
    {
        auto& object = *objectInstance.pObject;
        pos.x = objectInstance.x;
        pos.y = objectInstance.y;
        for (int y = 0; y < object.height; ++y)
        {
            for (int x = 0; x < object.width; ++x)
            {
                drawTile(object.tiles[y * object.width + x], 
                         Vector2(static_cast<float>((pos.x + x) * 16), static_cast<float>((pos.y + y) * 16) + 256));
            }
        }
    }

    // Selected object, semi-transparent
    if (m_pSelectedObject)
    {
        oSpriteBatch->changeBlendMode(OBlendAdd);
        auto& object = *m_pSelectedObject;
        pos = oInput->mousePos / 16;
        for (int y = 0; y < object.height; ++y)
        {
            for (int x = 0; x < object.width; ++x)
            {
                drawTile(object.tiles[y * object.width + x], 
                         Vector2(static_cast<float>((pos.x + x) * 16), static_cast<float>((pos.y + y) * 16)));
            }
        }
    }

    // Chr
    oSpriteBatch->drawRect(m_pCharTexture, {OScreenWf - 256, 256, 256, 256});
    oSpriteBatch->changeBlendMode(OBlendPreMultiplied);
    for (auto& chr : m_usedChr)
    {
        oSpriteBatch->drawRect(nullptr, {OScreenWf - 256 + static_cast<float>((chr % 16) * 16), 256 + static_cast<float>((chr / 16) * 16), 16, 16}, Color(0, .5f, 0, 0));
    }

    oSpriteBatch->end();
}