00001 #include <GL/glew.h>
00002 #include <GL/glut.h>
00003 #include <Cg/cgGL.h>
00004
00005 #include "VolumeRender.h"
00006
00007 VolumeRender::VolumeRender(CGcontext cg_context, VolumeBuffer *volume)
00008 : m_cg_context(cg_context),
00009 m_volume(volume),
00010 m_density(0.01),
00011 m_brightness(2.0)
00012 {
00013 loadPrograms();
00014 }
00015
00016 VolumeRender::~VolumeRender()
00017 {
00018 cgDestroyProgram(m_raymarch_vprog);
00019 cgDestroyProgram(m_raymarch_fprog);
00020 }
00021
00022 void
00023 VolumeRender::loadPrograms()
00024 {
00025 m_cg_vprofile = cgGLGetLatestProfile(CG_GL_VERTEX);
00026 m_cg_fprofile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
00027
00028 m_raymarch_vprog = cgCreateProgramFromFile( m_cg_context, CG_SOURCE, "raymarch.cg", m_cg_vprofile , "RayMarchVP", 0);
00029 cgGLLoadProgram(m_raymarch_vprog);
00030
00031 m_raymarch_fprog = cgCreateProgramFromFile( m_cg_context, CG_SOURCE, "raymarch.cg", m_cg_fprofile , "RayMarchFP", 0);
00032 cgGLLoadProgram(m_raymarch_fprog);
00033
00034 m_density_param = cgGetNamedParameter(m_raymarch_fprog, "density");
00035 m_brightness_param = cgGetNamedParameter(m_raymarch_fprog, "brightness");
00036
00037 m_steps_param = cgGetNamedParameter(m_raymarch_fprog, "steps");
00038
00039 transfer_function = cgGetNamedParameter(m_raymarch_fprog, "transfer_function");
00040 }
00041
00042
00043
00044 void
00045 VolumeRender::render()
00046 {
00047 cgGLBindProgram(m_raymarch_vprog);
00048 cgGLEnableProfile(m_cg_vprofile);
00049
00050 cgGLEnableProfile(m_cg_fprofile);
00051
00052 cgGLBindProgram(m_raymarch_fprog);
00053 cgGLSetParameter1f(m_density_param, m_density);
00054 cgGLSetParameter1f(m_brightness_param, m_brightness);
00055
00056 cgGLSetParameter1f(m_steps_param, m_steps);
00057
00058 cgGLSetTextureParameter(transfer_function, m_tfid);
00059 cgGLEnableTextureParameter(transfer_function);
00060
00061 glActiveTextureARB(GL_TEXTURE0_ARB);
00062 glBindTexture(GL_TEXTURE_3D, m_volume->getTexture());
00063
00064 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00065 glutSolidCube(2.0);
00066
00067 cgGLDisableProfile(m_cg_vprofile);
00068 cgGLDisableProfile(m_cg_fprofile);
00069 }