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