]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - gl_backend.c
csqc patch from [515], seems to work with [515]'s dpcsqc test mod, needs a lot of...
[xonotic/darkplaces.git] / gl_backend.c
index 677da0e4f938c3a15d33c1847563569f7662d7fd..9e12d566f48fc7716a29ed22d0709813aa6c65fd 100644 (file)
@@ -73,7 +73,7 @@ void GL_PrintError(int errornumber, char *filename, int linenumber)
 }
 #endif
 
-#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active\n");
+#define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active");
 
 void SCR_ScreenShot_f (void);
 
@@ -274,9 +274,8 @@ void GL_SetupView_Orientation_FromEntity(matrix4x4_t *matrix)
        memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix));
 }
 
-void GL_SetupView_Mode_Perspective (double fovx, double fovy, double zNear, double zFar)
+void GL_SetupView_Mode_Perspective (double frustumx, double frustumy, double zNear, double zFar)
 {
-       double xmax, ymax;
        double m[16];
 
        if (!r_render.integer)
@@ -285,11 +284,8 @@ void GL_SetupView_Mode_Perspective (double fovx, double fovy, double zNear, doub
        // set up viewpoint
        qglMatrixMode(GL_PROJECTION);CHECKGLERROR
        qglLoadIdentity();CHECKGLERROR
-       // pyramid slopes
-       xmax = zNear * tan(fovx * M_PI / 360.0);
-       ymax = zNear * tan(fovy * M_PI / 360.0);
        // set view pyramid
-       qglFrustum(-xmax, xmax, -ymax, ymax, zNear, zFar);CHECKGLERROR
+       qglFrustum(-frustumx * zNear, frustumx * zNear, -frustumy * zNear, frustumy * zNear, zNear, zFar);CHECKGLERROR
        qglGetDoublev(GL_PROJECTION_MATRIX, m);
        backend_projectmatrix.m[0][0] = m[0];
        backend_projectmatrix.m[1][0] = m[1];
@@ -311,7 +307,7 @@ void GL_SetupView_Mode_Perspective (double fovx, double fovy, double zNear, doub
        GL_SetupView_Orientation_Identity();
 }
 
-void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double fovx, double fovy, double zNear)
+void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double frustumx, double frustumy, double zNear)
 {
        double nudge, m[16];
 
@@ -323,12 +319,12 @@ void GL_SetupView_Mode_PerspectiveInfiniteFarClip (double fovx, double fovy, dou
        qglLoadIdentity();CHECKGLERROR
        // set view pyramid
        nudge = 1.0 - 1.0 / (1<<23);
-       m[ 0] = 1.0 / tan(fovx * M_PI / 360.0);
+       m[ 0] = 1.0 / frustumx;
        m[ 1] = 0;
        m[ 2] = 0;
        m[ 3] = 0;
        m[ 4] = 0;
-       m[ 5] = 1.0 / tan(fovy * M_PI / 360.0);
+       m[ 5] = 1.0 / frustumy;
        m[ 6] = 0;
        m[ 7] = 0;
        m[ 8] = 0;
@@ -757,7 +753,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver
 {
        GLint vertexshadercompiled, fragmentshadercompiled, programlinked;
        GLuint vertexshaderobject, fragmentshaderobject, programobject = 0;
-       char compilelog[4096];
+       char compilelog[MAX_INPUTLINE];
        CHECKGLERROR
 
        programobject = qglCreateProgramObjectARB();
@@ -781,7 +777,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver
                qglGetObjectParameterivARB(vertexshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &vertexshadercompiled);
                qglGetInfoLogARB(vertexshaderobject, sizeof(compilelog), NULL, compilelog);
                if (compilelog[0])
-                       Con_Printf("vertex shader compile log:\n%s\n", compilelog);
+                       Con_DPrintf("vertex shader compile log:\n%s\n", compilelog);
                if (!vertexshadercompiled)
                {
                        qglDeleteObjectARB(programobject);
@@ -810,7 +806,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver
                qglGetObjectParameterivARB(fragmentshaderobject, GL_OBJECT_COMPILE_STATUS_ARB, &fragmentshadercompiled);
                qglGetInfoLogARB(fragmentshaderobject, sizeof(compilelog), NULL, compilelog);
                if (compilelog[0])
-                       Con_Printf("fragment shader compile log:\n%s\n", compilelog);
+                       Con_DPrintf("fragment shader compile log:\n%s\n", compilelog);
                if (!fragmentshadercompiled)
                {
                        qglDeleteObjectARB(programobject);
@@ -829,7 +825,7 @@ unsigned int GL_Backend_CompileProgram(int vertexstrings_count, const char **ver
        qglGetInfoLogARB(programobject, sizeof(compilelog), NULL, compilelog);
        if (compilelog[0])
        {
-               Con_Printf("program link log:\n%s\n", compilelog);
+               Con_DPrintf("program link log:\n%s\n", compilelog);
                // software vertex shader is ok but software fragment shader is WAY
                // too slow, fail program if so.
                // NOTE: this string might be ATI specific, but that's ok because the
@@ -1737,16 +1733,8 @@ void R_ClearScreen(void)
        }
 }
 
-/*
-====================
-CalcFov
-====================
-*/
-float CalcFov (float fov_x, float width, float height)
-{
-       // calculate vision size and alter by aspect, then convert back to angle
-       return atan (((height/width)/vid_pixelaspect.value)*tan(fov_x/360.0*M_PI))*360.0/M_PI;
-}
+qboolean CL_VM_UpdateView (void);
+void SCR_DrawConsole (void);
 
 int r_stereo_side;
 
@@ -1797,10 +1785,21 @@ void SCR_DrawScreen (void)
                        }
 
                        // LordHavoc: viewzoom (zoom in for sniper rifles, etc)
-                       r_refdef.fov_x = scr_fov.value * r_refdef.fovscale_x;
-                       r_refdef.fov_y = CalcFov (scr_fov.value, r_refdef.width, r_refdef.height) * r_refdef.fovscale_y;
-
-                       R_RenderView();
+                       // LordHavoc: this is designed to produce widescreen fov values
+                       // when the screen is wider than 4/3 width/height aspect, to do
+                       // this it simply assumes the requested fov is the vertical fov
+                       // for a 4x3 display, if the ratio is not 4x3 this makes the fov
+                       // higher/lower according to the ratio
+                       r_refdef.frustum_y = tan(scr_fov.value * cl.viewzoom * M_PI / 360.0) * (3.0/4.0);
+                       r_refdef.frustum_x = r_refdef.frustum_y * (float)r_refdef.width / (float)r_refdef.height / vid_pixelheight.value;
+
+                       r_refdef.frustum_x *= r_refdef.frustumscale_x;
+                       r_refdef.frustum_y *= r_refdef.frustumscale_y;
+
+                       if(!CL_VM_UpdateView())
+                               R_RenderView();
+                       else
+                               SCR_DrawConsole();
 
                        if (scr_zoomwindow.integer)
                        {
@@ -1810,10 +1809,15 @@ void SCR_DrawScreen (void)
                                r_refdef.height = vid.height * sizey;
                                r_refdef.x = (vid.width - r_refdef.width)/2;
                                r_refdef.y = 0;
-                               r_refdef.fov_x = scr_zoomwindow_fov.value * r_refdef.fovscale_x;
-                               r_refdef.fov_y = CalcFov(scr_zoomwindow_fov.value, r_refdef.width, r_refdef.height) * r_refdef.fovscale_y;
 
-                               R_RenderView();
+                               r_refdef.frustum_y = tan(scr_zoomwindow_fov.value * cl.viewzoom * M_PI / 360.0) * (3.0/4.0);
+                               r_refdef.frustum_x = r_refdef.frustum_y * vid_pixelheight.value * (float)r_refdef.width / (float)r_refdef.height;
+
+                               r_refdef.frustum_x *= r_refdef.frustumscale_x;
+                               r_refdef.frustum_y *= r_refdef.frustumscale_y;
+
+                               if(!CL_VM_UpdateView())
+                                       R_RenderView();
                        }
                }