   Cube environment mapping problems
  Once again I'm back here to seek the help of the ones with greater knowledge of OpenGL, GLSL and shaders in general.What I try to do:Cube environment mapping How:Render all 6 phases of a cube around the reflective object. Store the data in a  cubemap of 2d  textures and pass it to the shader.Problem symphom: The shit(the reflective object) is all black and it's because the cubemap seems to be all black.Note:I try to render the cubemap before I enter the glut mainloop so that I don't have to render the whole scene multiple times in every loop. The object is in a static position won't change during a run.Comment:The problem is that I'm not sure if I'm doing things in the correct order. It seems to be really hard to find a proper tutorial on this so if you know of any it's would also be a great help. Thanks in advance...Approach-Enable and generate cubemap-Set cubemap parameters-Creating a frame buffer object-Binding a frame buffer object-Set the render target-Bind cubemap texture to active texture unit-----LOOP PHASES-Attach correct cubemap face from cubemap texture to the fbo-----LOOP ENDS-Unbind FBO i.e. use window system frame buffer-GlutMainLoop-When rendering reflective object enable the vertex and fragment shader-Pass cubemap to shaders-EndCode:Relevant GLUT C++ codeint main(int argc, char **argv) {glutInit(&argc, argv);glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH | GLUT_ALPHA);glutInitWindowSize(600, 600);glutCreateWindow("Amaze");// Event functionsglutReshapeFunc(myReshape);glutDisplayFunc(display);glutIdleFunc(myIdleFunc);glutSpecialFunc(keys);glutKeyboardFunc(keyPressed);glutPassiveMotionFunc(mouseLookFunc);glutMotionFunc(mouseLookFunc);glutSetCursor(GLUT_CURSOR_NONE);   glEnable(GL_TEXTURE_2D);glBlendFunc(GL_SRC_ALPHA,GL_ONE);glClearColor(0.0f, 0.0f, 0.0f, 1.0f);glClearDepth(1.0);   glDepthFunc(GL_LESS);glEnable(GL_DEPTH_TEST);glShadeModel(GL_SMOOTH);glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);GLenum err = glewInit();    if (GLEW_OK != err) {   fprintf(stderr, "Error: %s\n", glewGetErrorString(err));    }    fprintf(stdout, "Status: Using GLEW %s\n", glewGetString(GLEW_VERSION));    // ladda shaders    if (GLEW_ARB_vertex_program && GLEW_ARB_fragment_program) {taskcube = load("cubemap.vertex", "cubemap.fragment");    }    else {   exit(1);    }//---------------CUBEMAP------------------// Enable and generate cubemapglEnable(GL_TEXTURE_CUBE_MAP);glGenTextures(1, &cubemap_texture);glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_CUBE_MAP, cubemap_texture);// Set cubemap parametersglTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_REPEAT);glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_REPEAT);glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_REPEAT);glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE, GL_REPLACE);// Creating a frame buffer objectGLuint fbo;glGenFramebuffersEXT(1, &fbo);// binding a frame buffer objectglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);glPushAttrib(GL_VIEWPORT_BIT | GL_COLOR_BUFFER_BIT);glViewport(0,0,600, 600);// Set the render targetglDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);// Render as normal here// output goes to the FBO and it’s attached buffers// bind cubemap texture to active texture unitglBindTexture(GL_TEXTURE_CUBE_MAP, cubemap_texture);// loop over all six sub-images of cube-mapfor (int i=0; i<6; ++i) {//attach correct cubemap face from cubemap texture to the fboglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_CUBE_MAP_POSITIVE_X+i, cubemap_texture,0);//Clears the viewglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);SetCameraView(i); //this works for surerenderAll(); // render the whole world same as glutMainLoop();}glPopAttrib();// unbind FBO i.e. use window system frame bufferglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);glDisable(GL_TEXTURE_CUBE_MAP);glutMainLoop();return 0;}void renderAll(){//LOTS OF STUFF HEREcallShaderCube();drawSphere(-1,-1,0.25); // my reflective objectglUseProgram(0);}void callShaderCube(){glUseProgram(taskcube);GLint loc;loc = glGetUniformLocation(taskcube, "cubeMap");glUniform1i(loc, cubemap_texture);}Fragment shaderuniform samplerCube cubeMap;varying vec3 ReflectionVector;void main (){//vec4 envColor = vec4(textureCube(cubeMap, ReflectionVector));//gl_FragColor = vec4(mix(envColor, gl_FrontColor, 0.5)); gl_FragColor = textureCube(cubeMap,ReflectionVector); //gl_FragColor = float(ReflectionVector);}Vertex Shadervarying vec3 ReflectionVector;void main() {vec3 normalEyeSpace = normalize(gl_NormalMatrix * gl_Normal);    vec3 eyeVec = vec3 (gl_ModelViewMatrix * gl_Vertex);ReflectionVector = reflect(eyeVec,normalEyeSpace);    gl_Position = ftransform();}
  Always difficult to find such problems, probably its something small. Have you tried checking if the FBO processing goes right?Select glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)    Case GL_FRAMEBUFFER_COMPLETE_EXT   Notify("Everything is okay.");    Case GL_FRAMEBUFFER_UNSUPPORTED_EXT   Notify("FBO error: Configuration unsupported",1)   End;    Case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT   Notify("FBO error: Missing Attachment.",1);   End;    Case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT   Notify("FBO error: Incomplete format.",1);   End;    Case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT   Notify("FBO error: Incomplete draw buffer.",1);   End;    Case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT   Notify("FBO error: Incomplete FBO attachment.",1);   End;    Default   Notify("FBO error: "+glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT)+"!",1);   End;EndSelectPut this code in a procedure, and call it after setting up your FBO for a pass.;  Thanks spek, doing as you said helped me to solve the problem. What i needed to do was to add this after i set the cubemap settings with glTexParameteri: //NULL means reserve texture memory, but texels are undefined glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+0, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+1, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+2, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+3, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+4, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X+5, 0, GL_RGBA8, 256, 256, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);Also I needed to fix the rendering by changing some of the code in the loop to:   glDisable(GL_TEXTURE_CUBE_MAP);renderAll();glEnable(GL_TEXTURE_CUBE_MAP);Note: Some other minor changes needed to be made before it was finally working as intended. So if you're reading this and having the same problem I can't guarantee that the code you see here will work as a final result for this task.   