void initHeightMap () { num_hm_elements = hm.sizeOfTriangleVertices()*2; vec4 hm_elements [num_hm_elements]; hm.flattenTriangles (hm_elements); // num_hm_elements = hm.getSize () * 2; // vec4 hm_elements [num_hm_elements]; // hm.flatten (hm_elements); // indices = new unsigned [ hm.sizeOfTriStripIndices () ]; // hm.flattenTriStripIndices (indices); glGenVertexArrays(1, &hm_vao); glBindVertexArray(hm_vao); GLuint buffer; glGenBuffers (1, &buffer); glBindBuffer (GL_ARRAY_BUFFER, buffer); glBufferData (GL_ARRAY_BUFFER, num_hm_elements*sizeof(vec4), hm_elements, GL_STATIC_DRAW); glEnableVertexAttribArray ( vPosition ); glVertexAttribPointer ( vPosition, 4, GL_FLOAT, GL_FALSE, sizeof(vec4)*2, BUFFER_OFFSET(0) ); glEnableVertexAttribArray( vColor ); glVertexAttribPointer ( vColor, 4, GL_FLOAT, GL_FALSE, sizeof(vec4)*2, BUFFER_OFFSET(sizeof (vec4))); }
void displayTerrain () { glUniform1i (solidColor, 0); glUniformMatrix4fv (vMvp, 1, GL_TRUE, projectionView); glBindVertexArray( hm_vao ); glPrimitiveRestartIndex (PRIMITIVE_RESTART); glDrawArrays( GL_TRIANGLES, 0, hm.sizeOfTriangleVertices () ); //glDrawArrays( GL_LINE_STRIP, 0, hm.getSize () ); //glDrawElements ( GL_TRIANGLE_STRIP, hm.sizeOfTriStripIndices (), GL_UNSIGNED_INT, indices); }