nvfx: expose GLSL
[mesa/mesa-lb.git] / progs / trivial / vbo-tri.c
blobd4cba14414c80e01310ff6ccbceea51df4063ff9
1 /* Even simpler for many drivers than trivial/tri -- pass-through
2 * vertex shader and vertex data in a VBO.
3 */
5 #include <assert.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10 #include <GL/glew.h>
11 #include <GL/glut.h>
14 struct {
15 GLfloat pos[4];
16 GLfloat color[4];
17 } verts[] =
19 { { -0.9, -0.9, 0.0, 1.0 },
20 {.8,0,0, 1},
23 { { 0.9, -0.9, 0.0, 1.0 },
24 { 0, .9, 0, 1 },
27 { { 0, 0.9, 0.0, 1.0 },
28 {0,0,.7, 1},
32 GLuint arrayObj;
34 static void Init( void )
36 GLint errno;
37 GLuint prognum;
39 static const char *prog1 =
40 "!!ARBvp1.0\n"
41 "MOV result.color, vertex.color;\n"
42 "MOV result.position, vertex.position;\n"
43 "END\n";
46 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);
52 assert(glIsProgramARB(prognum));
53 errno = glGetError();
54 printf("glGetError = %d\n", errno);
55 if (errno != GL_NO_ERROR)
57 GLint errorpos;
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));
65 glEnableClientState( GL_VERTEX_ARRAY );
66 glEnableClientState( GL_COLOR_ARRAY );
68 glGenBuffersARB(1, &arrayObj);
69 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
70 glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), verts, GL_STATIC_DRAW_ARB);
72 glVertexPointer( 4, GL_FLOAT, sizeof(verts[0]), 0 );
73 glColorPointer( 4, GL_FLOAT, sizeof(verts[0]), (void *)(4*sizeof(float)) );
78 static void Display( void )
80 glClearColor(0.3, 0.3, 0.3, 1);
81 glClear( GL_COLOR_BUFFER_BIT );
83 glEnable(GL_VERTEX_PROGRAM_NV);
84 glDrawArrays( GL_TRIANGLES, 0, 3 );
86 glutSwapBuffers();
90 static void Reshape( int width, int height )
92 glViewport( 0, 0, width, height );
93 glMatrixMode( GL_PROJECTION );
94 glLoadIdentity();
95 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
96 glMatrixMode( GL_MODELVIEW );
97 glLoadIdentity();
98 /*glTranslatef( 0.0, 0.0, -15.0 );*/
102 static void Key( unsigned char key, int x, int y )
104 (void) x;
105 (void) y;
106 switch (key) {
107 case 27:
108 exit(0);
109 break;
111 glutPostRedisplay();
117 int main( int argc, char *argv[] )
119 glutInit( &argc, argv );
120 glutInitWindowPosition( 0, 0 );
121 glutInitWindowSize( 250, 250 );
122 glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE );
123 glutCreateWindow(argv[0]);
124 glewInit();
125 glutReshapeFunc( Reshape );
126 glutKeyboardFunc( Key );
127 glutDisplayFunc( Display );
128 Init();
129 glutMainLoop();
130 return 0;