Merge commit 'origin/gallium-master-merge'
[mesa.git] / progs / trivial / vp-line-clip.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.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
41 static 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 #if 0
49 glBegin(GL_LINES);
50 glColor3f(0,0,1);
51 glVertex3f( 0.75, -0.75, 0.0);
52 glColor3f(0,1,0);
53 glVertex3f( 0.75, 0.75, 0.0);
54
55 glColor3f(0,1,0);
56 glVertex3f( 0.75, 0.75, 0.0);
57 glColor3f(1,0,0);
58 glVertex3f(-1.75, 0.0, 0.0);
59 glEnd();
60 #else
61 glBegin(GL_LINE_STRIP);
62 glColor3f(0,0,1);
63 glVertex3f( 0.75, -0.75, 0.0);
64 glColor3f(0,1,0);
65 glVertex3f( 0.75, 0.75, 0.0);
66 glColor3f(1,0,0);
67 glVertex3f(-1.75, 0.0, 0.0);
68 glEnd();
69 #endif
70
71
72 glFlush();
73 }
74
75
76 static void Reshape( int width, int height )
77 {
78 glViewport( 0, 0, width, height );
79 glMatrixMode( GL_PROJECTION );
80 glLoadIdentity();
81 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
82 glMatrixMode( GL_MODELVIEW );
83 glLoadIdentity();
84 /*glTranslatef( 0.0, 0.0, -15.0 );*/
85 }
86
87
88 static void Key( unsigned char key, int x, int y )
89 {
90 (void) x;
91 (void) y;
92 switch (key) {
93 case 27:
94 exit(0);
95 break;
96 }
97 glutPostRedisplay();
98 }
99
100
101
102
103 int main( int argc, char *argv[] )
104 {
105 glutInit( &argc, argv );
106 glutInitWindowPosition( 0, 0 );
107 glutInitWindowSize( 250, 250 );
108 glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
109 glutCreateWindow(argv[0]);
110 glewInit();
111 glutReshapeFunc( Reshape );
112 glutKeyboardFunc( Key );
113 glutDisplayFunc( Display );
114 Init();
115 glutMainLoop();
116 return 0;
117 }