资源简介

基于光线投射的体绘制算法,采用opengl和GPU(Cg语言)实现,比较基础的代码,适合对体绘制有兴趣的初学者。 详见国外Peter Triers Blog,可google之。

资源截图

代码片段和文件信息


// --------------------------------------------------------------------------
// GPU raycasting tutorial
// Made by Peter Trier jan 2007
//
// This file contains all the elements nessesary to implement a simple 
// GPU volume raycaster.
// Notice this implementation requires a shader model 3.0 gfxcard
// --------------------------------------------------------------------------

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include “Vector3.h“

#define MAX_KEYS 256
#define WINDOW_SIZE 800
#define VOLUME_TEX_SIZE 128

using namespace std;

// Globals ------------------------------------------------------------------

bool gKeys[MAX_KEYS];
bool toggle_visuals = true;
CGcontext context; 
CGprofile vertexProfile fragmentProfile; 
CGparameter param1param2;
GLuint renderbuffer; 
GLuint framebuffer; 
CGprogram vertex_mainfragment_main; // the raycasting shader programs
GLuint volume_texture; // the volume texture
GLuint backface_buffer; // the FBO buffers
GLuint final_image;
float stepsize = 1.0/50.0;

/// Implementation ----------------------------------------

void cgErrorCallback()
{
CGerror lastError = cgGetError(); 
if(lastError)
{
cout << cgGetErrorString(lastError) << endl;
if(context != NULL)
cout << cgGetLastListing(context) << endl;
exit(0);
}
}

// Sets a uniform texture parameter
void set_tex_param(char* par GLuint texconst CGprogram &programCGparameter param) 
{
param = cgGetNamedParameter(program par); 
cgGLSetTextureParameter(param tex); 
cgGLEnableTextureParameter(param);
}


// load_vertex_program: loading a vertex program
void load_vertex_program(CGprogram &v_programchar *shader_path char *program_name)
{
assert(cgIsContext(context));
v_program = cgCreateProgramFromFile(context CG_SOURCEshader_path
vertexProfileprogram_name NULL);
if (!cgIsProgramCompiled(v_program))
cgCompileProgram(v_program);

cgGLEnableProfile(vertexProfile);
cgGLLoadProgram(v_program);
cgGLDisableProfile(vertexProfile);
}

// load_fragment_program: loading a fragment program
void load_fragment_program(CGprogram &f_programchar *shader_path char *program_name)
{
assert(cgIsContext(context));
f_program = cgCreateProgramFromFile(context CG_SOURCE shader_path
fragmentProfileprogram_name NULL);
if (!cgIsProgramCompiled(f_program))
cgCompileProgram(f_program);

cgGLEnableProfile(fragmentProfile);
cgGLLoadProgram(f_program);
cgGLDisableProfile(fragmentProfile);
}

void enable_renderbuffers()
{
glBindframebufferEXT (GL_frameBUFFER_EXT framebuffer);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT renderbuffer);
}

void disable_renderbuffers()
{
glBindframebufferEXT(GL_frameBUFFER_EXT 0);
}

void vertex(flo

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     文件     1388544  2005-01-07 13:12  raycasting_tutorial\cg.dll
     文件       35830  2005-01-07 13:11  raycasting_tutorial\cg.lib
     文件      180224  2005-01-07 13:12  raycasting_tutorial\cgGL.dll
     文件       19722  2005-01-07 13:11  raycasting_tutorial\cgGL.lib
     文件          77  2007-01-30 07:29  raycasting_tutorial\Desktop.ini
     文件      188416  2005-05-15 23:42  raycasting_tutorial\glew32.dll
     文件      279300  2005-05-15 23:42  raycasting_tutorial\glew32.lib
     文件      690534  2005-05-15 23:42  raycasting_tutorial\glew32s.lib
     文件      237568  2006-06-26 14:14  raycasting_tutorial\glut32.dll
     文件       28728  2006-10-23 14:32  raycasting_tutorial\glut32.lib
     文件       90112  2007-01-30 11:15  raycasting_tutorial\GPU_raycasting.exe
     文件        2039  2006-11-27 21:54  raycasting_tutorial\Jelly ball.rc
     文件       15399  2007-01-30 11:15  raycasting_tutorial\main.cpp
     文件        3638  2006-11-27 21:54  raycasting_tutorial\Quad 5.ico
     文件      838656  2007-01-30 11:16  raycasting_tutorial\raycasting tut.ncb
     文件         901  2006-11-21 21:55  raycasting_tutorial\raycasting tut.sln
     文件       13824  2007-01-30 11:16  raycasting_tutorial\raycasting tut.suo
     文件        2558  2007-01-30 11:14  raycasting_tutorial\raycasting_shader.cg
     文件        2580  2007-01-30 09:35  raycasting_tutorial\raycasting_shader.cg~
     目录           0  2007-01-30 12:59  raycasting_tutorial\Release\
     文件        2365  2007-01-30 11:15  raycasting_tutorial\Release\BuildLog.htm
     文件        3764  2007-01-30 09:41  raycasting_tutorial\Release\Jelly ball.res
     文件       91186  2007-01-30 11:15  raycasting_tutorial\Release\main.obj
     文件      650240  2007-01-30 11:15  raycasting_tutorial\Release\raycasting tut.pdb
     文件      347136  2007-01-30 11:15  raycasting_tutorial\Release\vc70.idb
     文件      167936  2007-01-30 11:15  raycasting_tutorial\Release\vc70.pdb
     文件         453  2006-11-27 21:54  raycasting_tutorial\resource.h
     文件        6144  2007-01-30 07:29  raycasting_tutorial\Thumbs.db
     文件        4580  2004-10-15 11:34  raycasting_tutorial\Vector3.h
     文件        3498  2007-01-30 08:02  raycasting_tutorial\Volley.vcproj

评论

共有 条评论