Hi,
i have read many tutorials about envoirement mapping for reflections, in some of them they are creating for every side of the cube one frame buffer in others they use one for the whole cube. Which is the right approach?
I am using java and Android 4.0.
I have follwing code and I am getting the glError 1282 on setting follwing:
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + p_face, m_cubeMap[0], 0 );
The code for cube map generation is:
m_cubeMap = new int[1];
m_cubeFB = new int[1];
m_cubeDB = new int[1];
// create the cube map
glGenTextures ( 1, m_cubeMap, 0 );
glBindTexture ( GL_TEXTURE_CUBE_MAP, m_cubeMap[0] );
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_MIN_FILTER, GL_LINEAR );
glTexParameteri( GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
glGenFramebuffers( 1, m_cubeFB, 0 );
glBindFramebuffer( GL_FRAMEBUFFER, m_cubeFB[0] );
for( int i = 0; i < 6; i++ ) {
glTexImage2D( GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, m_cubeMapSize, m_cubeMapSize, 0, GL_RGB, GL_UNSIGNED_BYTE, null );
}
glGenRenderbuffers ( 1, m_cubeDB, 0 );
glBindRenderbuffer ( GL_RENDERBUFFER, m_cubeDB[0] );
glRenderbufferStorage( GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, m_cubeMapSize, m_cubeMapSize );
glFramebufferRenderbuffer( GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, m_cubeFB[0] );
glFramebufferTexture2D ( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, m_cubeMap[0], 0 );
glBindFramebuffer ( GL_FRAMEBUFFER, 0 );
glBindRenderbuffer( GL_RENDERBUFFER, 0 );
glBindTexture ( GL_TEXTURE_CUBE_MAP, 0 );
if( LoggerConfig.ON )
checkGlError( "InitRefCubeMap()" );
Before I iterate through all faces I set follwing state:
glBindFramebuffer( GL_FRAMEBUFFER, m_cubeFB[0] );
glViewport( 0, 0, m_cubeMapSize, m_cubeMapSize );
For drawing every Face i, and where the Error will happen:
glFramebufferTexture2D( GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + p_face, m_cubeMap[0], 0 );
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
if( LoggerConfig.ON )
checkGlError( "DrawRefCubeMap() Face " + p_face );
It would be great if you can help me. Thanks!