source: trunk/packages/vizservers/nanovis/PlaneRenderer.cpp @ 1452

Last change on this file since 1452 was 1111, checked in by gah, 16 years ago

nanovis/heightmap update

File size: 3.2 KB
Line 
1
2/*
3 * ----------------------------------------------------------------------
4 * PlaneRenderer.cpp : PlaneRenderer class for volume visualization
5 *
6 * ======================================================================
7 *  AUTHOR:  Wei Qiao <qiaow@purdue.edu>
8 *           Purdue Rendering and Perceptualization Lab (PURPL)
9 *
10 *  Copyright (c) 2004-2006  Purdue Research Foundation
11 *
12 *  See the file "license.terms" for information on usage and
13 *  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14 * ======================================================================
15 */
16
17#include "global.h"
18#include "PlaneRenderer.h"
19
20PlaneRenderer::PlaneRenderer(CGcontext _context, int _width, int _height):
21    active_plane(-1),
22    n_planes(0),
23    render_width(_width),
24    render_height(_height),
25    g_context(_context)
26{
27    plane.clear();
28    tf.clear();
29    init_shaders();
30}
31
32PlaneRenderer::~PlaneRenderer()
33{
34    /*empty*/
35}
36
37//initialize the render shader
38void
39PlaneRenderer::init_shaders()
40{
41    //plane rendering shader
42    m_fprog = LoadCgSourceProgram(g_context, "one_plane.cg", CG_PROFILE_FP30,
43        NULL);
44    m_data_param = cgGetNamedParameter(m_fprog, "data");
45    m_tf_param = cgGetNamedParameter(m_fprog, "tf");
46    m_render_param = cgGetNamedParameter(m_fprog, "render_param");
47}
48
49
50int
51PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* _tf)
52{
53    int ret = n_planes;
54
55    plane.push_back(_p);
56    tf.push_back(_tf);
57
58    if(ret==0)
59        active_plane = ret;
60
61    n_planes++;
62    return ret;
63}
64
65void
66PlaneRenderer::remove_plane(int index) {
67    vector<Texture2D*>::iterator piter = plane.begin()+index;
68    vector<TransferFunction*>::iterator tfiter = tf.begin()+index;
69
70    plane.erase(piter);
71    tf.erase(tfiter);
72
73    n_planes--;
74}
75
76
77void
78PlaneRenderer::render()
79{
80    if (n_planes == 0)
81        return;
82
83    glEnable(GL_TEXTURE_2D);
84    glEnable(GL_BLEND);
85
86    glViewport(0, 0, render_width, render_height);
87    glMatrixMode(GL_PROJECTION);
88    glLoadIdentity();
89    gluOrtho2D(0, render_width, 0, render_height);
90    glMatrixMode(GL_MODELVIEW);
91    glLoadIdentity();
92
93    //glColor3f(1.,1.,1.);         //MUST HAVE THIS LINE!!!
94
95    //if no active plane
96    if(active_plane == -1)
97        return;
98
99    activate_shader(active_plane);
100    glBegin(GL_QUADS);
101    glTexCoord2f(0, 0); glVertex2f(0, 0);
102    glTexCoord2f(1, 0); glVertex2f(render_width, 0);
103    glTexCoord2f(1, 1); glVertex2f(render_width, render_height);
104    glTexCoord2f(0, 1); glVertex2f(0, render_height);
105    glEnd();
106    deactivate_shader();
107
108}
109
110void
111PlaneRenderer::activate_shader(int index)
112{
113
114    cgGLSetTextureParameter(m_data_param, plane[index]->id);
115    cgGLSetTextureParameter(m_tf_param, tf[index]->id);
116    cgGLEnableTextureParameter(m_data_param);
117    cgGLEnableTextureParameter(m_tf_param);
118
119    cgGLSetParameter4f(m_render_param, 0., 0., 0., 0.);
120
121    cgGLBindProgram(m_fprog);
122    cgGLEnableProfile(CG_PROFILE_FP30);
123}
124
125
126void
127PlaneRenderer::deactivate_shader()
128{
129    cgGLDisableProfile(CG_PROFILE_FP30);
130    cgGLDisableTextureParameter(m_data_param);
131    cgGLDisableTextureParameter(m_tf_param);
132}
133
134void
135PlaneRenderer::set_active_plane(int index)
136{
137    active_plane = index;
138}
139
140void
141PlaneRenderer::set_screen_size(int w, int h)
142{
143    render_width = w;
144    render_height = h;
145}
Note: See TracBrowser for help on using the repository browser.