diff --git a/docs/reference.xml b/docs/reference.xml
index ab1bf8c7..785dc428 100644
--- a/docs/reference.xml
+++ b/docs/reference.xml
@@ -1986,7 +1986,7 @@
-
+
diff --git a/source/src/protos.h b/source/src/protos.h
index 6fb840dd..b25f2955 100644
--- a/source/src/protos.h
+++ b/source/src/protos.h
@@ -185,6 +185,8 @@ extern serverinfo *getconnectedserverinfo();
extern void pingservers();
// rendergl
+extern GLdouble mvmatrix[16], projmatrix[16], mvpmatrix[16], invmvmatrix[16];
+
extern void gl_checkextensions();
extern void gl_init(int w, int h, int bpp, int depth, int fsaa);
extern void cleangl();
diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp
index ed537c0b..a36838c9 100644
--- a/source/src/rendergl.cpp
+++ b/source/src/rendergl.cpp
@@ -406,14 +406,14 @@ void transplayer()
glTranslatef(-camera1->o.x, -camera1->o.y, -camera1->o.z);
}
-void genclipmatrix(float a, float b, float c, float d, GLfloat matrix[16])
+void genclipmatrix(double a, double b, double c, double d, GLdouble matrix[16])
{
// transform the clip plane into camera space
- GLdouble clip[4] = {a, b, c, d};
- glClipPlane(GL_CLIP_PLANE0, clip);
- glGetClipPlane(GL_CLIP_PLANE0, clip);
+ double clip[4];
+ loopi(4) clip[i] = a*invmvmatrix[i*4 + 0] + b*invmvmatrix[i*4 + 1] + c*invmvmatrix[i*4 + 2] + d*invmvmatrix[i*4 + 3];
+
+ memcpy(matrix, projmatrix, 16*sizeof(GLdouble));
- glGetFloatv(GL_PROJECTION_MATRIX, matrix);
float x = ((clip[0]<0 ? -1 : (clip[0]>0 ? 1 : 0)) + matrix[8]) / matrix[0],
y = ((clip[1]<0 ? -1 : (clip[1]>0 ? 1 : 0)) + matrix[9]) / matrix[5],
w = (1 + matrix[10]) / matrix[14],
@@ -428,7 +428,7 @@ bool reflecting = false, refracting = false;
GLuint reflecttex = 0, refracttex = 0;
int reflectlastsize = 0;
-VARP(reflectres, 6, 8, 10);
+VARP(reflectsize, 6, 8, 10);
VAR(reflectclip, 0, 3, 100);
VARP(waterreflect, 0, 1, 1);
VARP(waterrefract, 0, 0, 1);
@@ -439,7 +439,7 @@ void drawreflection(float hf, int w, int h, float changelod, bool refract)
reflecting = true;
refracting = refract;
- int size = 1< sizelimit) size /= 2;
if(size!=reflectlastsize)
{
@@ -495,11 +495,11 @@ void drawreflection(float hf, int w, int h, float changelod, bool refract)
glScalef(1, 1, -1);
}
- GLfloat clipmat[16];
- genclipmatrix(0, 0, refract ? -1 : 1, refract ? 0.1f*reflectclip+hf : 0.1f*reflectclip-hf, clipmat);
+ GLdouble clipmat[16];
+ genclipmatrix(0, 0, -1, 0.1f*reflectclip+hf, clipmat);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
- glLoadMatrixf(clipmat);
+ glLoadMatrixd(clipmat);
glMatrixMode(GL_MODELVIEW);
renderstripssky();
@@ -795,6 +795,9 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
gluPerspective(fovy, aspect, 0.15f, farplane);
glMatrixMode(GL_MODELVIEW);
+ transplayer();
+ readmatrices();
+
if(!underwater && waterreflect)
{
extern int wx1;
@@ -808,8 +811,6 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
glClear((outsidemap(camera1) ? GL_COLOR_BUFFER_BIT : 0) | GL_DEPTH_BUFFER_BIT);
- transplayer();
-
glEnable(GL_TEXTURE_2D);
resetcubes();
@@ -844,7 +845,6 @@ void gl_drawframe(int w, int h, float changelod, float curfps)
renderentities();
endmodelbatches();
- readmatrices();
readdepth(w, h, worldpos);
startmodelbatches();
diff --git a/source/src/vertmodel.h b/source/src/vertmodel.h
index 4aaafcb3..07dc06db 100644
--- a/source/src/vertmodel.h
+++ b/source/src/vertmodel.h
@@ -442,7 +442,6 @@ struct vertmodel : model
glGetDoublev(GL_MODELVIEW_MATRIX, mm);
vec eyepos;
loopk(3) eyepos[k] = tagpos.x*mm[0+k] + tagpos.y*mm[4+k] + tagpos.z*mm[8+k] + mm[12+k];
- extern GLdouble invmvmatrix[16];
vec worldpos;
loopk(3) worldpos[k] = eyepos.x*invmvmatrix[0+k] + eyepos.y*invmvmatrix[4+k] + eyepos.z*invmvmatrix[8+k] + invmvmatrix[12+k];
particle_emit(emitters[i].type, emitters[i].args, basetime, emitters[i].seed, worldpos);
diff --git a/source/src/water.cpp b/source/src/water.cpp
index c8ad8fbb..d0cfaff2 100644
--- a/source/src/water.cpp
+++ b/source/src/water.cpp
@@ -75,16 +75,13 @@ extern int nquads;
void setprojtexmatrix()
{
- GLfloat pm[16], mm[16];
- glGetFloatv(GL_PROJECTION_MATRIX, pm);
- glGetFloatv(GL_MODELVIEW_MATRIX, mm);
+ GLdouble matrix[16];
+
+ memcpy(matrix, mvpmatrix, 16*sizeof(GLdouble));
+ loopi(2) loopj(4) matrix[i + j*4] = 0.5f*(matrix[i + j*4] + matrix[3 + j*4]);
glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glTranslatef(0.5f, 0.5f, 0.5f);
- glScalef(0.5f, 0.5f, 0.5f);
- glMultMatrixf(pm);
- glMultMatrixf(mm);
+ glLoadMatrixd(matrix);
}
void setupmultitexrefract(GLuint reflecttex, GLuint refracttex)
@@ -237,7 +234,6 @@ void addwaterquad(int x, int y, int size) // update bounding rect that con
void calcwaterscissor()
{
- extern GLdouble mvpmatrix[16];
vec4 v[4];
float sx1 = 1, sy1 = 1, sx2 = -1, sy2 = -1;
loopi(4)