1 /* Test vertex state program execution */
8 #define GL_GLEXT_PROTOTYPES
13 static void Display( void )
15 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
23 static void Reshape( int width
, int height
)
25 glViewport( 0, 0, width
, height
);
26 glMatrixMode( GL_PROJECTION
);
28 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
29 glMatrixMode( GL_MODELVIEW
);
31 glTranslatef( 0.0, 0.0, -15.0 );
35 static void Key( unsigned char key
, int x
, int y
)
48 static void Test1( void )
50 static const GLfloat p
[4] = {9, 8, 7, 6};
53 static const char *prog
=
60 glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV
, 1,
62 (const GLubyte
*) prog
);
63 assert(glIsProgramNV(1));
65 glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV
, 0, 1, 2, 3, 4);
66 glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV
, 1, 10, 20, 30, 40);
68 glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV
, 1, p
);
70 glGetProgramParameterfvNV(GL_VERTEX_PROGRAM_NV
, 2, GL_PROGRAM_PARAMETER_NV
, q
);
71 printf("Result c[2] = %g %g %g %g (should be 11 22 33 44)\n",
72 q
[0], q
[1], q
[2], q
[3]);
76 static void Test2( void )
78 static const GLfloat p
[4] = {9, 8, 7, 6};
81 static const char *prog
=
83 "MOV R0, c[0].wzyx;\n"
84 "MOV R1, c[1].wzyx;\n"
88 glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV
, 1,
90 (const GLubyte
*) prog
);
91 assert(glIsProgramNV(1));
93 glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV
, 0, 1, 2, 3, 4);
94 glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV
, 1, 10, 20, 30, 40);
96 glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV
, 1, p
);
98 glGetProgramParameterfvNV(GL_VERTEX_PROGRAM_NV
, 2, GL_PROGRAM_PARAMETER_NV
, q
);
99 printf("Result c[2] = %g %g %g %g (should be 44 33 22 11)\n",
100 q
[0], q
[1], q
[2], q
[3]);
104 static void Test3( void )
106 static const GLfloat p
[4] = {0, 0, 0, 0};
108 /* normalize vector */
109 static const char *prog
=
111 "# c[0] = (nx,ny,nz)\n"
112 "# R0.xyz = normalize(R1)\n"
113 "# R0.w = 1/sqrt(nx*nx + ny*ny + nz*nz)\n"
115 "DP3 R0.w, c[0], c[0];\n"
117 "MUL R0.xyz, c[0], R0.w;\n"
121 glLoadProgramNV(GL_VERTEX_STATE_PROGRAM_NV
, 1,
123 (const GLubyte
*) prog
);
124 assert(glIsProgramNV(1));
126 glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV
, 0, 0, 10, 0, 0);
128 glExecuteProgramNV(GL_VERTEX_STATE_PROGRAM_NV
, 1, p
);
130 glGetProgramParameterfvNV(GL_VERTEX_PROGRAM_NV
, 2, GL_PROGRAM_PARAMETER_NV
, q
);
131 printf("Result c[2] = %g %g %g %g (should be 0, 1, 0, 0.1)\n",
132 q
[0], q
[1], q
[2], q
[3]);
136 int main( int argc
, char *argv
[] )
138 glutInit( &argc
, argv
);
139 glutInitWindowPosition( 0, 0 );
140 glutInitWindowSize( 50, 50 );
141 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
142 glutCreateWindow(argv
[0]);
143 glutReshapeFunc( Reshape
);
144 glutKeyboardFunc( Key
);
145 glutDisplayFunc( Display
);