#if defined(__APPLE__) #include #include #include #else #include #endif #include "plane.h" #include "plane_cloud.h" static GLuint _vertex_buffer_id; static GLuint _index_buffer_id; int initialize_naive_vbo_renderer(void) { #if defined(__APPLE__) CGLContextObj CGL_MACRO_CONTEXT = CGLGetCurrentContext(); #endif if (!gluCheckExtension( (const GLubyte*)"GL_ARB_vertex_buffer_object", glGetString(GL_EXTENSIONS))) { return 0; } glGenBuffersARB(1, &_vertex_buffer_id); if (_vertex_buffer_id == 0) { return 0; } glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vertex_buffer_id); glBufferDataARB( GL_ARRAY_BUFFER_ARB, 3 * sizeof(float) * PLANE_VERTEX_COUNT, PLANE_VERTICES, GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glGenBuffersARB(1, &_index_buffer_id); if (_index_buffer_id == 0) { glDeleteBuffersARB(1, &_vertex_buffer_id); return 0; } glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _index_buffer_id); glBufferDataARB( GL_ELEMENT_ARRAY_BUFFER_ARB, sizeof(unsigned) * PLANE_INDEX_COUNT, PLANE_INDICES, GL_STATIC_DRAW_ARB); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); return 1; } void update_naive_vbo_rendererer(double dt) { #if defined(__APPLE__) CGLContextObj CGL_MACRO_CONTEXT = CGLGetCurrentContext(); #endif unsigned num_planes = plane_count(); const float *matrices = plane_matrices(); glBindBufferARB(GL_ARRAY_BUFFER_ARB, _vertex_buffer_id); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, _index_buffer_id); glVertexPointer(3, GL_FLOAT, 0, 0); glEnableClientState(GL_VERTEX_ARRAY); unsigned i; const float *matrix = matrices; for (i = 0; i < num_planes; ++i) { glPushMatrix(); glMultMatrixf(matrix); glDrawElements( GL_TRIANGLES, PLANE_INDEX_COUNT, GL_UNSIGNED_INT, 0); glPopMatrix(); matrix += 16; } glDisableClientState(GL_VERTEX_ARRAY); glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0); glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0); }