Keith Whitwell | 055d986 | 2008-10-14 13:56:12 +0100 | [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 void Init( void ) |
| 12 | { |
| 13 | GLint errno; |
| 14 | GLuint prognum; |
| 15 | |
| 16 | static const char *prog1 = |
| 17 | "!!ARBvp1.0\n" |
| 18 | "MOV result.texcoord[0], vertex.texcoord[0];\n" |
| 19 | "MOV result.position, vertex.position;\n" |
| 20 | "END\n"; |
| 21 | |
| 22 | |
| 23 | glGenProgramsARB(1, &prognum); |
| 24 | |
| 25 | glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); |
| 26 | glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, |
| 27 | strlen(prog1), (const GLubyte *) prog1); |
| 28 | |
| 29 | assert(glIsProgramARB(prognum)); |
| 30 | errno = glGetError(); |
| 31 | printf("glGetError = %d\n", errno); |
| 32 | if (errno != GL_NO_ERROR) |
| 33 | { |
| 34 | GLint errorpos; |
| 35 | |
| 36 | glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); |
| 37 | printf("errorpos: %d\n", errorpos); |
| 38 | printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); |
| 39 | } |
| 40 | |
| 41 | #define SIZE 32 |
| 42 | { |
| 43 | GLubyte tex2d[SIZE][SIZE][3]; |
| 44 | GLint s, t; |
| 45 | |
| 46 | for (s = 0; s < SIZE; s++) { |
| 47 | for (t = 0; t < SIZE; t++) { |
| 48 | #if 0 |
| 49 | tex2d[t][s][0] = (s < SIZE/2) ? 0 : 255; |
| 50 | tex2d[t][s][1] = (t < SIZE/2) ? 0 : 255; |
| 51 | tex2d[t][s][2] = 0; |
| 52 | #else |
| 53 | tex2d[t][s][0] = s*255/(SIZE-1); |
| 54 | tex2d[t][s][1] = t*255/(SIZE-1); |
| 55 | tex2d[t][s][2] = 0; |
| 56 | #endif |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 61 | |
| 62 | glTexImage2D(GL_TEXTURE_2D, 0, 3, SIZE, SIZE, 0, |
| 63 | GL_RGB, GL_UNSIGNED_BYTE, tex2d); |
| 64 | |
| 65 | glEnable(GL_TEXTURE_2D); |
| 66 | glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); |
| 67 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT); |
| 68 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 69 | glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 70 | |
| 71 | glPixelStorei(GL_UNPACK_ALIGNMENT, 4); |
| 72 | } |
| 73 | |
| 74 | } |
| 75 | |
| 76 | static void Display( void ) |
| 77 | { |
| 78 | glClearColor(0.3, 0.3, 0.3, 1); |
| 79 | glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); |
| 80 | |
| 81 | glEnable(GL_VERTEX_PROGRAM_NV); |
| 82 | |
| 83 | glBegin(GL_TRIANGLES); |
| 84 | glTexCoord2f(1,-1); |
| 85 | glVertex3f( 0.9, -0.9, -0.0); |
| 86 | glTexCoord2f(1,1); |
| 87 | glVertex3f( 0.9, 0.9, -0.0); |
| 88 | glTexCoord2f(-1,0); |
| 89 | glVertex3f(-0.9, 0.0, -0.0); |
| 90 | glEnd(); |
| 91 | |
| 92 | |
| 93 | glFlush(); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | static void Reshape( int width, int height ) |
| 98 | { |
| 99 | glViewport( 0, 0, width, height ); |
| 100 | glMatrixMode( GL_PROJECTION ); |
| 101 | glLoadIdentity(); |
| 102 | glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); |
| 103 | glMatrixMode( GL_MODELVIEW ); |
| 104 | glLoadIdentity(); |
| 105 | /*glTranslatef( 0.0, 0.0, -15.0 );*/ |
| 106 | } |
| 107 | |
| 108 | |
| 109 | static void Key( unsigned char key, int x, int y ) |
| 110 | { |
| 111 | (void) x; |
| 112 | (void) y; |
| 113 | switch (key) { |
| 114 | case 27: |
| 115 | exit(0); |
| 116 | break; |
| 117 | } |
| 118 | glutPostRedisplay(); |
| 119 | } |
| 120 | |
| 121 | |
| 122 | |
| 123 | |
| 124 | int main( int argc, char *argv[] ) |
| 125 | { |
| 126 | glutInit( &argc, argv ); |
| 127 | glutInitWindowPosition( 0, 0 ); |
| 128 | glutInitWindowSize( 250, 250 ); |
| 129 | glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE ); |
| 130 | glutCreateWindow(argv[0]); |
| 131 | glutReshapeFunc( Reshape ); |
| 132 | glutKeyboardFunc( Key ); |
| 133 | glutDisplayFunc( Display ); |
| 134 | Init(); |
| 135 | glutMainLoop(); |
| 136 | return 0; |
| 137 | } |