PDA

View Full Version : Very Basic: about resizing a window



zedrummer
11-09-2014, 10:26 AM
Hello
I am just trying to texture a full openGL window (created with glfwCreateWindow). I have the simplest 2D shaders:

VS

#version 330 core

layout(location = 0) in vec2 vPosition;
layout(location = 1) in vec2 vUV;
out vec2 UV;

void main()
{
gl_Position = vec4(vPosition,0,1);
UV = vUV;
}


FS

#version 330 core

in vec2 UV;

out vec4 color;

uniform sampler2D texte3dsampler;

void main()
{
color=texture2D(texte3dsampler,UV);
}


To which I send via VAO/VBO 2 triangles with vertices coordinates ((-1,-1),(-1,1),(1,1)) and ((-1,-1),(1,1),(1,-1)) and texture coordinates ((0,1),(0,0),(1,0)) and ((0,1),(1,0),(1,1)). I setup everything well, because whatever the initial value I pass for the width/height to "glfwCreateWindow", it draws exactly as expected. But if I resize the window, I was expecting that the texture immediatly adapt to the new size with coordinates from -1 to 1 and it does not. If the window is extended, I have a blue background (the color of the glClear, so the new size is known by openGL) beyond the initial texture which remains of the same size, and if I shrink the window, the extra texture texels are just disappearing.

What do I miss, do I have to setup something at windows resizing when catching "glfwSetWindowSizeCallback" and/or "glfwSetFramebufferSizeCallback"?

Thanks
Cathy L.

carsten neumann
11-09-2014, 11:46 AM
If you are doing nothing at all in glfwSetWindowSizeCallback, you are missing a call to glViewport (https://www.opengl.org/sdk/docs/man/html/glViewport.xhtml) to inform OpenGL how to transform normalized device coordinates to window coordinates - for the initial window size this is taken care of for you, but when the window size changes you need to tell OpenGL about it.

zedrummer
11-09-2014, 12:30 PM
Thanks a lot Carsten, I should have known, but I have switched to OpenGL 3+ not that long ago and I still need to improve.
Cathy L.