写好Sphere Map程序了


程序调了半天,最后发现是Reflective vector没有normalized的问题,导致最后结果莫名其妙。下面是在CG中用texture map的步骤:

To set a texture for a cg program you have to query the handle of the texture parameter via its name (CGparameter cgGetNamedParameter(CGprogram prog, const char * name)). Then you can use your texture created with OGL and attach it to the shader with cgGLSetTextureParameter(CGparameter handle_of_the_cg_texture_parameter, GLuint opengl_texture_id). To activate your texture that it is used with the program you have to call cgGLEnableTextureParameter(CGparameter handle_of_the_cg_texture_parameter). You can disable the texture with cgGLDisableTextureParameter(CGparameter handle_of_the_cg_texture_parameter).

If you don’t want to manage cgGLEnableTextureParameter/cgGLDisableTextureParameter calls and want them to be set automatically you can tell this cg with a call to cgGLSetManageTextureParameters(CGcontext ctx, CGbool flag) and flag set to CG_TRUE (it’s disabled by default). CG will the enable all textures attached to a certain program when you bind the program. To reset the texture state you should unbind the program again.

If you want to manage texture states all by yourself (via OpenGL calls) you can query for the texture stage you have to bind your texture to with a call to cgGLGetTextureEnum(CGparameter handle_of_the_cg_texture_parameter). It returns the proper GLenum that can be used to activate the correct texture stage with glActiveTexture.
Instead of querying the texture unit you can use a TEXUNITn semantic when you declare your uniform texture sampler in your cg program but there are some limitations when you want to compile to basic profiles.

                                                       -by someone

一个很不错的CG code网站:http://www.codesampler.com/oglsrc/oglsrc_10.htm。记得上次那个CG 程序就是看这个网站上的code才搞定的。

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s