[2798] | 1 | /* -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- */ |
---|
[2836] | 2 | #include <stdlib.h> |
---|
| 3 | |
---|
[2958] | 4 | #include <GL/glew.h> |
---|
| 5 | |
---|
[580] | 6 | #include <R2/R2Fonts.h> |
---|
[2836] | 7 | |
---|
[580] | 8 | #include "NvColorTableRenderer.h" |
---|
| 9 | |
---|
[2836] | 10 | NvColorTableRenderer::NvColorTableRenderer() : |
---|
[2863] | 11 | _fonts(NULL), |
---|
| 12 | _shader(new NvColorTableShader()) |
---|
[580] | 13 | { |
---|
| 14 | } |
---|
| 15 | |
---|
| 16 | NvColorTableRenderer::~NvColorTableRenderer() |
---|
| 17 | { |
---|
| 18 | delete _shader; |
---|
| 19 | } |
---|
| 20 | |
---|
[2836] | 21 | void NvColorTableRenderer::render(int width, int height, |
---|
| 22 | Texture2D *texture, TransferFunction *tf, |
---|
| 23 | double rangeMin, double rangeMax) |
---|
[580] | 24 | { |
---|
[2915] | 25 | glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT); |
---|
| 26 | |
---|
[580] | 27 | glEnable(GL_TEXTURE_2D); |
---|
| 28 | glEnable(GL_BLEND); |
---|
| 29 | |
---|
| 30 | glViewport(0, 0, width, height); |
---|
[854] | 31 | |
---|
[580] | 32 | glMatrixMode(GL_PROJECTION); |
---|
| 33 | glPushMatrix(); |
---|
| 34 | glLoadIdentity(); |
---|
| 35 | gluOrtho2D(0, width, 0, height); |
---|
[854] | 36 | |
---|
[580] | 37 | glMatrixMode(GL_MODELVIEW); |
---|
| 38 | glPushMatrix(); |
---|
| 39 | glLoadIdentity(); |
---|
| 40 | |
---|
[2836] | 41 | //glColor3f(1., 1., 1.); //MUST HAVE THIS LINE!!! |
---|
[580] | 42 | _shader->bind(texture, tf); |
---|
| 43 | |
---|
| 44 | glBegin(GL_QUADS); |
---|
| 45 | glTexCoord2f(0, 0); glVertex2f(30, 30); |
---|
| 46 | glTexCoord2f(1, 0); glVertex2f(width - 30, 30); |
---|
| 47 | glTexCoord2f(1, 1); glVertex2f(width - 30, 60); |
---|
| 48 | glTexCoord2f(0, 1); glVertex2f(30, 60); |
---|
| 49 | glEnd(); |
---|
| 50 | |
---|
| 51 | _shader->unbind(); |
---|
| 52 | |
---|
[2836] | 53 | if (_fonts) { |
---|
[580] | 54 | _fonts->resize(width, height); |
---|
| 55 | _fonts->begin(); |
---|
[854] | 56 | |
---|
[580] | 57 | glPushMatrix(); |
---|
[854] | 58 | glTranslatef(width - 110, 5, 0.0f); |
---|
| 59 | _fonts->draw("Quantum dot lab - www.nanohub.org"); |
---|
[580] | 60 | glPopMatrix(); |
---|
[854] | 61 | |
---|
[580] | 62 | glPushMatrix(); |
---|
[854] | 63 | glTranslatef(30, height - 25, 0.0f); |
---|
| 64 | _fonts->draw("%.08lf", rangeMin); |
---|
[580] | 65 | glPopMatrix(); |
---|
[854] | 66 | |
---|
[580] | 67 | glPushMatrix(); |
---|
[854] | 68 | glTranslatef(width - 110, height - 25, 0.0f); |
---|
| 69 | _fonts->draw("%.08lf", rangeMax); |
---|
| 70 | glPopMatrix(); |
---|
| 71 | |
---|
[580] | 72 | _fonts->end(); |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | glMatrixMode(GL_PROJECTION); |
---|
| 76 | glPopMatrix(); |
---|
| 77 | glMatrixMode(GL_MODELVIEW); |
---|
| 78 | glPopMatrix(); |
---|
[2915] | 79 | |
---|
| 80 | glPopAttrib(); |
---|
[580] | 81 | } |
---|