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