OpenGL rendering to cubemap
<p>I'm trying to render to cubemap. The scene that is being render is a terrain.
I use latitude-longitude debug display to see what's in a certain cubemap.
The two debug view on the bottom left are dummy cubemap that just shows directions and one cubemap with real pictures.</p>

<p>The debug view on the right bottom half show what I get rendered in a cubemap that I'm after.</p>

<p>I've tried many different combinations for setting up the camera, but none of them gave any logical results. I've also compared the code with several samples for implementation of the dynamic cubemap and I was still unable to spot the problem. I'm out of ideas what to even try next, so any help or suggestion is welcome.</p>

<p>Draw to cubemap function:</p>

<pre><code>void Draw(GLuint cubemap, glm::ivec2 res, glm::vec3 position)
{

    glBindFramebuffer(GL_FRAMEBUFFER, fbo);

    glBindRenderbuffer(GL_RENDERBUFFER, rb);
    glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT, res.x, res.y);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rb);

    // camera
    glm::mat4 p = glm::perspective(90.0f, 1.0f, 0.01f, 10.0f);
    glm::mat4 v;

    glm::vec3 targets[6] = {
        glm::vec3(+1.0f, 0.0f, 0.0f),
        glm::vec3(-1.0f, 0.0f, 0.0f),
        glm::vec3(0.0f, +1.0f, 0.0f),
        glm::vec3(0.0f, -1.0f, 0.0f),
        glm::vec3(0.0f, 0.0f, +1.0f),
        glm::vec3(0.0f, 0.0f, -1.0f)
    };
    glm::vec3 ups[6] = {
        glm::vec3(0.0f, 1.0f, 0.0f),
        glm::vec3(0.0f, 1.0f, 0.0f),
        glm::vec3(0.0f, 0.0f, 1.0f),
        glm::vec3(0.0f, 0.0f, -1.0f),
        glm::vec3(0.0f, 1.0f, 0.0f),
        glm::vec3(0.0f, 1.0f, 0.0f)
    };

    // render
    for (int i = 0; i &lt; 6; i++)
    {
        glViewport(0, 0, res.x, res.y);
        // setup target face
        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubemap, 0);
        // setup camera
        v = glm::lookAt(position, position + targets[i], ups[i]);
        // draw
        DrawTerrain(terrain.heightmap, terrain.m, v, p);    // model, view, projection matrices
    }
    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
</code></pre>

<p><img src="https://i.stack.imgur.com/3dVt8.png" alt="screenshot"></p>