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

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

Remove Nv prefix from shader classes now that they are in nv namespace.

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