2013-01-15 4 views
1

큐브 맵 렌더 대상 클래스를 만들고 있습니다. 이미 2D로 작동합니다. 그러나이 큐브 맵 렌더링 대상 클래스에 대해 원하는대로 특정면을 렌더링 할 수 있기를 원합니다. 어쩌면 "X +"얼굴에는 원을 렌더링하고 싶지만 "Y +"얼굴에는 삼각형을 렌더링하고 싶을 것입니다.OpenGL 큐브 맵 텍스처의 한면으로 렌더링하는 방법

이 이것은

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

이 내 바인드 기능이

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

모습입니다처럼 내 기능이 보이는 만드는 방법입니다

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

처럼 내 클래스는 모습입니다 // 내 바인딩 해제 기능은 다음과 같습니다.

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

나는 지난 주 동안 수많은 연구를 수행했습니다. 나는 내 큐브 맵을 바인딩하는 대신 내 큐브 맵의 한면을 바인딩하는 방법을 찾을 수없는 것 같습니다. 내 전반적인 목표입니다. DirectX에서 6면을 잡고 수동으로 처리 할 수는 있지만 어떻게하면 OpenGL 큐브 맵에서 각면을 수동으로 처리 할 수 ​​있습니까?

+1

"glFramebufferTexture2D": 어떤 얼굴이 현재 대상인지 선택합니다. – JasonD

+0

빠른 예를 입력하는 마음? 내가 전화해야한다는 것을 의미합니까 glBindFrameBuffer 다음 "glFramebufferTexture2D"를 호출 –

답변

4

프레임 버퍼를 바인딩하면 대상 텍스처의 레벨을 지정해야합니다. 다음과 같이되어야합니다 :

glBindFramebuffer(GL_FRAMEBUFFER, m_uifboHandle); 
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_uiTextureHandle, 0); 
+0

나는 그것을 시도합니다. 고맙습니다 –