Merge commit 'origin/gallium-master-merge'
[mesa.git] / progs / trivial / vp-tri-swap.c
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 <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.position, vertex.color;\n"
19 "MOV result.color, 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
42 static void Display( void )
43 {
44 glClearColor(0.3, 0.3, 0.3, 1);
45 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
46
47 glEnable(GL_VERTEX_PROGRAM_NV);
48
49 glBegin(GL_TRIANGLES);
50 glColor3f(0,0,.7);
51 glVertex3f( 0.9, -0.9, -0.0);
52 glColor3f(.8,0,0);
53 glVertex3f( 0.9, 0.9, -0.0);
54 glColor3f(0,.9,0);
55 glVertex3f(-0.9, 0.0, -0.0);
56 glEnd();
57
58
59 glFlush();
60 }
61
62
63 static void Reshape( int width, int height )
64 {
65 glViewport( 0, 0, width, height );
66 glMatrixMode( GL_PROJECTION );
67 glLoadIdentity();
68 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
69 glMatrixMode( GL_MODELVIEW );
70 glLoadIdentity();
71 /*glTranslatef( 0.0, 0.0, -15.0 );*/
72 }
73
74
75 static void Key( unsigned char key, int x, int y )
76 {
77 (void) x;
78 (void) y;
79 switch (key) {
80 case 27:
81 exit(0);
82 break;
83 }
84 glutPostRedisplay();
85 }
86
87
88
89
90 int main( int argc, char *argv[] )
91 {
92 glutInit( &argc, argv );
93 glutInitWindowPosition( 0, 0 );
94 glutInitWindowSize( 250, 250 );
95 glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
96 glutCreateWindow(argv[0]);
97 glewInit();
98 glutReshapeFunc( Reshape );
99 glutKeyboardFunc( Key );
100 glutDisplayFunc( Display );
101 Init();
102 glutMainLoop();
103 return 0;
104 }