2

I'm making a Cube map render target class. I already have a 2D one that works fine. But for this cube map render target class I want to be able to render to a specific face as i wish. Maybe I want to render circles on the "X+" face but triangles in the "Y+" face.

This is what my class looks like

class CRenderTarget 
{
private:
    //frame buffer to render on
    unsigned  m_uifboHandle;

    //depth stencil 
    unsigned  m_uiDepthStencilHandle;

    //the texture we will render on
    unsigned  m_uiTextureHandle;

public:
    CCubeRenderTarget( void );

    ~CCubeRenderTarget( void );

    void Create( unsigned uiHeightWidth = 512,
             int iInternalFormat = 0x1908 ); //GL_RGBA

    void Bind( void );

    void UnBind( void );
}

This is how my create function looks like

void Create( unsigned uiHeightWidth, int iInternalFormat )
{
        //generate our variables
    glGenFramebuffers(1, &m_uifboHandle);
    glGenRenderbuffers(1, &m_uiDepthStencilHandle);
    glGenTextures(1, &m_uiTextureHandle);

    // Initialize FBO
    glBindFramebuffer( GL_FRAMEBUFFER, m_uifboHandle);

    glBindTexture( GL_TEXTURE_CUBE_MAP, m_uiTextureHandle);

    // Pre-allocate the correct sized cube map
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
    glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, iInternalFormat, uiHeightWidth, uiHeightWidth, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);

    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_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);

    // Must attach texture to framebuffer. Has Stencil and depth
    glBindRenderbuffer(GL_RENDERBUFFER, m_uiDepthStencilHandle);
    glRenderbufferStorage(GL_RENDERBUFFER, /*GL_DEPTH_STENCIL*/GL_DEPTH24_STENCIL8, uiHeightWidth, uiHeightWidth );
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_uiDepthStencilHandle);
    glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_uiDepthStencilHandle);

    glBindFramebuffer(GL_FRAMEBUFFER, 0);
}

this is what my bind function looks like

void Bind( void )
{
    glBindFramebuffer( GL_FRAMEBUFFER, m_uifboHandle );
}

//this is what my unbind function looks like

void Unbind( void )
{
    glBindFramebuffer( GL_FRAMEBUFFER, 0 );
}

I done tons of research for the past week. I can't seem to find a way that i can just some how instead of binding my entire cube map just bind maybe 1 face of my cube map. which is my overall goal. I know that in DirectX you can by just grabbing the 6 faces and manually handling them but how can i manually handle each face on an openGL cube map?

Franky Rivera
  • 553
  • 8
  • 20

1 Answers1

5

Having bound the framebuffer, you need to specify what level of the texture should be targetted. It should be something like this:

glBindFramebuffer( GL_FRAMEBUFFER, m_uifboHandle );
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_uiTextureHandle, 0);
JasonD
  • 16,464
  • 2
  • 29
  • 44