glapi: Move to src/mapi/.
[mesa.git] / progs / trivial / vp-tri-imm.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 "ADD result.color, vertex.color, {.5}.x;\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
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,0);
51 glVertex3f( 0.9, -0.9, -0.0);
52 glVertex3f( 0.9, 0.9, -0.0);
53 glVertex3f(-0.9, 0.0, -0.0);
54 glEnd();
55
56
57 glFlush();
58 }
59
60
61 static void Reshape( int width, int height )
62 {
63 glViewport( 0, 0, width, height );
64 glMatrixMode( GL_PROJECTION );
65 glLoadIdentity();
66 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
67 glMatrixMode( GL_MODELVIEW );
68 glLoadIdentity();
69 /*glTranslatef( 0.0, 0.0, -15.0 );*/
70 }
71
72
73 static void Key( unsigned char key, int x, int y )
74 {
75 (void) x;
76 (void) y;
77 switch (key) {
78 case 27:
79 exit(0);
80 break;
81 }
82 glutPostRedisplay();
83 }
84
85
86
87
88 int main( int argc, char *argv[] )
89 {
90 glutInit( &argc, argv );
91 glutInitWindowPosition( 0, 0 );
92 glutInitWindowSize( 250, 250 );
93 glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
94 glutCreateWindow(argv[0]);
95 glewInit();
96 glutReshapeFunc( Reshape );
97 glutKeyboardFunc( Key );
98 glutDisplayFunc( Display );
99 Init();
100 glutMainLoop();
101 return 0;
102 }