From 007038e1e1efa45786e5d66e49ee7e1685308e64 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Sun, 30 May 2004 19:17:58 +0000 Subject: [PATCH] - don't call glNormal unnecessarily - do The Right Thing (TM) with the light position, i.e., set it *before* we multiply by the modelview matrix. It's much easier to achieve predictable lighting results like this: (-1,0,0) simply means "light from the left", (0,1,0) means "light from the top", (0,0,1) means "light from the front", etc. --- Common/Context.h | 2 +- Graphics/Draw.cpp | 38 +++++++++++++++++++++----------------- Graphics/Entity.cpp | 6 +++--- Graphics/Geom.cpp | 8 ++++---- Graphics/Mesh.cpp | 18 ++++++++++++------ Graphics/PostElement.cpp | 8 ++++---- doc/VERSIONS | 5 +++-- 7 files changed, 48 insertions(+), 37 deletions(-) diff --git a/Common/Context.h b/Common/Context.h index c11bbbfbd5..56a9672d07 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -120,7 +120,7 @@ public : int viewport[4]; // current viewport double vxmin, vxmax, vymin, vymax; // current viewport in real coordinates int light[6]; // status of light - double light_position[6][4]; // light sources positions + double light_position[6][3]; // light sources positions double shine; // specular value int render_mode; // GMSH_RENDER, GMSH_SELECT, GMSH_FEEDBACK int clip[6]; // status of clip planes diff --git a/Graphics/Draw.cpp b/Graphics/Draw.cpp index 0eb1b182f4..6081b33bc4 100644 --- a/Graphics/Draw.cpp +++ b/Graphics/Draw.cpp @@ -1,4 +1,4 @@ -// $Id: Draw.cpp,v 1.55 2004-05-30 06:24:02 geuzaine Exp $ +// $Id: Draw.cpp,v 1.56 2004-05-30 19:17:58 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -44,9 +44,8 @@ void Draw3d(void) glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); glDisable(GL_CULL_FACE); - for(int i = 0; i < 6; i++) - if(CTX.clip[i]) - glEnable((GLenum) (GL_CLIP_PLANE0 + i)); + + InitRenderModel(); glPushMatrix(); Draw_Mesh(&M); @@ -55,15 +54,17 @@ void Draw3d(void) void Draw2d(void) { + GLenum clip[6] = { GL_CLIP_PLANE0, GL_CLIP_PLANE1, GL_CLIP_PLANE2, + GL_CLIP_PLANE3, GL_CLIP_PLANE4, GL_CLIP_PLANE5 }; + glDisable(GL_DEPTH_TEST); for(int i = 0; i < 6; i++) - glDisable((GLenum) (GL_CLIP_PLANE0 + i)); + glDisable(clip[i]); glMatrixMode(GL_PROJECTION); glLoadIdentity(); // to draw directly in screen coords - glOrtho((double)CTX.viewport[0], - (double)CTX.viewport[2], + glOrtho((double)CTX.viewport[0], (double)CTX.viewport[2], (double)CTX.viewport[1], (double)CTX.viewport[3], -1., 1.); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); @@ -154,27 +155,30 @@ void Orthogonalize(int x, int y) void InitRenderModel(void) { + GLenum light[6] = {GL_LIGHT0, GL_LIGHT1, GL_LIGHT2, + GL_LIGHT3, GL_LIGHT4, GL_LIGHT5}; + GLfloat pos[4] = {0., 0., 0., 0.}; + GLfloat spec[4] = {CTX.shine, CTX.shine, CTX.shine, 1.0}; + for(int i = 0; i < 6; i++) { if(CTX.light[i]) { - GLfloat tmp[4]; - for(int j = 0; j < 4; j++) - tmp[j] = (GLfloat)CTX.light_position[i][j]; - glLightfv((GLenum) (GL_LIGHT0 + i), GL_POSITION, tmp); - glEnable((GLenum) (GL_LIGHT0 + i)); + for(int j = 0; j < 3; j++) + pos[j] = (GLfloat)CTX.light_position[i][j]; + glEnable(light[i]); + glLightfv(light[i], GL_POSITION, pos); } else{ - glDisable((GLenum) (GL_LIGHT0 + i)); + glDisable(light[i]); } } + glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 40.); glShadeModel(GL_SMOOTH); - float specular[4] = {CTX.shine, CTX.shine, CTX.shine, 1.0}; - glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); glEnable(GL_RESCALE_NORMAL); glEnable(GL_COLOR_MATERIAL); - // disable lighting by default (we enable it for each particular - // case in the drawing routines) + // lighting is enabled/disabled for each particular primitive later glDisable(GL_LIGHTING); } diff --git a/Graphics/Entity.cpp b/Graphics/Entity.cpp index abfb0179fa..85eefce51b 100644 --- a/Graphics/Entity.cpp +++ b/Graphics/Entity.cpp @@ -1,4 +1,4 @@ -// $Id: Entity.cpp,v 1.41 2004-05-29 10:11:12 geuzaine Exp $ +// $Id: Entity.cpp,v 1.42 2004-05-30 19:17:58 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -178,7 +178,7 @@ void Draw_SimpleVector(int arrow, int fill, glEnd(); glBegin(GL_TRIANGLES); - glNormal3dv(u); + if(light) glNormal3dv(u); glVertex3d(x + dx, y + dy, z + dz); glVertex3d(x + f2 * dx + b * (t[0]), y + f2 * dy + b * (t[1]), @@ -190,7 +190,7 @@ void Draw_SimpleVector(int arrow, int fill, z + f2 * dz + b * (-t[2])); glVertex3d(x + f1 * dx, y + f1 * dy, z + f1 * dz); - glNormal3dv(t); + if(light) glNormal3dv(t); glVertex3d(x + dx, y + dy, z + dz); glVertex3d(x + f2 * dx + b * (-u[0]), y + f2 * dy + b * (-u[1]), z + f2 * dz + b * (-u[2])); diff --git a/Graphics/Geom.cpp b/Graphics/Geom.cpp index 18dfc56968..3bad1b9bbe 100644 --- a/Graphics/Geom.cpp +++ b/Graphics/Geom.cpp @@ -1,4 +1,4 @@ -// $Id: Geom.cpp,v 1.63 2004-05-25 04:10:04 geuzaine Exp $ +// $Id: Geom.cpp,v 1.64 2004-05-30 19:17:58 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -279,11 +279,11 @@ void Draw_Triangulated_Surface(Surface * s) p1 = (double*)List_Pointer(s->thePolyRep->points_and_normals, 6*(int)points[1]); p2 = (double*)List_Pointer(s->thePolyRep->points_and_normals, 6*(int)points[2]); p3 = (double*)List_Pointer(s->thePolyRep->points_and_normals, 6*(int)points[3]); - glNormal3dv(&p1[3]); + if(CTX.geom.light) glNormal3dv(&p1[3]); glVertex3d(p1[0],p1[1],p1[2]); - glNormal3dv(&p2[3]); + if(CTX.geom.light) glNormal3dv(&p2[3]); glVertex3d(p2[0],p2[1],p2[2]); - glNormal3dv(&p3[3]); + if(CTX.geom.light) glNormal3dv(&p3[3]); glVertex3d(p3[0],p3[1],p3[2]); } } diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp index 9fffa0a6d6..2d097d11ae 100644 --- a/Graphics/Mesh.cpp +++ b/Graphics/Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Mesh.cpp,v 1.93 2004-05-30 06:24:02 geuzaine Exp $ +// $Id: Mesh.cpp,v 1.94 2004-05-30 19:17:58 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -105,14 +105,20 @@ double intersectCutPlane(int num, Vertex **v) void Draw_Mesh(Mesh * M) { - int i; + GLenum clip[6] = { GL_CLIP_PLANE0, GL_CLIP_PLANE1, GL_CLIP_PLANE2, + GL_CLIP_PLANE3, GL_CLIP_PLANE4, GL_CLIP_PLANE5 }; - InitRenderModel(); InitPosition(); - for(i = 0; i < 6; i++) - if(CTX.clip[i]) - glClipPlane((GLenum) (GL_CLIP_PLANE0 + i), CTX.clip_plane[i]); + for(int i = 0; i < 6; i++){ + if(CTX.clip[i]){ + glClipPlane(clip[i], CTX.clip_plane[i]); + glEnable(clip[i]); + } + else{ + glDisable(clip[i]); + } + } // draw the geometry diff --git a/Graphics/PostElement.cpp b/Graphics/PostElement.cpp index 45ecc34f43..eaa2bdeeaa 100644 --- a/Graphics/PostElement.cpp +++ b/Graphics/PostElement.cpp @@ -1,4 +1,4 @@ -// $Id: PostElement.cpp,v 1.34 2004-05-30 06:24:02 geuzaine Exp $ +// $Id: PostElement.cpp,v 1.35 2004-05-30 19:17:58 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -476,13 +476,13 @@ void Draw_ScalarTriangle(Post_View * View, int preproNormals, glEnable(GL_POLYGON_OFFSET_FILL); glBegin(GL_TRIANGLES); PaletteContinuous(View, ValMin, ValMax, Val[0]); - glNormal3dv(&norms[0]); + if(View->Light) glNormal3dv(&norms[0]); glVertex3d(X[0] + Raise[0][0], Y[0] + Raise[1][0], Z[0] + Raise[2][0]); PaletteContinuous(View, ValMin, ValMax, Val[1]); - glNormal3dv(&norms[3]); + if(View->Light) glNormal3dv(&norms[3]); glVertex3d(X[1] + Raise[0][1], Y[1] + Raise[1][1], Z[1] + Raise[2][1]); PaletteContinuous(View, ValMin, ValMax, Val[2]); - glNormal3dv(&norms[6]); + if(View->Light) glNormal3dv(&norms[6]); glVertex3d(X[2] + Raise[0][2], Y[2] + Raise[1][2], Z[2] + Raise[2][2]); glEnd(); glDisable(GL_POLYGON_OFFSET_FILL); diff --git a/doc/VERSIONS b/doc/VERSIONS index 3f0ff10ca9..3876cccbab 100644 --- a/doc/VERSIONS +++ b/doc/VERSIONS @@ -1,4 +1,4 @@ -$Id: VERSIONS,v 1.215 2004-05-29 20:33:15 geuzaine Exp $ +$Id: VERSIONS,v 1.216 2004-05-30 19:17:58 geuzaine Exp $ New in 1.53: completed support for second order elements (lines, triangles, quadrangles, tetrahedra, hexahedra, prisms and pyramids); @@ -14,7 +14,8 @@ guessing routines so that entities can be selected in an arbitrary order; Mac users can now double click on geo/msh/pos files in the Finder to launch Gmsh; removed support for fltk 1.0; rewrote most of the code related to quadrangles; fixed 2d elliptic algorithm; removed -all OpenGL display list code and options; many code cleanups; +all OpenGL display list code and options; fixed light positioning; +many code cleanups; New in 1.52: new raster ("bitmap") PostScript/EPS/PDF output formats; new Plugin(Extract) to extract a given component from a -- GitLab