PDA

View Full Version : Viewport



Domididongo
12-02-2016, 05:53 AM
I don't know if I really understand what viewport is doing. I want to render in a texture of size 256 x 256 this render step is done in a framebuffer. For debugging I want to render the texture in a bigger screen 640 x 480. Is it korrekt like that:


glViewport(0, 0, 256, 256);

renderToFrameBuffer();

glViewport(0, 0, 640, 480);

renderToScreen();

I mean the result looks fine. But I am not sure if I understand something wrong, and it is doing something else, what I don't won't.

And further. When I want to build a 512 x 512 texture, and render 4 time 256 x 256 pixels in this texture, can I handle this like that:



for(int x = 0; x < 2; ++x)
{
for(int y = 0; y < 2; ++y)
{
glViewport(0+x*256, 0+y*256, 256+x*256, 256 +y*256);
render();
}

}


is the result than correctly a 512 x 512 texture with informations of 4 rendering steps of a 256 x 256 texture?

Dark Photon
12-02-2016, 06:11 AM
I don't know if I really understand what viewport is doing. I want to render in a texture of size 512 x 512 this render step is done in a framebuffer. For debugging I want to render the texture in a bigger screen 640 x 480. Is it korrekt like that:

Yes, that's fine.

Here's a sketch (https://www.opengl.org/wiki/General_OpenGL:_Transformations#How_are_coordinate s_transformed.3F_What_are_the_different_coordinate _spaces.3F) of how OpenGL transforms coordinates. See the end where glViewport is mentioned. Basically, when the pipeline gets to Normalized Device Coordinates (NDC), your geometry is in a 3D box with extent -1 <= X,Y,Z <= +1. glViewport tells it what range to map X and Y into.

For a more detailed discussion of OpenGL coordinate space transforms, see this link (http://www.songho.ca/opengl/gl_transform.html) (search down to Window Coordinates).