Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - cepro

Pages: [1]
1
Graphics / Render a rectangle with vertices using a texture and a color
« on: August 18, 2014, 03:22:54 am »
Hello,

This is maybe easy to achieve but (as I just started learning Graphics Programming) I couldn't manage to get it working as intended.
So I have a red rectangle rendered via a vertex array :

Now I want to draw on top of it a texture (white question mark with transparent background) using "textCoord" :

so the final result would be like this :

But this is what I get instead:

I assume this because SFML infernally multiplies the texture's pixels by the vertices' colors. If that's true, how can I change the blend mode used to draw the rectangle? And what's the appropriate mode to use in this case?

Thank you in advance.

PS: Here is a minimal code ("questionMark.png" is attached to this post):
int main()
{
    sf::RenderWindow window(sf::VideoMode(400, 240), "My window");

    sf::Texture texture;
    if (!texture.loadFromFile("questionMark.png"))
    {
        // error...
    }

    // create an array of 4 vertices that define a quad primitive
    sf::VertexArray quad(sf::Quads, 4);

    // define the position of the quad's points
    quad[0].position = sf::Vector2f(10, 10);
    quad[1].position = sf::Vector2f(100, 10);
    quad[2].position = sf::Vector2f(100, 100);
    quad[3].position = sf::Vector2f(10, 100);

    // define the color of the quad's points
    quad[0].color = sf::Color::Red;
    quad[1].color = sf::Color::Red;
    quad[2].color = sf::Color::Red;
    quad[3].color = sf::Color::Red;

    // define its texture area
    quad[0].texCoords = sf::Vector2f(0, 0);
    quad[1].texCoords = sf::Vector2f(8, 0);
    quad[2].texCoords = sf::Vector2f(8, 8);
    quad[3].texCoords = sf::Vector2f(0, 8);

    // define the render states
    sf::RenderStates states;
    //states.blendMode = ???;
    states.texture = &texture;


    // run the program as long as the window is open
    while (window.isOpen())
    {
        // check all the window's events that were triggered since the last iteration of the loop
        sf::Event event;
        while (window.pollEvent(event))
        {
            // "close requested" event: we close the window
            if (event.type == sf::Event::Closed)
                window.close();
        }

        // clear the window with black color
        window.clear(sf::Color::Black);

        // draw everything here...
        window.draw(quad, states);

        // end the current frame
        window.display();
    }

    return 0;
}
 

Pages: [1]