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