1 /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
13 static void Display( void )
15 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
20 glVertexAttrib2fNV(0, -1, -1);
21 glVertexAttrib2fNV(0, 1, -1);
22 glVertexAttrib2fNV(0, 0, 1);
31 static void Reshape( int width
, int height
)
33 glViewport( 0, 0, width
, height
);
34 glMatrixMode( GL_PROJECTION
);
36 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
37 glMatrixMode( GL_MODELVIEW
);
39 glTranslatef( 0.0, 0.0, -15.0 );
43 static void Key( unsigned char key
, int x
, int y
)
56 static void Init( void )
58 static const char *prog1
=
60 "MUL o[COL0].xyz, R0, c[35]; \n"
62 static const char *prog2
=
65 "# c[0-3] = modelview projection (composite) matrix\n"
66 "# c[32] = normalized light direction in object-space\n"
67 "# c[35] = yellow diffuse material, (1.0, 1.0, 0.0, 1.0)\n"
69 "# c[64].z = 0.125, a scaling factor\n"
71 "# outputs diffuse illumination for color and perturbed position\n"
73 "DP3 R0, c[32], v[NRML]; # light direction DOT normal\n"
74 "MUL o[COL0].xyz, R0, c[35]; \n"
75 "MAX R0, c[64].x, R0; \n"
76 "MUL R0, R0, v[NRML]; \n"
77 "MUL R0, R0, c[64].z; \n"
78 "ADD R1, v[OPOS], -R0; # perturb object space position\n"
79 "DP4 o[HPOS].x, c[0], R1; \n"
80 "DP4 o[HPOS].y, c[1], R1; \n"
81 "DP4 o[HPOS].z, c[2], R1; \n"
82 "DP4 o[HPOS].w, c[3], R1; \n"
84 static const char *prog3
=
86 "DP4 o[HPOS].x, c[0], v[OPOS];\n"
87 "DP4 o[HPOS].y, c[1], v[OPOS];\n"
88 "DP4 o[HPOS].z, c[2], v[OPOS];\n"
89 "DP4 o[HPOS].w, c[3], v[OPOS];\n"
90 "DP3 R0.x, c[4], v[NRML];\n"
91 "DP3 R0.y, c[5], v[NRML]; \n"
92 "DP3 R0.z, c[6], v[NRML]; # R0 = n' = transformed normal\n"
93 "DP3 R1.x, c[32], R0; # R1.x = Lpos DOT n'\n"
94 "DP3 R1.y, c[33], R0; # R1.y = hHat DOT n'\n"
95 "MOV R1.w, c[38].x; # R1.w = specular power\n"
96 "LIT R2, R1; # Compute lighting values\n"
97 "MAD R3, c[35].x, R2.y, c[35].y; # diffuse + emissive\n"
98 "MAD o[COL0].xyz, c[36], R2.z, R3; # + specular\n"
100 static const char *prog4
=
102 "DP4 R2, R3, c[A0.x];\n"
103 "DP4 R2, R3, c[A0.x + 5];\n"
104 "DP4 o[HPOS], R3, c[A0.x - 4];\n"
106 static const char *prog5
=
108 "DP4 R2, R3, c[A0.x];\n"
109 "DP4 R2, R3, v[0];\n"
110 "DP4 c[3], R3, R2;\n"
116 if (!glutExtensionSupported("GL_NV_vertex_program")) {
117 printf("Sorry, this program requires GL_NV_vertex_program\n");
121 glGenProgramsNV(2, progs
);
124 assert(progs
[0] != progs
[1]);
126 glGenProgramsNV(3, progs
+ 2);
129 assert(progs
[2] != progs
[3]);
130 assert(progs
[0] != progs
[2]);
133 glLoadProgramNV(GL_VERTEX_PROGRAM_NV
, 1,
135 (const GLubyte
*) prog1
);
136 assert(glIsProgramNV(1));
138 glLoadProgramNV(GL_VERTEX_PROGRAM_NV
, 2,
140 (const GLubyte
*) prog2
);
141 assert(glIsProgramNV(2));
143 glLoadProgramNV(GL_VERTEX_PROGRAM_NV
, 3,
145 (const GLubyte
*) prog3
);
146 assert(glIsProgramNV(3));
148 glLoadProgramNV(GL_VERTEX_PROGRAM_NV
, 4,
150 (const GLubyte
*) prog4
);
151 assert(glIsProgramNV(4));
153 glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV
, 5,
155 (const GLubyte
*) prog5
);
156 assert(glIsProgramNV(5));
158 printf("glGetError = %d\n", (int) glGetError());
162 int main( int argc
, char *argv
[] )
164 glutInit( &argc
, argv
);
165 glutInitWindowPosition( 0, 0 );
166 glutInitWindowSize( 250, 250 );
167 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
168 glutCreateWindow(argv
[0]);
170 glutReshapeFunc( Reshape
);
171 glutKeyboardFunc( Key
);
172 glutDisplayFunc( Display
);