Cg程序在C/C++环境中的使用

来源:互联网 发布:手机时间不与网络同步 编辑:程序博客网 时间:2024/06/11 02:41

 

哭求评论啊  求评论哭

 

通常cg程序需要依附于opengl与d3d程序使用,在opengl中的典型使用方式如下:

1创建一个cg上下文

context = cgCreateContext();

2 设置profile(每个顶点或片段程序各需要一个)

myCgVertexProfile=cgGLGetLatestProfile(CG_GL_VERTEX);

3 动态的编译cg程序

vertexProgram=cgCreateProgramFromFile(context,CG_SOURCE,"v_shadowmap.cg",myCgVertexProfile,"vShadowmap",NULL);

4 加载编译好的cg程序

cgGLLoadProgram(vertexProgram);

在使用cg程序之前都要先绑定这个cg程序

cgGLBindProgram(vertexProgram)

每次在使用cg程序之前要激活这个profile

cgGLEnableProfile(myCgFragmentProfile);

使用之后要让这个profile失效

cgGLDisableProfile(myCgVertexProfile)