blob: 0672ca50ff193a11b88f4d7b53a7269267be673a [file] [log] [blame]
Keith Whitwell5f2569a2009-04-30 12:35:59 +01001/* 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
12struct {
13 GLfloat pos[4][4];
14 GLfloat col[4][4];
15} verts =
16{
17 /* Position: a quad
18 */
19 {
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 },
24 },
25
26 /* Color: all red
27 */
28 {
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 },
33 },
34
35
36};
37
38GLuint arrayObj, elementObj;
39
40static void Init( void )
41{
42 GLint errno;
43 GLuint prognum;
44
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";
50
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);
55
56 assert(glIsProgramARB(prognum));
57 errno = glGetError();
58 printf("glGetError = %d\n", errno);
59 if (errno != GL_NO_ERROR)
60 {
61 GLint errorpos;
62
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));
66 }
67
68
69 glEnableClientState( GL_VERTEX_ARRAY );
70 glEnableClientState( GL_COLOR_ARRAY );
71
72 glGenBuffersARB(1, &arrayObj);
73 glBindBufferARB(GL_ARRAY_BUFFER_ARB, arrayObj);
74 glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verts), &verts, GL_STATIC_DRAW_ARB);
75
76 glVertexPointer( 4, GL_FLOAT, sizeof(verts.pos[0]), 0 );
77 glColorPointer( 4, GL_FLOAT, sizeof(verts.col[0]), (void *)(4*4*sizeof(float)) );
78
79}
80
81
82
83static void Display( void )
84{
85 glClearColor(0.3, 0.3, 0.3, 1);
86 glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
87
88 glEnable(GL_VERTEX_PROGRAM_ARB);
89
90// glDrawArrays( GL_TRIANGLES, 0, 3 );
91// glDrawArrays( GL_TRIANGLES, 1, 3 );
92 glDrawArrays( GL_QUADS, 0, 4 );
93
94 glFlush();
95}
96
97
98static void Reshape( int width, int height )
99{
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 );*/
107}
108
109
110static void Key( unsigned char key, int x, int y )
111{
112 (void) x;
113 (void) y;
114 switch (key) {
115 case 27:
116 exit(0);
117 break;
118 }
119 glutPostRedisplay();
120}
121
122
123
124
125int main( int argc, char *argv[] )
126{
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;
139}