实时阴影绘制技术研究

C++博客 首页 新随笔 联系 聚合 管理
  48 Posts :: 20 Stories :: 57 Comments :: 0 Trackbacks

因为要往nsg中填加shader框架,所以从昨天开始着手学习cg,上午跟lzd问了一下传参的问题,发现了glColor设置的颜色其实只对COLOR的语义变量起作用,那DIFFUSE和SPECULAR的就不好使了,所以每次都要set一下parameter.

下边是我看到的cg使用的流程。


cg 使用流程:

  1. #ifdef __APPLE__

static CGprofile VertexProfile = CG_PROFILE_ARBVP1;

#else

static CGprofile VertexProfile = CG_PROFILE_VP20;

#endif

  1. CGContext context = cgCreateContext() ;
  2. CGProgram VertexProgram = cgCreateProgramFromFile(Context,CG_SOURCE, "vertexShader.cg",VertexProfile,NULL, NULL );
  3. if(VertexProgram != NULL)

{

/* Vertex shader only needs to be loaded once */

cgGLLoadProgram(VertexProgram);

/* Bind parameters to give access to variables in the shader */

KdParam = cgGetNamedParameter(VertexProgram, "Kd");

ModelViewProjParam = cgGetNamedParameter(VertexProgram, "ModelViewProj");

VertexColorParam = cgGetNamedParameter(VertexProgram, "IN.VertexColor");

}

  1. // 上边做一次初始化工作即可,下边是每次循环要用到的
  2. cgGLBindProgram(VertexProgram);
  3. if(KdParam != NULL)

cgGLSetParameter4f(KdParam, 1.0, 1.0, 0.0, 1.0);

if(ModelViewProjParam != NULL)

cgGLSetStateMatrixParameter(ModelViewProjParam,CG_GL_MODELVIEW_PROJECTION_MATRIX,CG_GL_MATRIX_IDENTITY);

  1. cgGLEnableProfile(VertexProfile);
  2. glBegin(GL_QUADS);

{

glNormal3fv(&CubeNormals[i][0]);

cgGLSetParameter3f(VertexColorParam, 1.0, 0.0, 0.0);

glVertex3fv(&CubeVertices[CubeFaces[i][0]][0]);

cgGLSetParameter3f(VertexColorParam, 0.0, 1.0, 0.0);

glVertex3fv(&CubeVertices[CubeFaces[i][1]][0]);

cgGLSetParameter3f(VertexColorParam, 0.0, 0.0, 1.0);

glVertex3fv(&CubeVertices[CubeFaces[i][2]][0]);

cgGLSetParameter3f(VertexColorParam, 1.0, 1.0, 1.0);

glVertex3fv(&CubeVertices[CubeFaces[i][3]][0]);

}

glEnd();

  1. cgGLDisableProfile(VertexProfile);

// 后边是收尾工作

  1. cgDestroyProgram(vertexProgram)
  2. cgDestroyContext(context);

 

posted on 2006-04-20 01:43 苦行僧 阅读(2052) 评论(0)  编辑 收藏 引用 所属分类: graphic

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理