0
\$\begingroup\$

I have a function for building a cube map, given a location in space. I also have a system for displaying cubemaps (either loaded from images or given as a texture handle), and they work fine and are used for displaying things such as a skybox as well as are used for reflections.

The issue is, when trying to create a cube map on the fly, I can't get it to be seemless, and it ends up looking like it is zoomed in, thus the right side of the image isn't complete.

This is what my scene looks like at an FOV of 90:

enter image description here

The left pillar isn't fully visible on the front side of the cube map, as well as the right pillar isn't even on that texture at all. The texture appears "zoomed in" so the last part of the image on the right side isn't even visible. This pattern occurs for each side of the cubemap.

If I increase the camera's FOV to 100, the pattern becomes even more clearer:

enter image description here

The way I'm trying to capture a cubemap is like this:

// Create camera, position at 0,0,0, rotate 0,0,0, 90 FOV
DCamera camera(QVector3D(0,0,0), QVector3D(0,0,0), 90.0f, 0x0004, 1.0f );
camera.setPerspective(512,512);

glBindTexture(GL_TEXTURE_CUBE_MAP, cubeTextureTarget);
for (int x = 0; x < 6; x++)
{
    QQuaternion q;
    switch (x) {
    case 0:
        q = QQuaternion::fromAxisAndAngle(0,1,0,90);
        break;
    case 1:
        q = QQuaternion::fromAxisAndAngle(0,1,0,-90);
        break;
    case 2:
        q = QQuaternion::fromAxisAndAngle(1,0,0,90);
        break;
    case 3:
        q = QQuaternion::fromAxisAndAngle(1,0,0,-90);
        break;
    case 4:
        q = QQuaternion::fromAxisAndAngle(0,1,0,0);
        break;
    case 5:
        q = QQuaternion::fromAxisAndAngle(0,1,0,180);
        break;
    }

    QMatrix4x4 mat;
    mat.rotate(q);
    mat.translate(camera.getPosition());
    camera.setModelMatrix(mat);

    /*... RENDERING LOGIC ...*/
}

When I set the camera's perspective projection, I do this:

void DCamera::setPerspective(int w, int h)
{
    projection = QMatrix4x4();
    projection.perspective( (fov), (float)w/(float)h, 1.0f, 1000000.0f );
}

In case it matters, my cubemap texture is formatted like this:

glBindTexture(ftype, cubeTextureTarget);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
for (int x = 0; x < 6; x++)
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+x, 0, GL_RGBA32F, WindowWidth, WindowHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT6, GL_TEXTURE_CUBE_MAP_POSITIVE_X, cubeTextureTarget, 0);

Of course, I increment the texture target within the actual loop for rendering into the cubemap


I'm having trouble finding the proper resources for creating a cubemap. 99% of the hits I'm getting is for rendering a cubemap, not generating one...

\$\endgroup\$
1
\$\begingroup\$

I made a very stupid mistake: I forgot to make the call to glViewport(), as the texture is a different size then the screen. I forgot I had to do that.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.