Use glad instead of GLEW.
[mesa-demos.git] / src / trivial / drawarrays.c
blobda4de10c1555456d108ba5d61d9b0eb3233089c1
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 <glad/glad.h>
9 #include "glut_wrap.h"
12 struct {
13 GLfloat pos[3];
14 GLubyte color[4];
15 } verts[] =
17 { { 0.9, -0.9, 0.0 },
18 { 0x00, 0x00, 0xff, 0x00 }
21 { { 0.9, 0.9, 0.0 },
22 { 0x00, 0xff, 0x00, 0x00 }
25 { { -0.9, 0.9, 0.0 },
26 { 0xff, 0x00, 0x00, 0x00 }
29 { { -0.9, -0.9, 0.0 },
30 { 0xff, 0xff, 0xff, 0x00 }
34 static void Init( void )
36 GLint errnum;
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";
45 glGenProgramsARB(1, &prognum);
46 glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
47 glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
48 strlen(prog1), (const GLubyte *) prog1);
50 assert(glIsProgramARB(prognum));
51 errnum = glGetError();
52 printf("glGetError = %d\n", errnum);
53 if (errnum != GL_NO_ERROR)
55 GLint errorpos;
57 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
58 printf("errorpos: %d\n", errorpos);
59 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
63 glEnableClientState( GL_VERTEX_ARRAY );
64 glEnableClientState( GL_COLOR_ARRAY );
66 glVertexPointer( 3, GL_FLOAT, sizeof(verts[0]), verts[0].pos );
67 glColorPointer( 4, GL_UNSIGNED_BYTE, sizeof(verts[0]), verts[0].color );
73 static void Display( void )
75 glClearColor(0.3, 0.3, 0.3, 1);
76 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
78 glEnable(GL_VERTEX_PROGRAM_ARB);
80 /* glDrawArrays( GL_TRIANGLES, 0, 3 ); */
81 glDrawArrays( GL_TRIANGLES, 1, 3 );
83 glFlush();
87 static void Reshape( int width, int height )
89 glViewport( 0, 0, width, height );
90 glMatrixMode( GL_PROJECTION );
91 glLoadIdentity();
92 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
93 glMatrixMode( GL_MODELVIEW );
94 glLoadIdentity();
95 /*glTranslatef( 0.0, 0.0, -15.0 );*/
99 static void Key( unsigned char key, int x, int y )
101 (void) x;
102 (void) y;
103 switch (key) {
104 case 27:
105 exit(0);
106 break;
108 glutPostRedisplay();
114 int main( int argc, char *argv[] )
116 glutInit( &argc, argv );
117 glutInitWindowPosition( 0, 0 );
118 glutInitWindowSize( 250, 250 );
119 glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
120 glutCreateWindow(argv[0]);
121 gladLoadGL();
122 glutReshapeFunc( Reshape );
123 glutKeyboardFunc( Key );
124 glutDisplayFunc( Display );
125 Init();
126 glutMainLoop();
127 return 0;