http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/007714.html
http://www.opengl.org/discussion_boards/ubb/Forum3/HTML/007732.html
Here’s some snippets from a program I made:
typedef void (__stdcall *PFNGLGENPROGRAMSARB) ( int n, const unsigned int
*programs );
typedef void (__stdcall *PFNGLBINDPROGRAMARB) ( const int target, unsigned
int program );
typedef void (__stdcall *PFNGLPROGRAMSTRINGARB) ( const int target, const
int format, int len, const void *string );
PFNGLGENPROGRAMSARB glGenProgramsARB = NULL;
PFNGLBINDPROGRAMARB glBindProgramARB = NULL;
PFNGLPROGRAMSTRINGARB glProgramStringARB = NULL;
// membrane effect (as seen in nVidia effects browser)
const unsigned char myprogram = "!!ARBvp1.0
\
variable declarations
TEMP xfNorm, xfPos, r0;
\
transform vertex to clip cooridinates
DP4 result.position.x, state.matrix.mvp.row[0], vertex.position;
DP4 result.position.y, state.matrix.mvp.row[1], vertex.position;
DP4 result.position.z, state.matrix.mvp.row[2], vertex.position;
DP4 result.position.w, state.matrix.mvp.row[3], vertex.position;
\
produce point-to-eye vector
DP4 xfPos.x, state.matrix.modelview.row[0], vertex.position;
DP4 xfPos.y, state.matrix.modelview.row[1], vertex.position;
DP4 xfPos.z, state.matrix.modelview.row[2], vertex.position;
DP4 xfPos.w, state.matrix.modelview.row[3], vertex.position;
\
normalize point-to-eye vector
DP3 r0.x, xfPos, xfPos;
RSQ r0.x, r0.x;
MUL xfPos, xfPos,-r0.x;
\
transform normal to eye coordinates
DP3 xfNorm.x, state.matrix.modelview.invtrans.row[0], vertex.normal;
DP3 xfNorm.y, state.matrix.modelview.invtrans.row[1], vertex.normal;
DP3 xfNorm.z, state.matrix.modelview.invtrans.row[2], vertex.normal;
\
determine color
DP3 r0.x, xfPos, xfNorm;
ADD result.color, vertex.normal.w,-r0.x;
MOV result.texcoord[0].x, r0.x;
END";
// cloaked object effect
const unsigned char myprogram = "!!ARBvp1.0
\
variable declarations
TEMP xfNorm, xfPos, xfLit, Half, r0;
\
transform vertex to clip cooridinates
DP4 result.position.x, state.matrix.mvp.row[0], vertex.position;
DP4 result.position.y, state.matrix.mvp.row[1], vertex.position;
DP4 result.position.z, state.matrix.mvp.row[2], vertex.position;
DP4 result.position.w, state.matrix.mvp.row[3], vertex.position;
\
produce point-to-eye vector
DP4 xfPos.x, state.matrix.modelview.row[0], vertex.position;
DP4 xfPos.y, state.matrix.modelview.row[1], vertex.position;
DP4 xfPos.z, state.matrix.modelview.row[2], vertex.position;
DP4 xfPos.w, state.matrix.modelview.row[3], vertex.position;
\
normalize point-to-eye vector
DP3 r0.x, xfPos, xfPos;
RSQ r0.x, r0.x;
MUL xfPos, xfPos,-r0.x;
\
transform normal to eye coordinates
DP3 xfNorm.x, state.matrix.modelview.invtrans.row[0], vertex.normal;
DP3 xfNorm.y, state.matrix.modelview.invtrans.row[1], vertex.normal;
DP3 xfNorm.z, state.matrix.modelview.invtrans.row[2], vertex.normal;
\
produce light vector
ADD xfLit, state.light[0].position,-xfPos;
\
normalize light vector
DP3 r0.x, xfLit, xfLit;
RSQ r0.x, r0.x;
MUL xfLit, xfLit, r0.x;
\
compute half vector
ADD Half, xfLit, xfPos;
\
normalize half vector
DP3 r0.x, Half, Half;
RSQ r0.x, r0.x;
MUL Half, Half, r0.x;
\
determine color
DP3 r0.y, xfNorm, Half;
MOV r0.w, state.material.shininess;
LIT r0, r0;
DP3 r0.x, xfNorm, xfPos;
MUL r0.z, r0.z, r0.z;
ADD result.color, r0.z,-r0.x;
END";
glGenProgramsARB = (PFNGLGENPROGRAMSARB)wglGetProcAddress(
“glGenProgramsARB” );
glBindProgramARB = (PFNGLBINDPROGRAMARB)wglGetProcAddress(
“glBindProgramARB” );
glProgramStringARB = (PFNGLPROGRAMSTRINGARB)wglGetProcAddress(
“glProgramStringARB” );
if (!glGenProgramsARB | | !glBindProgramARB | | !glProgramStringARB) {
MessageBox( NULL, “Unable to retrieve vertex program procedure
addresses.”, “”, MB_OK );
return false; }
glGenProgramsARB( 1, programs );
glBindProgramARB( GL_VERTEX_PROGRAM_ARB, programs[0] );
glProgramStringARB( GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
strlen( (const char*)myprogram ), myprogram );
if (glGetError() == GL_INVALID_OPERATION) // tripped
MessageBox( NULL, “Invalid Operation”, “”, MB_OK );
// … and last, but not least, our beloved glEnable() call.
glEnable( GL_VERTEX_PROGRAM_ARB );