Created
December 5, 2012 13:06
-
-
Save Lewuathe/4215364 to your computer and use it in GitHub Desktop.
The template of OpenGL setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate Vertex array object | |
glGenVertexArraysOES(1, &_triangleArray); | |
// Binding VAO | |
glBindVertexArrayOES(_triangleArray); | |
// Generate Vertex buffer object | |
glGenBuffers(1, &_triangleBuffer); | |
// Binding VBO | |
glBindBuffer(GL_ARRAY_BUFFER, _triangleBuffer); | |
// Send buffer data | |
glBufferData(GL_ARRAY_BUFFER, sizeof(gTriangleData), gTriangleData, GL_STATIC_DRAW); | |
glEnableVertexAttribArray(GLKVertexAttribPosition); | |
// glVertexAttribPointer(GLuint index, num of vertices, type of points, ?, num of bytes in one vertex, start pffset); | |
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(0)); | |
glEnableVertexAttribArray(GLKVertexAttribNormal); | |
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, 24, BUFFER_OFFSET(12)); | |
glBindBuffer(GL_ARRAY_BUFFER, 0); | |
glBindVertexArrayOES(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* With GLKit, it is not necessary to reuse buffer object. | |
* You only need to bind VAO. | |
*/ | |
glBindVertexArrayOES(_triangleArray); | |
// Use compiled shader | |
glUseProgram(_program); | |
glUniformMatrix4fv(uniforms[UNIFORM_MODELVIEWPROJECTION_MATRIX], 1, 0, _modelViewProjectionMatrix.m); | |
glUniformMatrix3fv(uniforms[UNIFORM_NORMAL_MATRIX], 1, 0, _normalMatrix.m); | |
glDrawArrays(GL_TRIANGLES, 0, 3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment