[vtk-developers] Gradient backgrounds in vtkRenderer.
Francois Bertel
francois.bertel at kitware.com
Mon Apr 7 17:05:21 EDT 2008
You'd better not use query functions like glIsEnable() because it
requires the driver to send information back to the client (which may
involve a flush of OpenGL commands). glPushAttrib/glPopAttrib should
be faster:
glPushAttrib(GL_ENABLE_BIT); // save depth test value and lighting value
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
[...]
glPopAttrib();
glColor() change the current color. You don't need to call it before
each call to glVertex() if it does not change. Just write:
//first Vertex (-1, -1)
glColor3dv(this->Background);
glVertex2f(-1.0, -1.0);
//second vertex
glVertex2f(1.0, -1.0);
//third vertex
glColor3dv(this->Background2);
glVertex2f(1.0, 1.0);
//fourth vertex
glVertex2f(-1.0, 1.0);
On Mon, Apr 7, 2008 at 4:24 PM, Jeff Baumes <jeff.baumes at kitware.com> wrote:
> In certain applications, gradient backgrounds can add to the quality
> of a visualization (in particular in information visualization). Does
> anyone object to the addition of a top-to-bottom gradient in
> vtkRenderer (by default it is disabled, of course)?
>
> This involves adding the following functions to vtkViewport:
>
> vtkSetVector3Macro(Background2,double);
> vtkGetVector3Macro(Background2,double);
>
> vtkSetMacro(GradientBackground,bool);
> vtkGetMacro(GradientBackground,bool);
> vtkBooleanMacro(GradientBackground,bool);
>
> And the following to vtkOpenGLRenderer:
>
> if (!this->Transparent() && this->GradientBackground)
> {
> GLboolean is_depth_en = glIsEnabled(GL_DEPTH_TEST);
> GLboolean is_light_en = glIsEnabled(GL_LIGHTING);
>
> if (is_depth_en)
> {
> glDisable(GL_DEPTH_TEST);
> }
>
> if (is_light_en)
> {
> glDisable(GL_LIGHTING);
> }
>
> glMatrixMode(GL_MODELVIEW);
> glPushMatrix();
> {
> glLoadIdentity ();
> glMatrixMode (GL_PROJECTION);
> glPushMatrix ();
> {
> glLoadIdentity ();
> glBegin(GL_QUADS);
>
> //first Vertex (-1, -1)
> glColor3dv(this->Background);
> glVertex2f(-1.0, -1.0);
>
> //second vertex
> glColor3dv(this->Background);
> glVertex2f(1.0, -1.0);
>
> //third vertex
> glColor3dv(this->Background2);
> glVertex2f(1.0, 1.0);
>
> //fourth vertex
> glColor3dv(this->Background2);
> glVertex2f(-1.0, 1.0);
> glEnd();
> }
> glPopMatrix();
> glMatrixMode(GL_MODELVIEW);
> }
> glPopMatrix();
>
> if (is_depth_en)
> {
> glEnable(GL_DEPTH_TEST);
> }
>
> if (is_light_en)
> {
> glEnable(GL_LIGHTING);
> }
> }
>
> --
> Jeff Baumes, Ph.D.
> R&D Engineer, Kitware Inc.
> (518) 371-3971 x132
> jeff.baumes at kitware.com
> _______________________________________________
> vtk-developers mailing list
> vtk-developers at vtk.org
> http://www.vtk.org/mailman/listinfo/vtk-developers
>
--
François Bertel, PhD | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
| Clifton Park NY 12065, USA
More information about the vtk-developers
mailing list