From d849d3d30e928f852bf2cfb325dbe8fe59228ab4 Mon Sep 17 00:00:00 2001 From: Christophe Geuzaine <cgeuzaine@ulg.ac.be> Date: Fri, 4 Jun 2004 02:07:07 +0000 Subject: [PATCH] quick hack to implement "fake transparency" as in xpost --- Common/Context.h | 1 + Common/DefaultOptions.h | 2 + Common/Options.cpp | 13 +++++-- Common/Options.h | 1 + Fltk/Callbacks.cpp | 4 +- Fltk/GUI.cpp | 4 +- Graphics/Draw.cpp | 7 +--- Graphics/Post.cpp | 81 +++++++++++++++++++++++++---------------- 8 files changed, 69 insertions(+), 44 deletions(-) diff --git a/Common/Context.h b/Common/Context.h index 63adb0f512..3c816514d5 100644 --- a/Common/Context.h +++ b/Common/Context.h @@ -108,6 +108,7 @@ public : int small_axes_pos[2]; // small axes position int threads, threads_lock; // threads?, lock (should be a mutex...) int alpha; // enable alpha blending + int fake_transparency; // use fake transparency (a la xpost) double zoom_factor; // mouse2 zoom coefficient int fontsize; // font size for fltk UI diff --git a/Common/DefaultOptions.h b/Common/DefaultOptions.h index 496f8b4a25..7678da05e5 100644 --- a/Common/DefaultOptions.h +++ b/Common/DefaultOptions.h @@ -445,6 +445,8 @@ StringXNumber GeneralOptions_Number[] = { { F|O, "DoubleBuffer" , opt_general_double_buffer , 1. , "Use a double buffered graphic window (on Unix, should be set to 0 when working on a remote host without GLX)" }, + { F|O, "FakeTransparency" , opt_general_fake_transparency , 0. , + "Use fake transparency (cheaper than the real thing, but incorrect)" }, { F|O, "FastRedraw" , opt_general_fast_redraw , 1. , "Fast redraw (no mesh or view display) when interacting with the model" }, { F|S, "FontSize" , opt_general_fontsize , 12. , diff --git a/Common/Options.cpp b/Common/Options.cpp index 73b2ffe1da..48fecf3f3a 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -1,4 +1,4 @@ -// $Id: Options.cpp,v 1.163 2004-06-02 00:16:30 geuzaine Exp $ +// $Id: Options.cpp,v 1.164 2004-06-04 02:07:06 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -2327,11 +2327,18 @@ double opt_general_alpha_blending(OPT_ARGS_NUM) { if(action & GMSH_SET) CTX.alpha = (int)val; + return CTX.alpha; +} + +double opt_general_fake_transparency(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.fake_transparency = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) - WID->gen_butt[4]->value(CTX.alpha); + WID->gen_butt[4]->value(CTX.fake_transparency); #endif - return CTX.alpha; + return CTX.fake_transparency; } double opt_general_vector_type(OPT_ARGS_NUM) diff --git a/Common/Options.h b/Common/Options.h index 4650393da4..d26d916b65 100644 --- a/Common/Options.h +++ b/Common/Options.h @@ -247,6 +247,7 @@ double opt_general_small_axes_position1(OPT_ARGS_NUM); double opt_general_quadric_subdivisions(OPT_ARGS_NUM); double opt_general_double_buffer(OPT_ARGS_NUM); double opt_general_alpha_blending(OPT_ARGS_NUM); +double opt_general_fake_transparency(OPT_ARGS_NUM); double opt_general_vector_type(OPT_ARGS_NUM); double opt_general_arrow_head_radius(OPT_ARGS_NUM); double opt_general_arrow_stem_length(OPT_ARGS_NUM); diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index bb1d8d9e47..10f0d7e29f 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.245 2004-06-01 22:16:24 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.246 2004-06-04 02:07:06 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -858,7 +858,7 @@ void general_options_ok_cb(CALLBACK_ARGS) opt_general_fast_redraw(0, GMSH_SET, WID->gen_butt[2]->value()); if(opt_general_double_buffer(0, GMSH_GET, 0) != WID->gen_butt[3]->value()) opt_general_double_buffer(0, GMSH_SET, WID->gen_butt[3]->value()); - opt_general_alpha_blending(0, GMSH_SET, WID->gen_butt[4]->value()); + opt_general_fake_transparency(0, GMSH_SET, WID->gen_butt[4]->value()); opt_general_trackball(0, GMSH_SET, WID->gen_butt[5]->value()); opt_general_terminal(0, GMSH_SET, WID->gen_butt[7]->value()); double sessionrc = opt_general_session_save(0, GMSH_GET, 0); diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index 97a9bb2136..7ffdd303d4 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -1,4 +1,4 @@ -// $Id: GUI.cpp,v 1.313 2004-06-02 00:16:30 geuzaine Exp $ +// $Id: GUI.cpp,v 1.314 2004-06-04 02:07:06 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -1458,7 +1458,7 @@ void GUI::create_option_window() gen_butt[1] = new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW, BH, "Show small axes"); gen_butt[2] = new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW, BH, "Enable fast redraw"); gen_butt[3] = new Fl_Check_Button(2 * WB, 2 * WB + 5 * BH, BW, BH, "Enable double buffering"); - gen_butt[4] = new Fl_Check_Button(2 * WB, 2 * WB + 6 * BH, BW, BH, "Enable alpha blending"); + gen_butt[4] = new Fl_Check_Button(2 * WB, 2 * WB + 6 * BH, BW, BH, "Use fake transparency"); gen_butt[5] = new Fl_Check_Button(2 * WB, 2 * WB + 7 * BH, BW, BH, "Use trackball rotation mode"); for(i = 0; i < 6; i++) { gen_butt[i]->type(FL_TOGGLE_BUTTON); diff --git a/Graphics/Draw.cpp b/Graphics/Draw.cpp index 2d21f808d1..f0706ab940 100644 --- a/Graphics/Draw.cpp +++ b/Graphics/Draw.cpp @@ -1,4 +1,4 @@ -// $Id: Draw.cpp,v 1.58 2004-06-02 15:04:33 geuzaine Exp $ +// $Id: Draw.cpp,v 1.59 2004-06-04 02:07:06 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -36,14 +36,9 @@ extern Mesh M; void Draw3d(void) { - if(CTX.alpha) { - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - glEnable(GL_BLEND); - } glPolygonOffset(1.0, 1.0); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); InitRenderModel(); diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp index 44e9eb3ae2..b19e6a5140 100644 --- a/Graphics/Post.cpp +++ b/Graphics/Post.cpp @@ -1,4 +1,4 @@ -// $Id: Post.cpp,v 1.67 2004-06-01 16:49:01 geuzaine Exp $ +// $Id: Post.cpp,v 1.68 2004-06-04 02:07:07 geuzaine Exp $ // // Copyright (C) 1997-2004 C. Geuzaine, J.-F. Remacle // @@ -407,36 +407,48 @@ void Draw_Post(void) break; } - // if we don't use vertex arrays, do a simple sort of - // transparent views (hybrid views will be sorted incorrectly; - // use Plugin(DecomposeInSimplex) and View->Combine to do remedy - // this limitation) - if(!CTX.post.vertex_arrays && CTX.alpha && ColorTable_IsAlpha(&v->CT) && - v->DrawScalars && (changedEye() || v->Changed)) { - Msg(DEBUG, "Sorting View[%d] for transparency (NO vertex array)", v->Index); - if(v->NbST && v->DrawTriangles) { - nb = List_Nbr(v->ST) / v->NbST; - qsort(v->ST->array, v->NbST, nb * sizeof(double), compareEye3Nodes); + // initialize alpha blending for transparency + if(CTX.alpha && ColorTable_IsAlpha(&v->CT)){ + if(CTX.fake_transparency){ // "a la xpost" + glBlendFunc(GL_SRC_ALPHA, GL_ONE); + glEnable(GL_BLEND); + glDisable(GL_DEPTH_TEST); } - if(v->NbSQ && v->DrawQuadrangles) { - nb = List_Nbr(v->SQ) / v->NbSQ; - qsort(v->SQ->array, v->NbSQ, nb * sizeof(double), compareEye4Nodes); - } - if(v->NbSS && v->DrawTetrahedra) { - nb = List_Nbr(v->SS) / v->NbSS; - qsort(v->SS->array, v->NbSS, nb * sizeof(double), compareEye4Nodes); - } - if(v->NbSH && v->DrawHexahedra) { - nb = List_Nbr(v->SH) / v->NbSH; - qsort(v->SH->array, v->NbSH, nb * sizeof(double), compareEye8Nodes); - } - if(v->NbSI && v->DrawPrisms) { - nb = List_Nbr(v->SI) / v->NbSI; - qsort(v->SI->array, v->NbSI, nb * sizeof(double), compareEye6Nodes); - } - if(v->NbSY && v->DrawPyramids) { - nb = List_Nbr(v->SY) / v->NbSY; - qsort(v->SY->array, v->NbSY, nb * sizeof(double), compareEye5Nodes); + else{ + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + // if we don't use vertex arrays, do a simple sort of + // transparent views (hybrid views will be sorted incorrectly; + // use Plugin(DecomposeInSimplex) and View->Combine to do remedy + // this limitation) + if(!CTX.post.vertex_arrays && v->DrawScalars && + (changedEye() || v->Changed)) { + Msg(DEBUG, "Sorting View[%d] for transparency (NO vertex array)", v->Index); + if(v->NbST && v->DrawTriangles) { + nb = List_Nbr(v->ST) / v->NbST; + qsort(v->ST->array, v->NbST, nb * sizeof(double), compareEye3Nodes); + } + if(v->NbSQ && v->DrawQuadrangles) { + nb = List_Nbr(v->SQ) / v->NbSQ; + qsort(v->SQ->array, v->NbSQ, nb * sizeof(double), compareEye4Nodes); + } + if(v->NbSS && v->DrawTetrahedra) { + nb = List_Nbr(v->SS) / v->NbSS; + qsort(v->SS->array, v->NbSS, nb * sizeof(double), compareEye4Nodes); + } + if(v->NbSH && v->DrawHexahedra) { + nb = List_Nbr(v->SH) / v->NbSH; + qsort(v->SH->array, v->NbSH, nb * sizeof(double), compareEye8Nodes); + } + if(v->NbSI && v->DrawPrisms) { + nb = List_Nbr(v->SI) / v->NbSI; + qsort(v->SI->array, v->NbSI, nb * sizeof(double), compareEye6Nodes); + } + if(v->NbSY && v->DrawPyramids) { + nb = List_Nbr(v->SY) / v->NbSY; + qsort(v->SY->array, v->NbSY, nb * sizeof(double), compareEye5Nodes); + } + } } } @@ -529,7 +541,8 @@ void Draw_Post(void) if(v->TriVertexArray && v->TriVertexArray->num){ - if(CTX.alpha && ColorTable_IsAlpha(&v->CT) && (changedEye() || v->Changed)){ + if(CTX.alpha && ColorTable_IsAlpha(&v->CT) && !CTX.fake_transparency && + (changedEye() || v->Changed)){ Msg(DEBUG, "Sorting View[%d] for transparency (WITH vertex array)", v->Index); v->TriVertexArray->sort(storedEye); } @@ -560,6 +573,12 @@ void Draw_Post(void) glColor4ubv((GLubyte *) & CTX.color.text); Draw_Text2D3D(3, v->TimeStep, v->NbT3, v->T3D, v->T3C); } + + // reset alpha blending + if(CTX.alpha){ + glDisable(GL_BLEND); + glEnable(GL_DEPTH_TEST); + } v->Changed = 0; } -- GitLab