ARB prog parser: fix parameter binding type
[mesa.git] / progs / trivial / vbo-drawarrays.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
12 struct {
13 GLfloat pos[3];
14 GLubyte color[4];
15 } verts[] =
16 {
17 { { 0.9, -0.9, 0.0 },
18 { 0x00, 0x00, 0xff, 0x00 }
19 },
20
21 { { 0.9, 0.9, 0.0 },
22 { 0x00, 0xff, 0x00, 0x00 }
23 },
24
25 { { -0.9, 0.9, 0.0 },
26 { 0xff, 0x00, 0x00, 0x00 }
27 },
28
29 { { -0.9, -0.9, 0.0 },
30 { 0xff, 0xff, 0xff, 0x00 }
31 },
32 };
33
34 GLuint arrayObj, elementObj;
35
36 static void Init( void )
37 {
38 GLint errno;
39 GLuint prognum;
40
41 static const char *prog1 =
42 "!!ARBvp1.0\n"
43 "MOV result.color, vertex.color;\n"
44 "MOV result.position, vertex.position;\n"
45 "END\n";
46
47 glGenProgramsARB(1, &prognum);
48 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
49 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
50 strlen(prog1), (const GLubyte *) prog1);
51
52 assert(glIsProgramARB(prognum));
53 errno = glGetError();
54 printf("glGetError = %d\n", errno);
55 if (errno != GL_NO_ERROR)
56 {
57 GLint errorpos;
58
59 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
60 printf("errorpos: %d\n", errorpos);
61 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
62 }
63
64
65 glEnableClientState( GL_VERTEX_ARRAY );
66 glEnableClientState( GL_COLOR_ARRAY );
67
68 glGenBuffersARB(1, &arrayObj);
69 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
70 glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STATIC_DRAW_ARB);
71
72 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), 0 );
73 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(verts[0]), (void *)(3*sizeof(float)) );
74
75 }
76
77
78
79 static void Display( void )
80 {
81 glClearColor(0.3, 0.3, 0.3, 1);
82 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
83
84 glEnable(GL_VERTEX_PROGRAM_ARB);
85
86 /* glDrawArrays( GL_TRIANGLES, 0, 3 ); */
87 glDrawArrays( GL_TRIANGLES, 1, 3 );
88
89 glFlush();
90 }
91
92
93 static void Reshape( int width, int height )
94 {
95 glViewport( 0, 0, width, height );
96 glMatrixMode( GL_PROJECTION );
97 glLoadIdentity();
98 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
99 glMatrixMode( GL_MODELVIEW );
100 glLoadIdentity();
101 /*glTranslatef( 0.0, 0.0, -15.0 );*/
102 }
103
104
105 static void Key( unsigned char key, int x, int y )
106 {
107 (void) x;
108 (void) y;
109 switch (key) {
110 case 27:
111 exit(0);
112 break;
113 }
114 glutPostRedisplay();
115 }
116
117
118
119
120 int main( int argc, char *argv[] )
121 {
122 glutInit( &argc, argv );
123 glutInitWindowPosition( 0, 0 );
124 glutInitWindowSize( 250, 250 );
125 glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
126 glutCreateWindow(argv[0]);
127 glewInit();
128 glutReshapeFunc( Reshape );
129 glutKeyboardFunc( Key );
130 glutDisplayFunc( Display );
131 Init();
132 glutMainLoop();
133 return 0;
134 }