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);


glViewport(0, 0, 640, 480);


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);


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

Yes, that’s fine.

Here’s a sketch 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 (search down to Window Coordinates).