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