# Weird streching of a texture in OpenGL

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:

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

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

And then I stretched the window once again:

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)

• 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.. – user100681 Nov 1 '17 at 12:01
• 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. – Greffin28 Nov 2 '17 at 10:42

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;
// ...
}
// ...
}