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