Spaces:
Sleeping
Sleeping
Ticket Name: TDA2HG: [Opengl] -- the cube usage in fbo | |
Query Text: | |
Part Number: TDA2HG Other Parts Discussed in Thread: TDA2 hi: I have a question about the usage of cubemap in fbo; the simple code as bellow: { glGenFramebuffers(1, &fboID); glBindFramebuffer(GL_FRAMEBUFFER,fboID); glGenTextures(1, &cubemapID); glBindTexture(GL_TEXTURE_CUBE_MAP, cubemapID); for (unsigned int i = 0; i < 6; ++i) { glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0, GL_RGB, 256, 256, 0, GL_RGB, GL_UNSIGNED_BYTE, nullptr); } 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); glUniform.. //update the uniform variable glViewport(0, 0, 256, 256); for (unsigned int i = 0; i < 6; ++i) { glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, cubemapID, 0); if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { printf("glCheckFramebufferStatus error!\n"); } glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); renderCube(); } } when i test the code, it works well on windows, but when i move it to the tda2 platform, the question is comming, sometimes the effiect is black , or is white, or white and black , or other colors, it's change every time. how is this? and how to resolved it? thanks | |
Responses: | |
Hello, Can you try and see if this works: // Setup texture for cubemap | |
glGenTextures(1, &textureCubeMap); | |
char buffer0[CUBEMAP_TEX_LEN * CUBEMAP_TEX_LEN * 6]; | |
glBindTexture(GL_TEXTURE_CUBE_MAP, textureCubeMap); | |
memset((void *)buffer0, 0x50, CUBEMAP_TEX_LEN*CUBEMAP_TEX_LEN*6); | |
for(GLuint i = 0; i < 6; i++) | |
{ | |
glTexImage2D( | |
GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, | |
0, GL_RGBA8, CUBEMAP_TEX_LEN, CUBEMAP_TEX_LEN, | |
0, GL_RGBA, GL_UNSIGNED_BYTE, (char *)buffer0 | |
); | |
} | |
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); | |
// Setup Framebuffer for cubemap | |
glGenFramebuffers(1, &fbCubeMap); | |
// Rendering part | |
GLint current_fbo; | |
glGetIntegerv(GL_FRAMEBUFFER_BINDING, ¤t_fbo); | |
glBindFramebuffer(GL_FRAMEBUFFER, fbCubeMap); | |
// Render to cubemap | |
for (int i = 0; i < 6; i++) | |
{ | |
glFramebufferTexture2D(GL_FRAMEBUFFER, | |
GL_COLOR_ATTACHMENT0, | |
GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, | |
textureCubeMap, | |
0); | |
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); | |
//.... draw/render to cube map surface | |
} | |
// Bind the original frame buffer | |
glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); | |
// Use cubemap texture | |
glBindTexture(GL_TEXTURE_CUBE_MAP, textureCubeMap); | |
//... draw to the final framebuffer using cubemap | |
// In the shader code, use samplerCube to sample texture | |
// e.g: | |
// uniform samplerCube skybox; | |
// ... | |
// vec4 colorval = texture(skybox, direction); | |
If it still doesn't work, can you try and use glGetError to check for any errors? Regards Hemant | |