From a0c6318eeaba2d25c8f9e1438c0ff26f8f91531d Mon Sep 17 00:00:00 2001 From: Lee Salzman Date: Thu, 18 Sep 2008 01:43:44 +0000 Subject: [PATCH] backported polygon offset replacement from sauer git-svn-id: svn://svn.code.sf.net/p/actiongame/code/trunk/ac@2673 e016b1c5-ed68-44aa-a2f7-31cac88cffde --- source/src/protos.h | 2 ++ source/src/rendergl.cpp | 45 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 3 deletions(-) diff --git a/source/src/protos.h b/source/src/protos.h index 4aaefdc4..f3f12b7f 100644 --- a/source/src/protos.h +++ b/source/src/protos.h @@ -208,6 +208,8 @@ 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(); +extern void enablepolygonoffset(GLenum type); +extern void disablepolygonoffset(GLenum type, bool restore = true); extern void line(int x1, int y1, float z1, int x2, int y2, float z2); extern void line(int x1, int y1, int x2, int y2, color *c = NULL); extern void box(block &b, float z1, float z2, float z3, float z4); diff --git a/source/src/rendergl.cpp b/source/src/rendergl.cpp index 3ae1ed67..02040862 100644 --- a/source/src/rendergl.cpp +++ b/source/src/rendergl.cpp @@ -114,7 +114,6 @@ void gl_init(int w, int h, int bpp, int depth, int fsaa) glEnable(GL_LINE_SMOOTH); glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); - glPolygonOffset(-3.0, -3.0); glCullFace(GL_FRONT); glEnable(GL_CULL_FACE); @@ -126,6 +125,44 @@ void gl_init(int w, int h, int bpp, int depth, int fsaa) camera1 = player1; } +FVAR(polygonoffsetfactor, -3.0f); +FVAR(polygonoffsetunits, -3.0f); +FVAR(depthoffset, 0.005f); + +void enablepolygonoffset(GLenum type) +{ + if(!depthoffset) + { + glPolygonOffset(polygonoffsetfactor, polygonoffsetunits); + glEnable(type); + return; + } + + GLdouble offsetmatrix[16]; + memcpy(offsetmatrix, projmatrix, 16*sizeof(GLdouble)); + offsetmatrix[14] += depthoffset * projmatrix[10]; + + glMatrixMode(GL_PROJECTION); + glLoadMatrixd(offsetmatrix); + glMatrixMode(GL_MODELVIEW); +} + +void disablepolygonoffset(GLenum type, bool restore) +{ + if(!depthoffset) + { + glDisable(type); + return; + } + + if(restore) + { + glMatrixMode(GL_PROJECTION); + glLoadMatrixd(projmatrix); + glMatrixMode(GL_MODELVIEW); + } +} + void line(int x1, int y1, float z1, int x2, int y2, float z2) { glBegin(GL_POLYGON); @@ -948,11 +985,13 @@ void gl_drawframe(int w, int h, float changelod, float curfps) if(editmode) { if(cursordepth==1.0f) worldpos = camera1->o; - glEnable(GL_POLYGON_OFFSET_LINE); + enablepolygonoffset(GL_POLYGON_OFFSET_LINE); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); + glDepthMask(GL_FALSE); cursorupdate(); + glDepthMask(GL_TRUE); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - glDisable(GL_POLYGON_OFFSET_LINE); + disablepolygonoffset(GL_POLYGON_OFFSET_LINE, false); } extern vector verts;