From 12a3c44a3e0403d4806d8803cc1469e7c822a975 Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 13 Sep 2002 04:03:54 +0000 Subject: [PATCH] GL_SetupView_* functions added, they replace most of R_Mesh_Start's functionality (it still exists and does the remaining things), GL_SetupView_* functions should be used for setting up a view (obviously) for rendering, view orientation and perspective and all that... git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@2376 d7cf8633-e32d-0410-b094-e92efae38249 --- gl_backend.c | 119 ++++++++++++++++++++++++--------------------------- gl_backend.h | 14 +++--- gl_rmain.c | 7 ++- 3 files changed, 70 insertions(+), 70 deletions(-) diff --git a/gl_backend.c b/gl_backend.c index 9af28f19..fc9ae38d 100644 --- a/gl_backend.c +++ b/gl_backend.c @@ -63,8 +63,6 @@ void GL_PrintError(int errornumber, char *filename, int linenumber) #define BACKENDACTIVECHECK if (!backendactive) Sys_Error("GL backend function called when backend is not active\n"); -float r_mesh_farclip; - int c_meshs, c_meshelements; int lightscalebit; @@ -199,77 +197,63 @@ void gl_backend_init(void) R_RegisterModule("GL_Backend", gl_backend_start, gl_backend_shutdown, gl_backend_newmap); } -/* -============= -GL_SetupFrame -============= -*/ -static void GL_SetupFrame (void) +void GL_SetupView_ViewPort (int x, int y, int width, int height) { - double xmax, ymax; - double fovx, fovy, zNear, zFar, aspect; - if (!r_render.integer) return; - qglDepthFunc (GL_LEQUAL);CHECKGLERROR + // y is weird beause OpenGL is bottom to top, we use top to bottom + qglViewport(x, vid.realheight - (y + height), width, height); + CHECKGLERROR +} - // set up viewpoint - qglMatrixMode(GL_PROJECTION);CHECKGLERROR - qglLoadIdentity ();CHECKGLERROR +void GL_SetupView_Orientation_Identity (void) +{ + Matrix4x4_CreateIdentity(&backend_viewmatrix); + memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix)); +} - // y is weird beause OpenGL is bottom to top, we use top to bottom - qglViewport(r_refdef.x, vid.realheight - (r_refdef.y + r_refdef.height), r_refdef.width, r_refdef.height);CHECKGLERROR +void GL_SetupView_Orientation_FromEntity (vec3_t origin, vec3_t angles) +{ + Matrix4x4_CreateRotate(&backend_viewmatrix, -90, 1, 0, 0); + Matrix4x4_ConcatRotate(&backend_viewmatrix, 90, 0, 0, 1); + Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[2], 1, 0, 0); + Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[0], 0, 1, 0); + Matrix4x4_ConcatRotate(&backend_viewmatrix, -angles[1], 0, 0, 1); + Matrix4x4_ConcatTranslate(&backend_viewmatrix, -origin[0], -origin[1], -origin[2]); + memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix)); +} - // depth range - zNear = 1.0; - zFar = r_mesh_farclip; - if (zFar < 64) - zFar = 64; +void GL_SetupView_Mode_Perspective (double aspect, double fovx, double fovy, double zNear, double zFar) +{ + double xmax, ymax; - // fov angles - fovx = r_refdef.fov_x; - fovy = r_refdef.fov_y; - aspect = r_refdef.width / r_refdef.height; + if (!r_render.integer) + return; + // set up viewpoint + qglMatrixMode(GL_PROJECTION);CHECKGLERROR + qglLoadIdentity ();CHECKGLERROR // pyramid slopes - xmax = zNear * tan(fovx * M_PI / 360.0) * aspect; + 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 - qglMatrixMode(GL_MODELVIEW);CHECKGLERROR + GL_SetupView_Orientation_Identity(); +} - Matrix4x4_CreateRotate(&backend_viewmatrix, -90, 1, 0, 0); - Matrix4x4_ConcatRotate(&backend_viewmatrix, 90, 0, 0, 1); - Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[2], 1, 0, 0); - Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[0], 0, 1, 0); - Matrix4x4_ConcatRotate(&backend_viewmatrix, -r_refdef.viewangles[1], 0, 0, 1); - Matrix4x4_ConcatTranslate(&backend_viewmatrix, -r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]); - //Con_Printf("Our Matrix:\n"); - //Matrix4x4_Print(&backend_viewmatrix); - - //Matrix4x4_Transpose(&backend_glmodelviewmatrix, &backend_viewmatrix); - //qglLoadMatrixf(&backend_glmodelviewmatrix.m[0][0]);CHECKGLERROR - memset(&backend_modelmatrix, 0, sizeof(backend_modelmatrix)); +void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar) +{ + if (!r_render.integer) + return; - /* - // put Z going up + // set up viewpoint + qglMatrixMode(GL_PROJECTION);CHECKGLERROR qglLoadIdentity ();CHECKGLERROR - qglRotatef (-90, 1, 0, 0);CHECKGLERROR - qglRotatef (90, 0, 0, 1);CHECKGLERROR - // camera rotation - qglRotatef (-r_refdef.viewangles[2], 1, 0, 0);CHECKGLERROR - qglRotatef (-r_refdef.viewangles[0], 0, 1, 0);CHECKGLERROR - qglRotatef (-r_refdef.viewangles[1], 0, 0, 1);CHECKGLERROR - // camera location - qglTranslatef (-r_refdef.vieworg[0], -r_refdef.vieworg[1], -r_refdef.vieworg[2]);CHECKGLERROR - qglGetFloatv (GL_MODELVIEW_MATRIX, &gl_viewmatrix.m[0][0]); - Matrix4x4_Transpose(&backend_viewmatrix, &gl_viewmatrix); - Con_Printf("GL Matrix:\n"); - Matrix4x4_Print(&backend_viewmatrix); - */ + qglOrtho(x1, y2, x2, y1, zNear, zFar); + qglMatrixMode(GL_MODELVIEW);CHECKGLERROR + GL_SetupView_Orientation_Identity(); } static struct @@ -410,20 +394,16 @@ void GL_Backend_ResetState(void) } // called at beginning of frame -void R_Mesh_Start(float farclip) +void R_Mesh_Start(void) { BACKENDACTIVECHECK CHECKGLERROR - r_mesh_farclip = farclip; - GL_Backend_CheckCvars(); if (mesh_maxverts != gl_mesh_maxverts.integer) GL_Backend_ResizeArrays(gl_mesh_maxverts.integer); - GL_SetupFrame(); - GL_Backend_ResetState(); } @@ -596,13 +576,24 @@ void R_Mesh_Finish(void) qglBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);CHECKGLERROR } -void R_Mesh_ClearDepth(void) +void GL_DepthFunc(int value) +{ + if (!r_render.integer) + return; + + qglDepthFunc (value); + CHECKGLERROR +} + +void GL_ClearDepth(void) { BACKENDACTIVECHECK - R_Mesh_Finish(); + if (!r_render.integer) + return; + qglClear(GL_DEPTH_BUFFER_BIT); - R_Mesh_Start(r_mesh_farclip); + CHECKGLERROR } void R_Mesh_Matrix(const matrix4x4_t *matrix) diff --git a/gl_backend.h b/gl_backend.h index b61093fb..3e1a17c2 100644 --- a/gl_backend.h +++ b/gl_backend.h @@ -9,6 +9,14 @@ extern int polygonelements[768]; void GL_DrawRangeElements(int firstvert, int endvert, int indexcount, int *index); +void GL_SetupView_ViewPort (int x, int y, int width, int height); +void GL_SetupView_Orientation_Identity (void); +void GL_SetupView_Orientation_FromEntity (vec3_t origin, vec3_t angles); +void GL_SetupView_Mode_Perspective (double aspect, double fovx, double fovy, double zNear, double zFar); +void GL_SetupView_Mode_Ortho (double x1, double y1, double x2, double y2, double zNear, double zFar); +void GL_DepthFunc(int value); +void GL_ClearDepth(void); + extern cvar_t gl_lockarrays; extern int c_meshelements, c_meshs; @@ -37,16 +45,12 @@ extern int mesh_maxverts; void gl_backend_init(void); // starts mesh rendering for the frame -void R_Mesh_Start(float farclip); +void R_Mesh_Start(void); // ends mesh rendering for the frame // (only valid after R_Mesh_Start) void R_Mesh_Finish(void); -// clears depth buffer, used for masked sky rendering -// (only valid between R_Mesh_Start and R_Mesh_Finish) -void R_Mesh_ClearDepth(void); - // sets up the requested transform matrix void R_Mesh_Matrix(const matrix4x4_t *matrix); diff --git a/gl_rmain.c b/gl_rmain.c index 024c1172..679096f3 100644 --- a/gl_rmain.c +++ b/gl_rmain.c @@ -661,7 +661,12 @@ void R_RenderView (void) r_farclip = R_FarClip_Finish() + 256.0f; R_TimeReport("markentity"); - R_Mesh_Start(r_farclip); + GL_SetupView_ViewPort(r_refdef.x, r_refdef.y, r_refdef.width, r_refdef.height); + GL_SetupView_Mode_Perspective((double) r_refdef.height / r_refdef.width, r_refdef.fov_x, r_refdef.fov_y, 1.0f, r_farclip); + GL_SetupView_Orientation_FromEntity (r_refdef.vieworg, r_refdef.viewangles); + GL_DepthFunc(GL_LEQUAL); + + R_Mesh_Start(); R_MeshQueue_BeginScene(); if (R_DrawBrushModelsSky()) -- 2.39.2