1
\$\begingroup\$

Here is the problem: I'm rendering a red triangle in an offscreen Frame Buffer Object. I have a texture of that Buffer, and i'm applying this texture to a Simple rectangle(at runtime).

I get This result: The rectangle is showing what the other buffer is rendering

This is exactly what i wanted. the problem is that when i strech my window the texture gets a little weird:

The texture seems to be moving to the right while streching the window

Just for curiosity i tried to render the rectangle without the texture.

Here it looks fine

And then I stretched the window once again:

The rect is kind of following the window while it's beeing stretched

I believe this is happening because in my default FBO I am setting glViewport to glViewport(0,0,m_Width,m_Height); (m_Width and m_Height are the dimensions of the Window)

\$\endgroup\$
2
  • \$\begingroup\$ I forgot to say i am using glfw as the windowing api. About glViewport, i am setting it every frame. Maybe this happens because i don't have a projection matrix of any sort.. \$\endgroup\$
    – user100681
    Nov 1, 2017 at 12:01
  • \$\begingroup\$ if you don't have projection matrix, it defaults to -1 to 1 and your rectangle, of course, automatically follow that if you didn't update the rectangle coordinates. \$\endgroup\$
    – Greffin28
    Nov 2, 2017 at 10:42

1 Answer 1

0
\$\begingroup\$

Your guess is correct. Every time you resize your window, make sure both of your glViewport() and projection matrix are up to date. In SFML it would be something like this:

while (running) {
    sf::Event e;
    while (wind.pollEvent(e)) {
        switch (e.type) {
        // ...
        case sf::Event::Resized:
            glViewport(0, 0, e.size.width, e.size.height);

            // Set your projection matrix here
            // Will be different from one library to the other

            break;
        // ...
    }
    // ...
}
\$\endgroup\$

You must log in to answer this question.