   Shadow mapping: rendering depth to texture
  I've been doing some shadows using shadow volumes, and now I wanna try shadow mapping. I know the theory, but I need help with the depth pass. How do I render the depth of the scene to a (float)-texture? I would like to do as much as possible by myself (i.e. using a shader to set the output to the depth). I know there is some extension for rendering depth-to-texture, but I would like to avoid that as much as possible. I've never done any rendering to texture before.   
  IIRC depth is something like pos.z / pos.w, where "pos" is vertex position in clip space (after ModelViewProjection transform).;  Basically, from fragment shader you can output only to one of the draw buffers (by default color buffer and depth buffer). The best way to do depth render (or any render to texture) would be to use FBO (framebuffer objects) with depth texture attachment, or pixel buffer (older, mostly superseded by FBO), but if you want only core functions without any extensions, you'll have to just render the scene as usual and use glCopyTexImage with GL_DEPTH_COMPONENT (24,32..) format to copy current draw depth buffer to a texture, after that clear the buffers and then do any other passes you want.   ;  Thanks!How do I use glCopyTexImage? I've never rendered to texture before, so I kinda dont know what to do at all.   ;  glCopyTexImage simply copies whatever is in color or depth buffer to current bound texture - pseudocode example:depth_tex = glGenTextures(......loop do  glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT) // clear buffers  render_your_scene();  glBindTexture(GL_TEXTURE_2D,depth_tex);  glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, screen_width, screen_height, 0);   // depth_tex now contains depth buffer of the rendered scene  glClear(GL_COLOR_BUFFER_BIT |GL_DEPTH_BUFFER_BIT); // clear buffers    do_second_pass_and_other_rendering();  ...endNote that screen_width and screen_height are usually not power-of-two, and so for this to work you'll need either hardware which supports non-power-of-two textures, or instead create power-of-two texture (for example 1024x1024 for rendering to 1024x768 window) and then use glCopyTexSubImage instead.