projected texture problem

I try to project a texture onto a flat surface (water relection for terrain)
I am using glCopyTexSubImage2D and the generated 512x512 sized texture looks just like it should.

Then I render the scene in 800x600 but when I map the texture onto the water surface then it is not correctly projected along the x axis. The part that is correct is centered on the x axis and is excactly 600 pixels wide (which happens to be the Height of my viewport). On both sides of the view the texture warps in from the other end but I don’t know why? The projection should be 800 wide not 600. On the y axis there is no such problem; I guess that’s because it’s using 800 as height so I never see a texture warping on y axis. For some reason there is width and height inverted, but how did that happen? I double checked all my glViewport calls in case I mistyped width for height or something.

Here is how I do the projection matrix:


// setup projection matrix
// center texture

// setup an isometric camera (the same camera setup is used when rendering the texture)
float fov = 16.0f;
float ratio = watertex->width / watertex->height;
float v = camera->znear * tanf ((fov/2.0f) * PI_OVER_180);
float u = v * ratio;
glFrustum(-u, u, -v, v, camera->znear, camera->zfar);
glRotatef(camera->yaw, 1.0f,0.0f,0.0f);
glTranslatef(camera->pos.x, camera->pos.y, camera->pos.z);
glRotatef(camera->pitch, 0.0f,1.0f,0.0f);
glScalef(1.0f,-1.0f,1.0f); // turn upside down


// render a quad with water texture
glTexCoord3f(0.0f, SEA_LEVEL, 0.0f);  glVertex3f(0.0f, SEA_LEVEL, 0.0f);
glTexCoord3f(64.0f, SEA_LEVEL, 0.0f);  glVertex3f(64.0f, SEA_LEVEL, 0.0f);
glTexCoord3f(64.0f, SEA_LEVEL, 64.0f);  glVertex3f(64.0f, SEA_LEVEL, 64.0f);
glTexCoord3f(0.0f, SEA_LEVEL, 64.0f);  glVertex3f(0.0f, SEA_LEVEL, 64.0f);

// clear projection matrix

here is a screenshot with the texture warping: