vp-clip.c revision 32001f49
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#include <GL/glew.h> 9#include "glut_wrap.h" 10 11static void Init( void ) 12{ 13 GLint errno; 14 GLuint prognum; 15 16 static const char *prog1 = 17 "!!ARBvp1.0\n" 18 "MOV result.color, vertex.color;\n" 19 "MOV result.position, vertex.position;\n" 20 "END\n"; 21 22 glGenProgramsARB(1, &prognum); 23 24 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum); 25 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, 26 strlen(prog1), (const GLubyte *) prog1); 27 28 assert(glIsProgramARB(prognum)); 29 errno = glGetError(); 30 printf("glGetError = %d\n", errno); 31 if (errno != GL_NO_ERROR) 32 { 33 GLint errorpos; 34 35 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos); 36 printf("errorpos: %d\n", errorpos); 37 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB)); 38 } 39} 40 41static void Display( void ) 42{ 43 glClearColor(0.3, 0.3, 0.3, 1); 44 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); 45 46 glEnable(GL_VERTEX_PROGRAM_NV); 47 48 glBegin(GL_TRIANGLES); 49 glColor3f(0,0,1); 50 glVertex3f( 2.0, -2.0, 0.0); 51 glColor3f(0,1,0); 52 glVertex3f( 2.0, 2.0, 0.0); 53 glColor3f(1,0,0); 54 glVertex3f(-2.0, 0.0, 0.0); 55 glEnd(); 56 57 58 glFlush(); 59} 60 61 62static void Reshape( int width, int height ) 63{ 64 glViewport( 0, 0, width, height ); 65 glMatrixMode( GL_PROJECTION ); 66 glLoadIdentity(); 67 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); 68 glMatrixMode( GL_MODELVIEW ); 69 glLoadIdentity(); 70 /*glTranslatef( 0.0, 0.0, -15.0 );*/ 71} 72 73 74static void Key( unsigned char key, int x, int y ) 75{ 76 (void) x; 77 (void) y; 78 switch (key) { 79 case 27: 80 exit(0); 81 break; 82 } 83 glutPostRedisplay(); 84} 85 86 87 88 89int main( int argc, char *argv[] ) 90{ 91 glutInit( &argc, argv ); 92 glutInitWindowPosition( 0, 0 ); 93 glutInitWindowSize( 250, 250 ); 94 glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH ); 95 glutCreateWindow(argv[0]); 96 glewInit(); 97 glutReshapeFunc( Reshape ); 98 glutKeyboardFunc( Key ); 99 glutDisplayFunc( Display ); 100 Init(); 101 glutMainLoop(); 102 return 0; 103} 104