gallium: change remaining util functions to use cso sampler views
[mesa/mesa-lb.git] / progs / trivial / vbo-noninterleaved.c
blobf7c42a89818273176dc6df6b0d2408f20df9bde3
1 /* Basic VBO */
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>
12 struct {
13 GLfloat pos[4][4];
14 GLfloat col[4][4];
15 } verts =
17 /* Position: a quad
20 { 0.9, -0.9, 0.0, 1.0 },
21 { 0.9, 0.9, 0.0, 1.0 },
22 { -0.9, 0.9, 0.0, 1.0 },
23 { -0.9, -0.9, 0.0, 1.0 },
26 /* Color: all red
29 { 1.0, 0.0, 0.0, 1.0 },
30 { 1.0, 0.0, 0.0, 1.0 },
31 { 1.0, 0.0, 0.0, 1.0 },
32 { 1.0, 0.0, 0.0, 1.0 },
38 GLuint arrayObj, elementObj;
40 static void Init( void )
42 GLint errno;
43 GLuint prognum;
45 static const char *prog1 =
46 "!!ARBvp1.0\n"
47 "MOV result.color, vertex.color;\n"
48 "MOV result.position, vertex.position;\n"
49 "END\n";
51 glGenProgramsARB(1, &prognum);
52 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
53 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
54 strlen(prog1), (const GLubyte *) prog1);
56 assert(glIsProgramARB(prognum));
57 errno = glGetError();
58 printf("glGetError = %d\n", errno);
59 if (errno != GL_NO_ERROR)
61 GLint errorpos;
63 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
64 printf("errorpos: %d\n", errorpos);
65 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
69 glEnableClientState( GL_VERTEX_ARRAY );
70 glEnableClientState( GL_COLOR_ARRAY );
72 glGenBuffersARB(1, &arrayObj);
73 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
74 glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), &verts, GL_STATIC_DRAW_ARB);
76 glVertexPointer( 4, GL_FLOAT, sizeof(verts.pos[0]), 0 );
77 glColorPointer( 4, GL_FLOAT, sizeof(verts.col[0]), (void *)(4*4*sizeof(float)) );
83 static void Display( void )
85 glClearColor(0.3, 0.3, 0.3, 1);
86 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
88 glEnable(GL_VERTEX_PROGRAM_ARB);
90 /* glDrawArrays( GL_TRIANGLES, 0, 3 ); */
91 /* glDrawArrays( GL_TRIANGLES, 1, 3 ); */
92 glDrawArrays( GL_QUADS, 0, 4 );
94 glFlush();
98 static void Reshape( int width, int height )
100 glViewport( 0, 0, width, height );
101 glMatrixMode( GL_PROJECTION );
102 glLoadIdentity();
103 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
104 glMatrixMode( GL_MODELVIEW );
105 glLoadIdentity();
106 /*glTranslatef( 0.0, 0.0, -15.0 );*/
110 static void Key( unsigned char key, int x, int y )
112 (void) x;
113 (void) y;
114 switch (key) {
115 case 27:
116 exit(0);
117 break;
119 glutPostRedisplay();
125 int main( int argc, char *argv[] )
127 glutInit( &argc, argv );
128 glutInitWindowPosition( 0, 0 );
129 glutInitWindowSize( 250, 250 );
130 glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
131 glutCreateWindow(argv[0]);
132 glewInit();
133 glutReshapeFunc( Reshape );
134 glutKeyboardFunc( Key );
135 glutDisplayFunc( Display );
136 Init();
137 glutMainLoop();
138 return 0;