2 * Test glMapBuffer() call immediately after glDrawArrays().
5 * NOTE: Do not use freeglut with this test! It calls the Display()
6 * callback twice right away instead of just once.
18 static GLuint BufferID
;
27 * Create VBO (position and color) and load with data.
32 static const GLfloat data
[] = {
33 /* vertex */ /* color */
40 glGenBuffersARB(1, &BufferID
);
41 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, BufferID
);
42 glBufferDataARB(GL_ARRAY_BUFFER_ARB
, sizeof(data
), data
,
52 printf("Draw Frame %d\n", count
);
55 glBindBufferARB(GL_ARRAY_BUFFER_ARB
, BufferID
);
56 glVertexPointer(3, GL_FLOAT
, 24, 0);
57 glEnableClientState(GL_VERTEX_ARRAY
);
59 glColorPointer(3, GL_FLOAT
, 24, (void*) 12);
60 glEnableClientState(GL_COLOR_ARRAY
);
62 glDrawArrays(GL_TRIANGLE_FAN
, 0, 4);
67 /* Immediately map the color buffer and change something.
68 * This should not effect the first glDrawArrays above, but the
69 * next time we draw we should see a black vertex.
72 GLfloat
*m
= (GLfloat
*) glMapBufferARB(GL_ARRAY_BUFFER_ARB
,
74 m
[3] = m
[4] = m
[5] = 0.0f
; /* black vertex */
75 glUnmapBufferARB(GL_ARRAY_BUFFER_ARB
);
80 static void Display( void )
82 glClear( GL_COLOR_BUFFER_BIT
);
88 static void Reshape( int width
, int height
)
90 float ar
= (float) width
/ (float) height
;
91 glViewport( 0, 0, width
, height
);
92 glMatrixMode( GL_PROJECTION
);
94 glFrustum( -ar
, ar
, -1.0, 1.0, 5.0, 25.0 );
95 glMatrixMode( GL_MODELVIEW
);
97 glTranslatef( 0.0, 0.0, -15.0 );
101 static void Key( unsigned char key
, int x
, int y
)
106 glutDestroyWindow(Win
);
113 static void Init( void )
115 if (!glutExtensionSupported("GL_ARB_vertex_buffer_object")) {
116 printf("GL_ARB_vertex_buffer_object not found!\n");
119 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
125 int main( int argc
, char *argv
[] )
127 glutInit( &argc
, argv
);
128 glutInitWindowPosition( 0, 0 );
129 glutInitWindowSize( 300, 300 );
130 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
131 Win
= glutCreateWindow(argv
[0]);
133 glutReshapeFunc( Reshape
);
134 glutKeyboardFunc( Key
);
135 glutDisplayFunc( Display
);