1 | /* |
---|
2 | * ---------------------------------------------------------------------- |
---|
3 | * PlaneRenderer.cpp : PlaneRenderer class for volume visualization |
---|
4 | * |
---|
5 | * ====================================================================== |
---|
6 | * AUTHOR: Wei Qiao <qiaow@purdue.edu> |
---|
7 | * Purdue Rendering and Perceptualization Lab (PURPL) |
---|
8 | * |
---|
9 | * Copyright (c) 2004-2006 Purdue Research Foundation |
---|
10 | * |
---|
11 | * See the file "license.terms" for information on usage and |
---|
12 | * redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
13 | * ====================================================================== |
---|
14 | */ |
---|
15 | |
---|
16 | #include "PlaneRenderer.h" |
---|
17 | |
---|
18 | PlaneRenderer::PlaneRenderer(CGcontext _context, int _width, int _height): |
---|
19 | n_planes(0), |
---|
20 | g_context(_context), |
---|
21 | render_width(_width), |
---|
22 | render_height(_height) |
---|
23 | { |
---|
24 | plane.clear(); |
---|
25 | tf.clear(); |
---|
26 | init_shaders(); |
---|
27 | } |
---|
28 | |
---|
29 | |
---|
30 | PlaneRenderer::~PlaneRenderer(){} |
---|
31 | |
---|
32 | //initialize the render shader |
---|
33 | void PlaneRenderer::init_shaders(){ |
---|
34 | |
---|
35 | //plane rendering shader |
---|
36 | m_fprog = loadProgram(g_context, CG_PROFILE_FP30, CG_SOURCE, "./shaders/one_plane.cg"); |
---|
37 | m_data_param = cgGetNamedParameter(m_fprog, "data"); |
---|
38 | m_tf_param = cgGetNamedParameter(m_fprog, "tf"); |
---|
39 | m_render_param = cgGetNamedParameter(m_fprog, "render_param"); |
---|
40 | } |
---|
41 | |
---|
42 | |
---|
43 | int PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* _tf){ |
---|
44 | |
---|
45 | int ret = n_planes; |
---|
46 | |
---|
47 | plane.push_back(_p); |
---|
48 | tf.push_back(_tf); |
---|
49 | |
---|
50 | if(ret==0) |
---|
51 | active_plane = ret; |
---|
52 | |
---|
53 | n_planes++; |
---|
54 | return ret; |
---|
55 | } |
---|
56 | |
---|
57 | |
---|
58 | void PlaneRenderer::render(){ |
---|
59 | if(n_planes == 0) |
---|
60 | return; |
---|
61 | |
---|
62 | glEnable(GL_TEXTURE_2D); |
---|
63 | glEnable(GL_BLEND); |
---|
64 | |
---|
65 | glViewport(0, 0, render_width, render_height); |
---|
66 | glMatrixMode(GL_PROJECTION); |
---|
67 | glLoadIdentity(); |
---|
68 | gluOrtho2D(0, render_width, 0, render_height); |
---|
69 | glMatrixMode(GL_MODELVIEW); |
---|
70 | glLoadIdentity(); |
---|
71 | |
---|
72 | //glColor3f(1.,1.,1.); //MUST HAVE THIS LINE!!! |
---|
73 | |
---|
74 | activate_shader(active_plane); |
---|
75 | glBegin(GL_QUADS); |
---|
76 | glTexCoord2f(0, 0); glVertex2f(0, 0); |
---|
77 | glTexCoord2f(1, 0); glVertex2f(render_width, 0); |
---|
78 | glTexCoord2f(1, 1); glVertex2f(render_width, render_height); |
---|
79 | glTexCoord2f(0, 1); glVertex2f(0, render_height); |
---|
80 | glEnd(); |
---|
81 | deactivate_shader(); |
---|
82 | |
---|
83 | } |
---|
84 | |
---|
85 | void PlaneRenderer::activate_shader(int index){ |
---|
86 | |
---|
87 | cgGLSetTextureParameter(m_data_param, plane[index]->id); |
---|
88 | cgGLSetTextureParameter(m_tf_param, tf[index]->id); |
---|
89 | cgGLEnableTextureParameter(m_data_param); |
---|
90 | cgGLEnableTextureParameter(m_tf_param); |
---|
91 | |
---|
92 | cgGLSetParameter4f(m_render_param, 0., 0., 0., 0.); |
---|
93 | |
---|
94 | cgGLBindProgram(m_fprog); |
---|
95 | cgGLEnableProfile(CG_PROFILE_FP30); |
---|
96 | } |
---|
97 | |
---|
98 | |
---|
99 | void PlaneRenderer::deactivate_shader(){ |
---|
100 | cgGLDisableProfile(CG_PROFILE_FP30); |
---|
101 | cgGLDisableTextureParameter(m_data_param); |
---|
102 | cgGLDisableTextureParameter(m_tf_param); |
---|
103 | } |
---|
104 | |
---|
105 | void PlaneRenderer::set_active_plane(int index) { active_plane = index; } |
---|
106 | |
---|