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

Last change on this file since 2218 was 2096, checked in by ldelgass, 13 years ago

Normalize line endings, set eol-style to native on *.cpp, *.h files

  • Property svn:eol-style set to native
File size: 3.3 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#include "Trace.h"
20
21PlaneRenderer::PlaneRenderer(CGcontext _context, int _width, int _height):
22    active_plane(-1),
23    n_planes(0),
24    render_width(_width),
25    render_height(_height),
26    g_context(_context)
27{
28    plane.clear();
29    tf.clear();
30    init_shaders();
31}
32
33PlaneRenderer::~PlaneRenderer()
34{
35    /*empty*/
36}
37
38//initialize the render shader
39void
40PlaneRenderer::init_shaders()
41{
42    //plane rendering shader
43    m_fprog = LoadCgSourceProgram(g_context, "one_plane.cg", CG_PROFILE_FP30,
44        NULL);
45    m_data_param = cgGetNamedParameter(m_fprog, "data");
46    m_tf_param = cgGetNamedParameter(m_fprog, "tf");
47    m_render_param = cgGetNamedParameter(m_fprog, "render_param");
48}
49
50
51int
52PlaneRenderer::add_plane(Texture2D* _p, TransferFunction* tfPtr)
53{
54    int ret = n_planes;
55
56    plane.push_back(_p);
57    tf.push_back(tfPtr);
58
59    if(ret==0)
60        active_plane = ret;
61
62    n_planes++;
63    return ret;
64}
65
66void
67PlaneRenderer::remove_plane(int index) {
68    vector<Texture2D*>::iterator piter = plane.begin()+index;
69    vector<TransferFunction*>::iterator tfiter = tf.begin()+index;
70
71    plane.erase(piter);
72    tf.erase(tfiter);
73
74    n_planes--;
75}
76
77
78void
79PlaneRenderer::render()
80{
81    if (n_planes == 0)
82        return;
83
84    glEnable(GL_TEXTURE_2D);
85    glEnable(GL_BLEND);
86
87    glViewport(0, 0, render_width, render_height);
88    glMatrixMode(GL_PROJECTION);
89    glLoadIdentity();
90    gluOrtho2D(0, render_width, 0, render_height);
91    glMatrixMode(GL_MODELVIEW);
92    glLoadIdentity();
93
94    //glColor3f(1.,1.,1.);         //MUST HAVE THIS LINE!!!
95
96    //if no active plane
97    if (active_plane == -1)
98        return;
99
100    activate_shader(active_plane);
101    glBegin(GL_QUADS);
102    glTexCoord2f(0, 0); glVertex2f(0, 0);
103    glTexCoord2f(1, 0); glVertex2f(render_width, 0);
104    glTexCoord2f(1, 1); glVertex2f(render_width, render_height);
105    glTexCoord2f(0, 1); glVertex2f(0, render_height);
106    glEnd();
107    deactivate_shader();
108
109}
110
111void
112PlaneRenderer::activate_shader(int index)
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.