void init( void ) { vec3 vertices[4] = { vec3( 0.0, 0.0, -1.0 ), vec3( 0.0, 0.942809, 0.333333 ), vec3( -0.816497, -0.471405, 0.333333 ), vec3( 0.816497, -0.471405, 0.333333 ) }; // Subdivide the original tetrahedron divide_tetra( vertices[0], vertices[1], vertices[2], vertices[3], NumTimesToSubdivide ); // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); // First, we create an empty buffer of the size we need by passing // a NULL pointer for the data values glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors), NULL, GL_STATIC_DRAW ); // Next, we load the real data in parts. We need to specify the // correct byte offset for placing the color data after the point // data in the buffer. Conveniently, the byte offset we need is // the same as the size (in bytes) of the points array, which is // returned from "sizeof(points)". glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader24.glsl", "fshader24.glsl" ); glUseProgram( program ); // Initialize the vertex position attribute from the vertex shader GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); // Likewise, initialize the vertex color attribute. Once again, we // need to specify the starting offset (in bytes) for the color // data. Just like loading the array, we use "sizeof(points)" // to determine the correct value. GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)) ); glEnable( GL_DEPTH_TEST ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); /* white background */ }
void TextureAtlas::setupVAOAndVBO(){ glGenVertexArraysAPPLE(1,&_vao); glBindVertexArrayAPPLE(_vao); glGenBuffers(2,&_bufferVBO[0]); glBindBuffer(GL_ARRAY_BUFFER,_bufferVBO[0]); glBufferData(GL_ARRAY_BUFFER,sizeof(V2F_C4F_T2F_Quad) * _capacity,_quads,GL_DYNAMIC_DRAW); #define kStrip sizeof(_quads[0].bl) // vertices glEnableVertexAttribArray(_shader->get_A_PositionId()); glVertexAttribPointer(_shader->get_A_PositionId(),2,GL_FLOAT,GL_FALSE,kStrip, (GLvoid*)offsetof(V2F_C4F_T2F,vertices)); // colors glEnableVertexAttribArray(_shader->get_A_ColorId()); glVertexAttribPointer(_shader->get_A_ColorId(),4,GL_FLOAT,GL_FALSE,kStrip,(GLvoid*)offsetof(V2F_C4F_T2F,colors)); // texCoords glEnableVertexAttribArray(_shader->get_A_TexCoordsId()); glVertexAttribPointer(_shader->get_A_TexCoordsId(),2,GL_FLOAT,GL_FALSE,kStrip, (GLvoid*)offsetof(V2F_C4F_T2F,texCoords)); // indices glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,_bufferVBO[1]); glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(_indices[0]) * _capacity * 6,_indices,GL_STATIC_DRAW); // unbind vao vbos glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,0); glBindBuffer(GL_ARRAY_BUFFER,0); glBindVertexArrayAPPLE(0); }
void init() { // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); /* set up buffer object */ glGenBuffers(1, buffers); glBindBuffer(GL_ARRAY_BUFFER, buffers[0]); glBufferData(GL_ARRAY_BUFFER, sizeof(square), square, GL_STATIC_DRAW); program = InitShader("vshader48.glsl", "fshader48.glsl"); glUseProgram( program ); loc = glGetAttribLocation(program, "vPosition"); glEnableVertexAttribArray(loc); glVertexAttribPointer(loc, 4, GL_FLOAT, GL_FALSE, 0, 0); matrix_loc = glGetUniformLocation(program, "model_view"); projection_loc = glGetUniformLocation(program, "projection"); color_loc = glGetUniformLocation(program, "fcolor"); for(int i =0; i<4; i++) for(int j =0; j<4;j++) m[i][j] = 0.0; m[0][0] = m[1][1] = m[2][2] = 1.0; m[3][1] = -1.0/light[1]; glClearColor(1.0, 1.0, 1.0, 1.0); /* white background */ }
// OpenGL initialization void init() { mesh(); // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vmesh.glsl", "fmesh.glsl" ); glUseProgram( program ); // set up vertex arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); timeParam = glGetUniformLocation(program, "time"); MVP_loc = glGetUniformLocation(program, "ModelViewProjection"); glClearColor( 1.0, 1.0, 1.0, 1.0 ); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); }
void rxImage::draw(const float& x, const float& y, const float& w, const float& h) { bool vao_bound = false; if(!buffer_created) { vao_bound = true; glGenVertexArraysAPPLE(1, &vao); eglGetError(); glBindVertexArrayAPPLE(vao); eglGetError(); glGenBuffers(1, &vbo); eglGetError(); glBindBuffer(GL_ARRAY_BUFFER, vbo); eglGetError(); vector<VertexPT> buffer(6); buffer[0].set(0, 0, 0, 0, 1); buffer[1].set(w, 0, 0, 1, 1); buffer[2].set(w, h, 0, 1, 0); buffer[3].set(w, h, 0, 1, 0); buffer[4].set(0, h, 0, 0, 0); buffer[5].set(0, 0, 0, 0, 1); glBufferData(GL_ARRAY_BUFFER, sizeof(VertexPT) * buffer.size(), buffer[0].getPtr(), GL_DYNAMIC_DRAW); eglGetError(); glEnableVertexAttribArray(shader.getAttribute("pos")); eglGetError(); glEnableVertexAttribArray(shader.getAttribute("tex")); eglGetError(); glVertexAttribPointer(shader.getAttribute("pos"), 3, GL_FLOAT, GL_FALSE, sizeof(VertexPT), (GLvoid*)offsetof(VertexPT, pos)); eglGetError(); glVertexAttribPointer(shader.getAttribute("tex"), 2, GL_FLOAT, GL_FALSE, sizeof(VertexPT), (GLvoid*)offsetof(VertexPT, tex)); eglGetError(); buffer_created = true; prev_w = w; prev_h = h; } else if( (prev_w != 0 && prev_w != w) || (prev_h != 0 && prev_h != h) ) { vector<VertexPT> buffer(6); buffer[0].set(0, 0, 0, 0, 1); buffer[1].set(w, 0, 0, 1, 1); buffer[2].set(w, h, 0, 1, 0); buffer[3].set(w, h, 0, 1, 0); buffer[4].set(0, h, 0, 0, 0); buffer[5].set(0, 0, 0, 0, 1); glBindBuffer(GL_ARRAY_BUFFER, vbo); eglGetError(); glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(VertexPT) * buffer.size(), buffer[0].getPtr()); eglGetError(); prev_w = w; prev_h = h; } if(!vao_bound) { glBindVertexArrayAPPLE(vao); eglGetError(); } shader.enable(); glEnable(GL_TEXTURE_2D); eglGetError(); glActiveTexture(GL_TEXTURE0); eglGetError(); glBindTexture(GL_TEXTURE_2D, tex.getID()); eglGetError(); shader.uniform1i("texture", 0); model_matrix.setPosition(x, y,0); shader.uniformMat4fv("modelview_matrix", model_matrix.getPtr()); glDrawArrays(GL_TRIANGLES, 0, 6); eglGetError(); shader.disable(); glDisable(GL_TEXTURE_2D); glBindVertexArrayAPPLE(0); glBindBuffer(GL_ARRAY_BUFFER, 0); }
void Mesh::InitTexMesh(const IndexedModel& model) { m_numIndices = model.indices.size(); glGenVertexArraysAPPLE(1, &m_vertexArrayObject); glBindVertexArrayAPPLE(m_vertexArrayObject); glGenBuffers(NUM_BUFFERS, m_vertexArrayBuffers); glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[POSITION_VB]); glBufferData(GL_ARRAY_BUFFER, sizeof(model.positions[0]) * model.positions.size(), &model.positions[0], GL_STATIC_DRAW); glEnableVertexAttribArray(0); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[TEXCOORD_VB]); glBufferData(GL_ARRAY_BUFFER, sizeof(model.texCoords[0]) * model.texCoords.size(), &model.texCoords[0], GL_STATIC_DRAW); glEnableVertexAttribArray(1); glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ARRAY_BUFFER, m_vertexArrayBuffers[NORMAL_VB]); glBufferData(GL_ARRAY_BUFFER, sizeof(model.normals[0]) * model.normals.size(), &model.normals[0], GL_STATIC_DRAW); glEnableVertexAttribArray(2); glVertexAttribPointer(2, 3, GL_FLOAT, GL_FALSE, 0, 0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_vertexArrayBuffers[INDEX_VB]); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(model.indices[0]) * model.indices.size(), &model.indices[0], GL_STATIC_DRAW); glBindVertexArrayAPPLE(0); }
/* Constructor * Allocate memory for Object */ SceneObject::SceneObject(int nv) { numVertices = nv; points = new point4[nv]; colors = new color4[nv]; normals = new normal4[nv]; glGenVertexArraysAPPLE(1,&vao); }
void Cube::InitDraw(){ // Initialize the data array on CPU m_Points[0] = Eigen::Vector4f( -0.5, -0.5, 0.5, 1.0 ); m_Points[1] = Eigen::Vector4f( -0.5, 0.5, 0.5, 1.0 ); m_Points[2] = Eigen::Vector4f( 0.5, 0.5, 0.5, 1.0 ); m_Points[3] = Eigen::Vector4f( 0.5, -0.5, 0.5, 1.0 ); m_Points[4] = Eigen::Vector4f( -0.5, -0.5, -0.5, 1.0 ); m_Points[5] = Eigen::Vector4f( -0.5, 0.5, -0.5, 1.0 ); m_Points[6] = Eigen::Vector4f( 0.5, 0.5, -0.5, 1.0 ); m_Points[7] = Eigen::Vector4f( 0.5, -0.5, -0.5, 1.0 ); m_Vertices = new Eigen::Vector4f[36]; m_Normals = new Eigen::Vector3f[36]; m_Index = 0; //generate the 6 faces with distinct colors GenFace( 5, 1, 0, 3, 2 ); GenFace( 1, 2, 3, 7, 6 ); GenFace( 2, 3, 0, 4, 7 ); GenFace( 3, 6, 5, 1, 2 ); GenFace( 4, 4, 5, 6, 7 ); GenFace( 0, 5, 4, 0, 1 ); //Create the Vertex Array and Buffers, bind them #ifdef __APPLE__ glGenVertexArraysAPPLE(1, &m_vertexArrayObject); glBindVertexArrayAPPLE(m_vertexArrayObject);//use as current vertex array #else glGenVertexArrays(1, &m_vertexArrayObject); glBindVertexArray(m_vertexArrayObject);//use as current vertex array #endif glGenBuffers(1, &m_vertexBufferObject);//generate buffer for current vertex array glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferObject);//use as current buffer //Send data from CPU to GPU glBufferData(GL_ARRAY_BUFFER, (sizeof(m_Vertices[0]) + sizeof(m_Normals[0]))*36, NULL, GL_STATIC_DRAW);//send data to current buffer glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(m_Vertices[0])*36, m_Vertices); glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_Vertices[0])*36, sizeof(m_Normals[0])*36, m_Normals); //load and compile shaders on GPU, use current shader program m_shader = Util::InitShader( "vPhong.glsl", "fPhong.glsl" ); glUseProgram(m_shader); // Link the Shader with the buffer data // initialize the vertex position attribute from the vertex shader GLuint position = glGetAttribLocation( m_shader, "vPosition" ); glEnableVertexAttribArray( position ); glVertexAttribPointer(position, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); GLuint normal = glGetAttribLocation(m_shader, "vNormal"); glEnableVertexAttribArray(normal); glVertexAttribPointer(normal, 3, GL_FLOAT, GL_FALSE,0, BUFFER_OFFSET(sizeof(m_Vertices[0])*36)); }
VAO::VAO() { CHECK_FOR_GL_ERROR; CHECK_F(glGenVertexArraysAPPLE != nullptr); CHECK_F(glDeleteVertexArraysAPPLE != nullptr); CHECK_F(glBindVertexArrayAPPLE != nullptr); glGenVertexArraysAPPLE(1, &_id); CHECK_FOR_GL_ERROR; }
_JATTA_EXPORT void Jatta::OpenGL::VertexArray::Create() { # ifdef JATTA_MACOS glGenVertexArraysAPPLE(1, &vertexArray); # else glGenVertexArrays(1, &vertexArray); # endif GLCHECK("Failed to generate vertex array."); }
ClothGL::ClothGL(Cloth& rCloth) :cloth(rCloth) ,particles(cloth.particles.particles) { num_vertices = cloth.cols * cloth.rows; num_indices = (cloth.cols-1) * (cloth.rows-1) * 4; glGenVertexArraysAPPLE(1, &vao_id); eglGetError(); glGenBuffers(1, &vbo_data); eglGetError(); glGenBuffers(1, &vbo_indices); eglGetError(); }
bool YUV420PGrabber::setupVAO() { assert(vao == 0); #if YUV420P_USE_APPLE_VAO glGenVertexArraysAPPLE(1, &vao); #else glGenVertexArrays(1, &vao); #endif return true; }
Platform3DObject Extensions3DOpenGL::createVertexArrayOES() { m_context->makeContextCurrent(); #if !PLATFORM(GTK) && !PLATFORM(QT) && defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object GLuint array = 0; glGenVertexArraysAPPLE(1, &array); return array; #else return 0; #endif }
Platform3DObject Extensions3DOpenGL::createVertexArrayOES() { m_context->makeContextCurrent(); GLuint array = 0; #if (PLATFORM(GTK) || PLATFORM(EFL) || PLATFORM(WIN) || PLATFORM(NIX) || PLATFORM(JS)) if (isVertexArrayObjectSupported()) glGenVertexArrays(1, &array); #elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object glGenVertexArraysAPPLE(1, &array); #endif return array; }
void init( void ) { colorcube(); /* set up particles with random locations and velocities */ for ( int i = 0; i < num_particles; i++ ) { particles[i].mass = 1.0; particles[i].color = i % NUM_COLORS; for ( int j = 0; j < 3; j++ ) { particles[i].position[j] = 2.0 * ( ( float ) rand() / RAND_MAX ) - 1.0; particles[i].velocity[j] = speed * 2.0 * ( ( float ) rand() / RAND_MAX ) - 1.0; } particles[i].position[3] = 1.0; } // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(point_colors), NULL, GL_STATIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(point_colors), point_colors ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader91.glsl", "fshader91.glsl" ); glUseProgram( program ); // set up vertex arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)) ); model_view_loc = glGetUniformLocation( program, "ModelView" ); projection_loc = glGetUniformLocation( program, "Projection" ); glClearColor( 0.5, 0.5, 0.5, 1.0 ); glPointSize( point_size ); }
void init(){ print_version_info(); print_err("start init"); vec2 points[NumPoints]; // Specifiy the vertices for a triangle vec2 vertices[3] = { vec2( -1.0, -1.0 ), vec2( 0.0, 1.0 ), vec2( 1.0, -1.0 ) }; // Select an arbitrary initial point inside of the triangle points[0] = vec2( 0.25, 0.50 ); // compute and store N-1 new points for ( int i = 1; i < NumPoints; ++i ) { int j = rand() % 3; // pick a vertex at random // Compute the point halfway between the selected vertex // and the previous point points[i] = ( points[i - 1] + vertices[j] ) / 2.0; } // print_err("finish making points"); // Create a vertex array object GLuint vao[1]; glGenVertexArraysAPPLE( 1, vao ); glBindVertexArrayAPPLE( vao[0] ); // print_err("gen and bind vertex arrays"); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); // print_err("bind buffer and buffer data"); // Load shaders and use the resulting shader program GLuint program = InitShader( "vertex1.glsl", "frag1.glsl" ); glUseProgram(program); print_err("glUseProgram"); // Initialize the vertex position attribute from the vertex shader GLuint loc = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( loc ); glVertexAttribPointer( loc, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background }
void init(void) { vec2 points[6] = { vec2(-0.5, -0.5),vec2(0.5, -0.5), vec2(0.5, 0.5), vec2(0.5, 0.5), vec2(-0.5, 0.5), vec2(-0.5, -0.5) }; GLuint vao, buffer; glGenVertexArraysAPPLE(1, &vao); glBindVertexArrayAPPLE(vao); }
void init( void ) { vec3 points[NumPoints]; // Specifiy the vertices for a tetrahedron vec3 vertices[] = { vec3( -0.5, -0.5, -0.5 ), vec3( 0.5, -0.5, -0.5 ), vec3( 0.0, 0.5, 0.0 ), vec3( 0.0, -0.5, 0.5 ) }; // Select an arbitrary initial point inside of the triangle points[0] = vec3( 0.0, 0.0, 0.0 ); // compute and store N-1 new points for ( int i = 1; i < NumPoints; ++i ) { int j = rand() % 3; // pick a vertex at random // Compute the point halfway between the selected vertex // and the previous point points[i] = ( points[i - 1] + vertices[j] ) / 2.0; } // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader23.glsl", "fshader23.glsl" ); glUseProgram( program ); // Initialize the vertex position attribute from the vertex shader GLuint loc = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( loc ); glVertexAttribPointer( loc, 3, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); // white background }
void init() { // Create a vertex array object GLuint vao[1]; #ifdef __APPLE__ // For use with OS X glGenVertexArraysAPPLE(1, vao ); glBindVertexArrayAPPLE(vao[0] ); #else // Other (Linux) glGenVertexArrays(1, vao ); glBindVertexArray(vao[0] ); #endif // Create and initialize a buffer object GLuint buffer; glGenBuffers( 2, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors), NULL, GL_STATIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors ); // Load shaders and use the resulting shader program GLuint program = InitShader( "v_bezier.glsl", "f_bezier.glsl" ); glUseProgram( program ); // set up vertex arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)) ); // Generate the Projection Matrix and send to vertex shader: GLuint Projection_loc = glGetUniformLocation( program, "Projection" ); glUniformMatrix4fv( Projection_loc, 1, GL_TRUE, Ortho( -1,1,-1,1, -1 ,1 ) ); glShadeModel(GL_FLAT); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // set clear color to white glClearColor (0.95, 0.95, 0.95, 1.0); }
void ModelRenderMesh::setup() { #ifdef RENDER_PIPELINE // TODO #else // Create the buffers for the vertices atttributes #ifdef RENDER_VAO_NORMAL glGenVertexArrays(1, &geometryVAO); glBindVertexArray(geometryVAO); #else glGenVertexArraysAPPLE(1, &geometryVAO); glBindVertexArrayAPPLE(geometryVAO); #endif // Create the buffers for the vertices atttributes glGenBuffers(7, m_Buffers); #endif }
Platform3DObject Extensions3DOpenGL::createVertexArrayOES() { m_context->makeContextCurrent(); GLuint array = 0; #if (PLATFORM(GTK) || PLATFORM(EFL)) || PLATFORM(WIN) if (isVertexArrayObjectSupported()) glGenVertexArrays(1, &array); #elif PLATFORM(QT) #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0) if (isVertexArrayObjectSupported()) m_vaoFunctions->glGenVertexArrays(1, &array); #endif #elif defined(GL_APPLE_vertex_array_object) && GL_APPLE_vertex_array_object glGenVertexArraysAPPLE(1, &array); #endif return array; }
void init( void ) { colorcube(); // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(colors), NULL, GL_DYNAMIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0, sizeof(points), points ); glBufferSubData( GL_ARRAY_BUFFER, sizeof(points), sizeof(colors), colors ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader82.glsl", "fshader82.glsl" ); glUseProgram( program ); GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(sizeof(points)) ); ModelView = glGetUniformLocation( program, "ModelView" ); Projection = glGetUniformLocation( program, "Projection" ); glEnable( GL_DEPTH_TEST ); glPolygonMode( GL_FRONT_AND_BACK, GL_LINE ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); }
void init() { // Generate spline data vec2 points[NumVertices+4]; for ( int i = 0; i < NumVertices; ++i ) { const float d = 1.0 / ( NumVertices - 1.0 ); float u = i * d; float v = 1.0 - u; points[i] = (u*u*u)*p[0] + 3*(u*u*v)*p[1] + 3*(u*v*v)*p[2] + (v*v*v)*p[3]; } for(int i =0; i<4; i++) points[NumVertices+i] = p[i]; // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points), points, GL_STATIC_DRAW ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader102.glsl", "fshader102.glsl" ); glUseProgram( program ); // set up vertex arrays GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); glPointSize(5.0); glClearColor( 1.0, 1.0, 1.0, 1.0 ); }
void init() { printf("init start\n"); #if defined(WIN) glGenVertexArrays(NumVAOs,VAOs); glBindVertexArray(VAOs[Triangles]); #endif #if defined(MAC) glGenVertexArraysAPPLE(NumVAOs,VAOs); glBindVertexArrayAPPLE(VAOs[Triangles]); #endif GLfloat vertices[NumVertices][2] = { {-0.90,-0.90}, {0.85,-0.90}, {-0.90,0.85}, {0.90,0.90}, {0.90,-0.85}, {-0.85,0.90} }; glGenBuffers(NumBuffers,Buffers); glBindBuffer(GL_ARRAY_BUFFER,Buffers[ArrayBuffer]); glBufferData(GL_ARRAY_BUFFER,sizeof(vertices),vertices,GL_STATIC_DRAW); ShaderInfo shaders[] = { {GL_VERTEX_SHADER,"./triangles.vert"}, {GL_FRAGMENT_SHADER,"./triangles.frag"}, {GL_NONE,NULL} }; printf("init 2\n"); GLuint program = LoadShaders(shaders); if(program == 0) return; glUseProgram(program); glVertexAttribPointer(vPosition,2,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(0)); glEnableVertexAttribArray(vPosition); }
VAO::VAO() { glGenVertexArraysAPPLE(1, &vao_id); eglGetError(); }
void init() { InitCylinder(4,2,2,20,20); //Texture Binding Stuff glGenTextures(1,&texture); glBindTexture(GL_TEXTURE_2D,texture); glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,texWidth,texHeight,0,GL_RGB,GL_UNSIGNED_BYTE,texImg); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glActiveTexture(GL_TEXTURE0); //Generate Vertex Array Objects GLuint vao; glGenVertexArraysAPPLE(1,&vao); glBindVertexArrayAPPLE(vao); //Generate Vertex Buffer Objects GLuint buffer; glGenBuffers(1,&buffer); glBindBuffer(GL_ARRAY_BUFFER,buffer); glBufferData(GL_ARRAY_BUFFER,sizeof(points)+sizeof(normals)+sizeof(texcoods),NULL,GL_STATIC_DRAW); GLintptr offset = 0; glBufferSubData(GL_ARRAY_BUFFER,0,sizeof(points),points); offset += sizeof(points); glBufferSubData(GL_ARRAY_BUFFER,offset,sizeof(normals),normals); offset += sizeof(normals); glBufferSubData(GL_ARRAY_BUFFER,offset,sizeof(texcoods),texcoods); //Load shader setups GLuint program = InitShader("shaders/vshader_dynTex.glsl","shaders/fshader_dynTex.glsl"); glUseProgram(program); //setup vertex arrays for data transmissions offset = 0; GLuint vPosition = glGetAttribLocation(program,"vPosition"); glEnableVertexAttribArray(vPosition); glVertexAttribPointer(vPosition,4,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(offset)); offset += sizeof(points); GLuint vNormal = glGetAttribLocation(program,"vNormal"); glEnableVertexAttribArray(vNormal); glVertexAttribPointer(vNormal,3,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(offset)); offset += sizeof(normals); GLuint vTexCoods = glGetAttribLocation(program,"vTextureCoods"); glEnableVertexAttribArray(vTexCoods); glVertexAttribPointer(vTexCoods,2,GL_FLOAT,GL_FALSE,0,BUFFER_OFFSET(offset)); glUniform1i(glGetUniformLocation(program,"texture"),0); ModelView = glGetUniformLocation(program,"modelView"); Projection = glGetUniformLocation(program,"projection"); glEnable(GL_DEPTH_TEST); glClearColor(1.0,1.0,1.0,1.0); }
void Terrain::InitDraw(){ // Initialize the data array on CPU m_NTrianglePoints = 3*2*m_res_x*m_res_z; m_TrianglePoints = new Eigen::Vector4f[m_NTrianglePoints]; m_TPointNormals = new Eigen::Vector3f[m_NTrianglePoints]; m_TriangleColors = new Eigen::Vector4f[m_NTrianglePoints]; int box_id; Eigen::Vector4f a,b,c,d; Eigen::Vector3f na,nb,nc,nd; for(int ix = 0; ix < m_res_x; ix++) for(int iz = 0; iz < m_res_z; iz++){ box_id = ix*m_res_z + iz; a.x() = m_dx*ix - 0.5*m_size_x;a.z() = m_dz*iz - 0.5*m_size_z;a.y() = m_height_data[ix*(m_res_z+1) + iz];a.w() = 1.0; b.x() = m_dx*(ix+1) - 0.5*m_size_x;b.z() = m_dz*iz - 0.5*m_size_z;b.y() = m_height_data[(ix+1)*(m_res_z+1) + iz];b.w() = 1.0; c.x() = m_dx*(ix+1) - 0.5*m_size_x;c.z() = m_dz*(iz+1) - 0.5*m_size_z;c.y() = m_height_data[(ix+1)*(m_res_z+1) + iz + 1];c.w() = 1.0; d.x() = m_dx*ix - 0.5*m_size_x;d.z() = m_dz*(iz+1) - 0.5*m_size_z;d.y() = m_height_data[ix*(m_res_z+1) + iz + 1];d.w() = 1.0; m_TrianglePoints[6*box_id] = a; m_TrianglePoints[6*box_id + 1] = b; m_TrianglePoints[6*box_id + 2] = c; m_TrianglePoints[6*box_id + 3] = c; m_TrianglePoints[6*box_id + 4] = d; m_TrianglePoints[6*box_id + 5] = a; na = m_normal_data[ix*(m_res_z+1) + iz]; nb = m_normal_data[(ix+1)*(m_res_z+1) + iz]; nc = m_normal_data[(ix+1)*(m_res_z+1) + iz+1]; nd = m_normal_data[ix*(m_res_z+1) + iz+1]; m_TPointNormals[6*box_id] = na; m_TPointNormals[6*box_id + 1] = nb; m_TPointNormals[6*box_id + 2] = nc; m_TPointNormals[6*box_id + 3] = nc; m_TPointNormals[6*box_id + 4] = nd; m_TPointNormals[6*box_id + 5] = na; for(int ii = 0; ii < 6; ii++) m_TriangleColors[box_id*6+ii] = Eigen::Vector4f(0,0.8,1.0,1.0); } //Create the Vertex Array and Buffers, bind them #ifdef __APPLE__ glGenVertexArraysAPPLE(1, &m_vertexArrayObject); glBindVertexArrayAPPLE(m_vertexArrayObject);//use as current vertex array #else glGenVertexArrays(1, &m_vertexArrayObject); glBindVertexArray(m_vertexArrayObject);//use as current vertex array #endif glGenBuffers(1, &m_vertexBufferObject);//generate buffer for current vertex array glBindBuffer(GL_ARRAY_BUFFER, m_vertexBufferObject); //send the updated data to buffer glBufferData(GL_ARRAY_BUFFER, (sizeof(m_TrianglePoints[0]) + sizeof(m_TriangleColors[0]) + sizeof(m_TPointNormals[0]))*m_NTrianglePoints, NULL, GL_STATIC_DRAW);//send data to current buffer glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(m_TrianglePoints[0])*m_NTrianglePoints, m_TrianglePoints); glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_TrianglePoints[0])*m_NTrianglePoints, sizeof(m_TriangleColors[0])*m_NTrianglePoints, m_TriangleColors); glBufferSubData(GL_ARRAY_BUFFER, sizeof(m_TriangleColors[0])*m_NTrianglePoints+sizeof(m_TrianglePoints[0])*m_NTrianglePoints,sizeof(m_TPointNormals[0])*m_NTrianglePoints, m_TPointNormals); //load and compile shaders on GPU, use current shader program m_shader = Util::InitShader( "vSmoothPhong.vert", "fSmoothPhong.frag" ); glUseProgram(m_shader); GLuint position; GLuint color; GLuint normal; position = glGetAttribLocation( m_shader, "vPosition" ); glEnableVertexAttribArray( position ); glVertexAttribPointer(position, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0)); color = glGetAttribLocation(m_shader, "vColor"); glEnableVertexAttribArray(color); glVertexAttribPointer(color, 4, GL_FLOAT, GL_FALSE,0, BUFFER_OFFSET(sizeof(m_TrianglePoints[0])*m_NTrianglePoints)); normal = glGetAttribLocation(m_shader, "vNormal"); glEnableVertexAttribArray(normal); glVertexAttribPointer(normal, 3, GL_FLOAT, GL_FALSE,0, BUFFER_OFFSET((sizeof(m_TriangleColors[0])+sizeof(m_TrianglePoints[0]))*m_NTrianglePoints)); }
void init() { colorcube(); // Create a checkerboard pattern for ( int i = 0; i < 64; i++ ) { for ( int j = 0; j < 64; j++ ) { GLubyte c = (((i & 0x8) == 0) ^ ((j & 0x8) == 0)) * 255; image[i][j][0] = c; image[i][j][1] = c; image[i][j][2] = c; image2[i][j][0] = c; image2[i][j][1] = 0; image2[i][j][2] = c; } } // Initialize texture objects glGenTextures( 2, textures ); glBindTexture( GL_TEXTURE_2D, textures[0] ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, TextureSize, TextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, image ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glBindTexture( GL_TEXTURE_2D, textures[1] ); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, TextureSize, TextureSize, 0, GL_RGB, GL_UNSIGNED_BYTE, image2 ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST ); glTexParameterf( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST ); glActiveTexture( GL_TEXTURE0 ); glBindTexture( GL_TEXTURE_2D, textures[0] ); // Create a vertex array object GLuint vao; glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); // Create and initialize a buffer object GLuint buffer; glGenBuffers( 1, &buffer ); glBindBuffer( GL_ARRAY_BUFFER, buffer ); glBufferData( GL_ARRAY_BUFFER, sizeof(points) + sizeof(quad_colors) + sizeof(tex_coords), NULL, GL_STATIC_DRAW ); // Specify an offset to keep track of where we're placing data in our // vertex array buffer. We'll use the same technique when we // associate the offsets with vertex attribute pointers. GLintptr offset = 0; glBufferSubData( GL_ARRAY_BUFFER, offset, sizeof(points), points ); offset += sizeof(points); glBufferSubData( GL_ARRAY_BUFFER, offset, sizeof(quad_colors), quad_colors ); offset += sizeof(quad_colors); glBufferSubData( GL_ARRAY_BUFFER, offset, sizeof(tex_coords), tex_coords ); // Load shaders and use the resulting shader program GLuint program = InitShader( "vshader71.glsl", "fshader71.glsl" ); glUseProgram( program ); // set up vertex arrays offset = 0; GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(offset) ); offset += sizeof(points); GLuint vColor = glGetAttribLocation( program, "vColor" ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer( vColor, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(offset) ); offset += sizeof(quad_colors); GLuint vTexCoord = glGetAttribLocation( program, "vTexCoord" ); glEnableVertexAttribArray( vTexCoord ); glVertexAttribPointer( vTexCoord, 2, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(offset) ); // Set the value of the fragment shader texture sampler variable // ("texture") to the the appropriate texture unit. In this case, // zero, for GL_TEXTURE0 which was previously set by calling // glActiveTexture(). glUniform1i( glGetUniformLocation(program, "texture"), 0 ); theta = glGetUniformLocation( program, "theta" ); glEnable( GL_DEPTH_TEST ); glClearColor( 1.0, 1.0, 1.0, 1.0 ); }
void Object::init_buffers( const vec4& lpos, const vec4& l_amb, const vec4& l_diff, const vec4& l_spec, bool load_shader, int rotate){ vector<GLfloat> shins; //build rotation matrix double radians = rotate * M_PI / 180.0; mat4 rotation(cos(radians), 0.0, sin(radians), 0.0, 0.0, 1.0, 0.0, 0.0, -sin(radians), 0.0, cos(radians), 0.0, 0.0, 0.0, 0.0, 1.0); //load vbo array data Load_Model_Data( model_name, rotation, scale_factor, vertices, normals, ambients, diffuses, speculars, shins, vertex_count ); vertices_size = sizeof(vec4)*vertex_count; shininess_size = sizeof(GLfloat)*vertex_count; /*************************************************/ /* Iterate through materials, multiplying the */ /* light material to the material. */ /*************************************************/ for(size_t i=0; i<vertex_count; i++){ ambients[i] *= l_amb; diffuses[i] *= l_diff; speculars[i] *= l_spec; } ///Get width of object double x_min = vertices[0].x; double x_max = vertices[0].x; double y_min = vertices[0].y; double y_max = vertices[0].y; double z_min = vertices[0].z; double z_max = vertices[0].z; for(size_t i=1; i<vertices.size(); i++){ if( vertices[i].x < x_min ) x_min = vertices[i].x; if( vertices[i].x > x_max ) x_max = vertices[i].x; if( vertices[i].y < y_min ) y_min = vertices[i].y; if( vertices[i].y > y_max ) y_max = vertices[i].y; if( vertices[i].z < z_min ) z_min = vertices[i].z; if( vertices[i].z > z_max ) z_max = vertices[i].z; } x_width = x_max - x_min; y_width = y_max - y_min; z_width = z_max - z_min; centroid = vec3( (x_max-x_min)/2.0+x_min, (y_max-y_min)/2.0+y_min, (z_max-z_min)/2.0+z_min); // in case we just want to read the model file if ( !load_shader ) return; /// Initialize Shader // Create a vertex array object #ifdef __APPLE__ glGenVertexArraysAPPLE( 1, &vao ); glBindVertexArrayAPPLE( vao ); #else glGenVertexArrays( 1, &vao ); glBindVertexArray( vao ); #endif // Create and initialize a buffer object glGenBuffers( 1, &vbo ); glBindBuffer( GL_ARRAY_BUFFER, vbo ); glBufferData( GL_ARRAY_BUFFER, 5*vertices_size, NULL, GL_STATIC_DRAW ); glBufferSubData( GL_ARRAY_BUFFER, 0*vertices_size, vertices_size, &vertices[0] ); glBufferSubData( GL_ARRAY_BUFFER, 1*vertices_size, vertices_size, &normals[0] ); glBufferSubData( GL_ARRAY_BUFFER, 2*vertices_size, vertices_size, &ambients[0] ); glBufferSubData( GL_ARRAY_BUFFER, 3*vertices_size, vertices_size, &diffuses[0] ); glBufferSubData( GL_ARRAY_BUFFER, 4*vertices_size, vertices_size, &speculars[0] ); glBufferSubData( GL_ARRAY_BUFFER, 5*vertices_size, shininess_size, &shininess[0] ); //load program glUseProgram( program ); // get ids of and set up attribute variables GLuint vPosition = glGetAttribLocation( program, "vPosition" ); glEnableVertexAttribArray( vPosition ); glVertexAttribPointer( vPosition, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET(0) ); GLuint vNormal = glGetAttribLocation( program, "vNormal" ); glEnableVertexAttribArray( vNormal ); glVertexAttribPointer( vNormal, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET((1*vertices_size))); GLuint vAmbient = glGetAttribLocation( program, "vAmbient" ); glEnableVertexAttribArray( vAmbient ); glVertexAttribPointer( vAmbient, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET((2*vertices_size))); GLuint vDiffuse = glGetAttribLocation( program, "vDiffuse" ); glEnableVertexAttribArray( vDiffuse ); glVertexAttribPointer( vDiffuse, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET((3*vertices_size))); GLuint vSpecular = glGetAttribLocation( program, "vSpecular" ); glEnableVertexAttribArray( vSpecular ); glVertexAttribPointer( vSpecular, 4, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET((4*vertices_size))); GLuint vShiny = glGetAttribLocation( program, "vShiny" ); glEnableVertexAttribArray( vShiny ); glVertexAttribPointer( vShiny, 1, GL_FLOAT, GL_FALSE, 0, BUFFER_OFFSET((5*vertices_size))); // get ids of uniform variables worldview = glGetUniformLocation( program, "worldview" ); projection = glGetUniformLocation( program, "projection" ); light_position = glGetUniformLocation( program, "light_position"); drawmode = glGetUniformLocation( program, "drawmode"); translation_id = glGetUniformLocation( program, "translation"); rotation_id = glGetUniformLocation( program, "rotation" ); translation = vec4(0,0,0,1); }
Track::Track(GLint givenVertexBufferLoc, GLint givenNormalBufferLoc) { setLoader(new ObjLoader()); ObjLoader * myLoaderRef = getLoader(); myLoaderRef -> loadObj(TRACK_PATH, MTL_BASEPATH); // In this OpenGL program, x-z is the horizontal plane. // The following code snippet grabs the x and z coordinates of all the // vertices that are at the bottom of the inner walls of the track. //std::cout << "ListPlot[ { " << std::endl; std::vector<GLfloat> vertices = myLoaderRef->getVertices(); for (int i = 0; i < vertices.size(); i += 3) { if (vertices[i + 1] > 1) continue; //if (i) std::cout << ", "; //std::cout << "{" << vertices[i] << ", " << vertices[i + 2] << "}"; walls.push_back(glm::vec2(vertices[i], vertices[i+2])); } //std::cout << " } ]" << std::endl; glGenBuffers(1, &vertexBuffer); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glBufferData(GL_ARRAY_BUFFER, myLoaderRef -> getVertices().size() * sizeof(GLfloat), myLoaderRef -> getVertices().data(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glGenBuffers(1, &normalBuffer); glBindBuffer(GL_ARRAY_BUFFER, normalBuffer); glBufferData(GL_ARRAY_BUFFER, myLoaderRef -> getNormals().size() * sizeof(GLfloat), myLoaderRef -> getNormals().data(), GL_STATIC_DRAW); glBindBuffer(GL_ARRAY_BUFFER, 0); glGenBuffers(1, &indexBuffer); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); glBufferData(GL_ELEMENT_ARRAY_BUFFER, myLoaderRef -> getIndices().size() * sizeof(GLuint), myLoaderRef -> getIndices().data(), GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); vertexCount = (unsigned int) myLoaderRef -> getIndices().size(); // setup initial model matrix scaleMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(0.0f, -1.0f, 0.0f)) * glm::mat4(1.0f); setModelMatrix(scaleMatrix); // wrap states using vao glGenVertexArraysAPPLE(1, &vertexArrayObjectHandle); glBindVertexArrayAPPLE(vertexArrayObjectHandle); // bind vertex array glEnableVertexAttribArray(givenVertexBufferLoc); glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer); glVertexAttribPointer(givenVertexBufferLoc, 3, // to simplify program, we always use triangles GL_FLOAT, // type of elements in vertex buffer is GLfloat GL_FALSE, // not normalized 0, // to simplify program, we keep each object in a homogeneous buffer 0); glEnableVertexAttribArray(givenNormalBufferLoc); glBindBuffer(GL_ARRAY_BUFFER, normalBuffer); glVertexAttribPointer(givenNormalBufferLoc, 3, GL_FLOAT, GL_FALSE, 0, 0); // bind index array glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexBuffer); // finished: unbind vao to clear state glBindVertexArrayAPPLE(0); }