progs/trivial: add dlist-flat-tri.c
[mesa.git] / progs / trivial / tri-array-interleaved.c
1 /* Test rebasing */
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 struct {
12 GLubyte color[4];
13 GLfloat vert[3];
14 } verts[] = {
15
16 { { 0x00, 0x00, 0xff, 0x00 },
17 { 0.9, -0.9, 0.0 } },
18
19 { { 0x00, 0xff, 0x00, 0x00 },
20 { 0.9, 0.9, 0.0 } },
21
22 { { 0xff, 0x00, 0x00, 0x00 },
23 { -0.9, 0.9, 0.0 } },
24
25 { { 0xff, 0xff, 0xff, 0x00 },
26 { -0.9, -0.9, 0.0 } },
27 };
28
29 GLuint indices[] = { 1, 2, 3 };
30
31 static void Init( void )
32 {
33 GLint errno;
34 GLuint prognum;
35
36 static const char *prog1 =
37 "!!ARBvp1.0\n"
38 "MOV result.color, vertex.color;\n"
39 "MOV result.position, vertex.position;\n"
40 "END\n";
41
42 glGenProgramsARB(1, &prognum);
43 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
44 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
45 strlen(prog1), (const GLubyte *) prog1);
46
47 assert(glIsProgramARB(prognum));
48 errno = glGetError();
49 printf("glGetError = %d\n", errno);
50 if (errno != GL_NO_ERROR)
51 {
52 GLint errorpos;
53
54 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
55 printf("errorpos: %d\n", errorpos);
56 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
57 }
58
59 glInterleavedArrays( GL_C4UB_V3F, sizeof(verts[0]), verts );
60 }
61
62
63
64 static void Display( void )
65 {
66 glClearColor(0.3, 0.3, 0.3, 1);
67 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
68
69 glEnable(GL_VERTEX_PROGRAM_NV);
70
71 /* Should have min_index == 1, maybe force a rebase:
72 */
73 glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
74
75 glFlush();
76 }
77
78
79 static void Reshape( int width, int height )
80 {
81 glViewport( 0, 0, width, height );
82 glMatrixMode( GL_PROJECTION );
83 glLoadIdentity();
84 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
85 glMatrixMode( GL_MODELVIEW );
86 glLoadIdentity();
87 /*glTranslatef( 0.0, 0.0, -15.0 );*/
88 }
89
90
91 static void Key( unsigned char key, int x, int y )
92 {
93 (void) x;
94 (void) y;
95 switch (key) {
96 case 27:
97 exit(0);
98 break;
99 }
100 glutPostRedisplay();
101 }
102
103
104
105
106 int main( int argc, char *argv[] )
107 {
108 glutInit( &argc, argv );
109 glutInitWindowPosition( 0, 0 );
110 glutInitWindowSize( 250, 250 );
111 glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
112 glutCreateWindow(argv[0]);
113 glewInit();
114 glutReshapeFunc( Reshape );
115 glutKeyboardFunc( Key );
116 glutDisplayFunc( Display );
117 Init();
118 glutMainLoop();
119 return 0;
120 }