- //create the reflection texture
- procedure CreateTexture;
- var
- CP: array [0..3] of Double;
- begin
- //set up clipping plane
- cp[0]:=0.0; //x
- cp[1]:=0.0; //y
- cp[2]:=1.0; //z
- cp[3]:=0.0; //w
- //set up the viewport
- glViewport(0, 0, M_SIZE, M_SIZE);
- //clear the buffers
- glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
- //set the camera pos
- glLoadIdentity;
- glLoadmatrixd(@matM);
- //mirror it
- glScalef(1.0, 1.0, -1.0);
- //translate the mirror from its position back to 0
- gltranslatef(-waterpos.x,-waterpos.y,-waterpos.z);
- //enable clipping plane
- glClipPlane(GL_CLIP_PLANE0, @CP);
- glEnable(GL_CLIP_PLANE0);
- //draw the scene...
- DrawObjects;
- //disable the clipping plane
- glDisable(GL_CLIP_PLANE0);
- //copy the color buffer to a texture creating a new texture if necessary
- if (Reflection <> 0) then
- begin
- glBindTexture(GL_TEXTURE_2D, Reflection);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GL_CLAMP);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
- M_SIZE, M_SIZE);
- end else
- begin
- glGenTextures(1, @Reflection);
- glBindTexture(GL_TEXTURE_2D, Reflection);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
- GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
- GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,
- GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,
- GL_CLAMP);
- glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0,
- M_SIZE, M_SIZE, 0);
- end;
- //restore the viewport
- glViewport(0, 0, WND_XSIZE, WND_YSIZE);
- end;