GLuint renderToCubeMap(int size, GLenum InternalFormat, GLenum Format, GLenum Type) {
GLuint renderToCubeMap(int size, GLenum InternalFormat, GLenum Format, GLenum Type)
{
// color cube map
GLuint textureObject;
int face;
GLenum status;
//glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE1);
glGenTextures(1, &textureObject);
glBindTexture(GL_TEXTURE_CUBE_MAP, textureObject);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
for (face = 0; face < 6; face++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, 0, InternalFormat, size, size, 0, Format, Type, NULL);
}
// framebuffer object
glGenFramebuffers(1, &fbo);
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_CUBE_MAP_POSITIVE_X, textureObject, 0);
status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
printf("%d\"\n", status);
printf("%d\n", GL_FRAMEBUFFER_COMPLETE);
glViewport(0,0,size, size);
for (face = 1; face < 6; face++) {
drawSpheres();
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,GL_TEXTURE_CUBE_MAP_POSITIVE_X + face, textureObject, 0);
}
//Bind 0, which means render to back buffer, as a result, fb is unbound
glBindFramebuffer(GL_FRAMEBUFFER, 0);
return textureObject;
}