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