Karl Rasche | 4814d79 | 2003-11-23 17:44:02 +0000 | [diff] [blame] | 1 | /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */ |
| 2 | |
| 3 | #include <assert.h> |
| 4 | #include <string.h> |
| 5 | #include <stdio.h> |
| 6 | #include <stdlib.h> |
| 7 | #include <math.h> |
| 8 | #define GL_GLEXT_PROTOTYPES |
| 9 | #include <GL/glut.h> |
| 10 | |
| 11 | static float Zrot = 0.0; |
| 12 | |
| 13 | |
| 14 | static void Display( void ) |
| 15 | { |
| 16 | glClearColor(0.3, 0.3, 0.3, 1); |
| 17 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 18 | |
| 19 | glEnable(GL_VERTEX_PROGRAM_NV); |
| 20 | |
| 21 | glLoadIdentity(); |
| 22 | glRotatef(Zrot, 0, 0, 1); |
| 23 | |
| 24 | glPushMatrix(); |
| 25 | |
| 26 | glVertexAttrib3fARB(3, 1, 0.5, 0.25); |
| 27 | glBegin(GL_TRIANGLES); |
| 28 | #if 1 |
| 29 | glVertexAttrib3fARB(3, 1.0, 0.0, 0.0); |
| 30 | glVertexAttrib2fARB(0, -0.5, -0.5); |
| 31 | glVertexAttrib3fARB(3, 0.0, 1.0, 0.0); |
| 32 | glVertexAttrib2fARB(0, 0.5, -0.5); |
| 33 | glVertexAttrib3fARB(3, 0.0, 0.0, 1.0); |
| 34 | glVertexAttrib2fARB(0, 0, 0.5); |
| 35 | #else |
| 36 | glVertex2f( -1, -1); |
| 37 | glVertex2f( 1, -1); |
| 38 | glVertex2f( 0, 1); |
| 39 | #endif |
| 40 | glEnd(); |
| 41 | |
| 42 | glPopMatrix(); |
| 43 | |
| 44 | glutSwapBuffers(); |
| 45 | } |
| 46 | |
| 47 | |
| 48 | static void Reshape( int width, int height ) |
| 49 | { |
| 50 | glViewport( 0, 0, width, height ); |
| 51 | glMatrixMode( GL_PROJECTION ); |
| 52 | glLoadIdentity(); |
| 53 | /* glFrustum( -2.0, 2.0, -2.0, 2.0, 5.0, 25.0 );*/ |
| 54 | glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0 ); |
| 55 | glMatrixMode( GL_MODELVIEW ); |
| 56 | glLoadIdentity(); |
| 57 | /*glTranslatef( 0.0, 0.0, -15.0 );*/ |
| 58 | } |
| 59 | |
| 60 | |
| 61 | static void Key( unsigned char key, int x, int y ) |
| 62 | { |
| 63 | (void) x; |
| 64 | (void) y; |
| 65 | switch (key) { |
| 66 | case 'z': |
| 67 | Zrot -= 5.0; |
| 68 | break; |
| 69 | case 'Z': |
| 70 | Zrot += 5.0; |
| 71 | break; |
| 72 | case 27: |
| 73 | exit(0); |
| 74 | break; |
| 75 | } |
| 76 | glutPostRedisplay(); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | static void Init( void ) |
| 81 | { |
| 82 | GLint errno; |
| 83 | GLuint prognum; |
| 84 | |
| 85 | static const char *prog1 = |
| 86 | "!!ARBvp1.0\n" |
| 87 | "MOV result.color, vertex.color;\n" |
| 88 | |
| 89 | "DP4 result.position.x, vertex.position, state.matrix.modelview.row[0];\n" |
| 90 | "DP4 result.position.y, vertex.position, state.matrix.modelview.row[1];\n" |
| 91 | "DP4 result.position.z, vertex.position, state.matrix.modelview.row[2];\n" |
| 92 | "DP4 result.position.w, vertex.position, state.matrix.modelview.row[3];\n" |
| 93 | "END\n"; |
| 94 | |
| 95 | glGenProgramsARB(1, &prognum); |
| 96 | |
| 97 | glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); |
| 98 | glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, |
| 99 | strlen(prog1), (const GLubyte *) prog1); |
| 100 | |
| 101 | assert(glIsProgramARB(prognum)); |
| 102 | errno = glGetError(); |
| 103 | printf("glGetError = %d\n", errno); |
| 104 | if (errno != GL_NO_ERROR) |
| 105 | { |
| 106 | GLint errorpos; |
| 107 | |
| 108 | glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); |
| 109 | printf("errorpos: %d\n", errorpos); |
Alan Hourihane | 29b2ced | 2004-01-28 16:28:53 +0000 | [diff] [blame] | 110 | printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); |
Karl Rasche | 4814d79 | 2003-11-23 17:44:02 +0000 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
| 114 | |
| 115 | int main( int argc, char *argv[] ) |
| 116 | { |
| 117 | glutInit( &argc, argv ); |
| 118 | glutInitWindowPosition( 0, 0 ); |
| 119 | glutInitWindowSize( 250, 250 ); |
| 120 | glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH ); |
| 121 | glutCreateWindow(argv[0]); |
| 122 | glutReshapeFunc( Reshape ); |
| 123 | glutKeyboardFunc( Key ); |
| 124 | glutDisplayFunc( Display ); |
| 125 | Init(); |
| 126 | glutMainLoop(); |
| 127 | return 0; |
| 128 | } |