1 /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
8 #define GL_GLEXT_PROTOTYPES
11 static void Display( void )
13 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
18 glVertexAttrib2fNV(0, -1, -1);
19 glVertexAttrib2fNV(0, 1, -1);
20 glVertexAttrib2fNV(0, 0, 1);
29 static void Reshape( int width
, int height
)
31 glViewport( 0, 0, width
, height
);
32 glMatrixMode( GL_PROJECTION
);
34 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
35 glMatrixMode( GL_MODELVIEW
);
37 glTranslatef( 0.0, 0.0, -15.0 );
41 static void Key( unsigned char key
, int x
, int y
)
53 static void load_program(const char *prog
, GLuint prognum
)
56 GLint errorpos
, errno
;
58 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, prognum
);
59 glProgramStringARB(GL_VERTEX_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
60 strlen(prog
), (const GLubyte
*) prog
);
62 assert(glIsProgramARB(prognum
));
64 printf("glGetError = %d\n", errno
);
65 if (errno
!= GL_NO_ERROR
)
67 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB
, &errorpos
);
68 printf("errorpos: %d\n", errorpos
);
69 printf("%s\n", glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
71 for (a
=-10; a
<10; a
++)
73 if ((errorpos
+a
< 0) || (errorpos
+a
>= strlen(prog
))) continue;
74 printf("%c", prog
[errorpos
+a
]);
81 static void Init( void )
85 static const char *prog1
=
88 "MUL result.color.primary.xyz, R0, program.local[35]; \n"
90 static const char *prog2
=
93 "# c[0-3] = modelview projection (composite) matrix\n"
94 "# c[32] = normalized light direction in object-space\n"
95 "# c[35] = yellow diffuse material, (1.0, 1.0, 0.0, 1.0)\n"
97 "# c[64].z = 0.125, a scaling factor\n"
100 "# outputs diffuse illumination for color and perturbed position\n"
102 "DP3 R0, program.local[32], vertex.normal; # light direction DOT normal\n"
103 "MUL result.color.primary.xyz, R0, program.local[35]; \n"
104 "MAX R0, program.local[64].x, R0; \n"
105 "MUL R0, R0, vertex.normal; \n"
106 "MUL R0, R0, program.local[64].z; \n"
107 "ADD R1, vertex.position, -R0; # perturb object space position\n"
108 "DP4 result.position.x, state.matrix.mvp.row[0], R1; \n"
109 "DP4 result.position.y, state.matrix.mvp.row[1], R1; \n"
110 "DP4 result.position.z, state.matrix.mvp.row[2], R1; \n"
111 "DP4 result.position.w, state.matrix.mvp.row[3], R1; \n"
113 static const char *prog3
=
115 "TEMP R0, R1, R2, R3;\n"
116 "DP4 result.position.x, state.matrix.mvp.row[0], vertex.position;\n"
117 "DP4 result.position.y, state.matrix.mvp.row[1], vertex.position;\n"
118 "DP4 result.position.z, state.matrix.mvp.row[2], vertex.position;\n"
119 "DP4 result.position.w, state.matrix.mvp.row[3], vertex.position;\n"
120 "DP3 R0.x, state.matrix.modelview.inverse.row[0], vertex.normal;\n"
121 "DP3 R0.y, state.matrix.modelview.inverse.row[1], vertex.normal;\n"
122 "DP3 R0.z, state.matrix.modelview.inverse.row[2], vertex.normal;\n"
123 "DP3 R1.x, program.env[32], R0; # R1.x = Lpos DOT n'\n"
124 "DP3 R1.y, program.env[33], R0; # R1.y = hHat DOT n'\n"
125 "MOV R1.w, program.local[38].x; # R1.w = specular power\n"
126 "LIT R2, R1; # Compute lighting values\n"
127 "MAD R3, program.env[35].x, R2.y, program.env[35].y; # diffuse + emissive\n"
128 "MAD result.color.primary.xyz, program.env[36], R2.z, R3; # + specular\n"
130 static const char *prog4
=
133 "DP4 R2, R3, program.local[A0.x];\n"
135 "DP4 R2, R3, program.local[A0.x + 5];\n"
136 "DP4 result.position, R3, program.local[A0.x - 4];\n"
141 glGenProgramsNV(4, prognum
);
143 load_program(prog1
, prognum
[0]);
144 load_program(prog2
, prognum
[1]);
145 load_program(prog3
, prognum
[2]);
148 * XXX: Don't have relative offsets working yet
149 load_program(prog4, prognum[3]);
154 int main( int argc
, char *argv
[] )
156 glutInit( &argc
, argv
);
157 glutInitWindowPosition( 0, 0 );
158 glutInitWindowSize( 250, 250 );
159 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
160 glutCreateWindow(argv
[0]);
161 glutReshapeFunc( Reshape
);
162 glutKeyboardFunc( Key
);
163 glutDisplayFunc( Display
);