progs/trivial: add dlist-flat-tri.c
[mesa.git] / progs / trivial / draw2arrays.c
1 /* Basic VBO */
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 GLfloat pos[][3] =
12 { { 0.9, -0.9, 0.0 },
13 { 0.9, 0.9, 0.0 },
14 { -0.9, 0.9, 0.0 },
15 { -0.9, -0.9, 0.0 } };
16
17 GLubyte color[][4] =
18 { { 0x00, 0x00, 0xff, 0x00 },
19 { 0x00, 0xff, 0x00, 0x00 },
20 { 0xff, 0x00, 0x00, 0x00 },
21 { 0xff, 0xff, 0xff, 0x00 } };
22
23 static void Init( void )
24 {
25 GLint errno;
26 GLuint prognum;
27
28 static const char *prog1 =
29 "!!ARBvp1.0\n"
30 "MOV result.color, vertex.color;\n"
31 "MOV result.position, vertex.position;\n"
32 "END\n";
33
34 glGenProgramsARB(1, &prognum);
35 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
36 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
37 strlen(prog1), (const GLubyte *) prog1);
38
39 assert(glIsProgramARB(prognum));
40 errno = glGetError();
41 printf("glGetError = %d\n", errno);
42 if (errno != GL_NO_ERROR)
43 {
44 GLint errorpos;
45
46 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
47 printf("errorpos: %d\n", errorpos);
48 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
49 }
50
51
52 glEnableClientState( GL_VERTEX_ARRAY );
53 glEnableClientState( GL_COLOR_ARRAY );
54
55 glVertexPointer( 3, GL_FLOAT, sizeof(pos[0]), pos );
56 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(color[0]), color );
57
58 }
59
60
61
62 static void Display( void )
63 {
64 glClearColor(0.3, 0.3, 0.3, 1);
65 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
66
67 glEnable(GL_VERTEX_PROGRAM_ARB);
68
69 // glDrawArrays( GL_TRIANGLES, 0, 3 );
70 glDrawArrays( GL_TRIANGLES, 1, 3 );
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 }