source: trunk/packages/vizservers/nanovis/PlaneRenderer.cpp @ 2930

Last change on this file since 2930 was 2930, checked in by ldelgass, 12 years ago

Rename offscreenBufferCapture to bindOffscreenBuffer. Fix more GL state leaks.
Require OpenGL 2.1 as a minimum. Style changes for PlaneRenderer? and rework
plane commands.

  • Property svn:eol-style set to native
File size: 2.6 KB
Line 
1/* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * ----------------------------------------------------------------------
4 * PlaneRenderer.cpp : PlaneRenderer class for volume visualization
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2006  Purdue Research Foundation
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16
17#include "PlaneRenderer.h"
18#include "Trace.h"
19
20PlaneRenderer::PlaneRenderer(int width, int height) :
21    _activePlane(-1),
22    _numPlanes(0),
23    _renderWidth(width),
24    _renderHeight(height),
25    _shader(new NvColorTableShader())
26{
27    _plane.clear();
28    _tf.clear();
29}
30
31PlaneRenderer::~PlaneRenderer()
32{
33    delete _shader;
34}
35
36int
37PlaneRenderer::addPlane(Texture2D *p, TransferFunction *tfPtr)
38{
39    int ret = _numPlanes;
40
41    _plane.push_back(p);
42    _tf.push_back(tfPtr);
43
44    if (ret == 0)
45        _activePlane = ret;
46
47    _numPlanes++;
48    return ret;
49}
50
51void
52PlaneRenderer::removePlane(int index)
53{
54    std::vector<Texture2D *>::iterator piter = _plane.begin()+index;
55    std::vector<TransferFunction *>::iterator tfiter = _tf.begin()+index;
56
57    _plane.erase(piter);
58    _tf.erase(tfiter);
59
60    _numPlanes--;
61}
62
63void
64PlaneRenderer::render()
65{
66    if (_numPlanes == 0)
67        return;
68
69    glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
70
71    glEnable(GL_TEXTURE_2D);
72    glEnable(GL_BLEND);
73
74    glViewport(0, 0, _renderWidth, _renderHeight);
75    glMatrixMode(GL_PROJECTION);
76    glPushMatrix();
77    glLoadIdentity();
78    gluOrtho2D(0, _renderWidth, 0, _renderHeight);
79    glMatrixMode(GL_MODELVIEW);
80    glPushMatrix();
81    glLoadIdentity();
82
83    //glColor3f(1., 1., 1.);         //MUST HAVE THIS LINE!!!
84
85    //if no active plane
86    if (_activePlane == -1)
87        return;
88
89    _shader->bind(_plane[_activePlane], _tf[_activePlane]);
90    glBegin(GL_QUADS);
91    glTexCoord2f(0, 0); glVertex2f(0, 0);
92    glTexCoord2f(1, 0); glVertex2f(_renderWidth, 0);
93    glTexCoord2f(1, 1); glVertex2f(_renderWidth, _renderHeight);
94    glTexCoord2f(0, 1); glVertex2f(0, _renderHeight);
95    glEnd();
96    _shader->unbind();
97
98    glMatrixMode(GL_PROJECTION);
99    glPopMatrix();
100
101    glMatrixMode(GL_MODELVIEW);
102    glPopMatrix();
103
104    glPopAttrib();
105}
106
107void
108PlaneRenderer::setActivePlane(int index)
109{
110    _activePlane = index;
111}
112
113void
114PlaneRenderer::setScreenSize(int w, int h)
115{
116    _renderWidth = w;
117    _renderHeight = h;
118}
Note: See TracBrowser for help on using the repository browser.