const GLuint ATTRIBUTE_LOCATION_POSITIONS = 0; const GLuint ATTRIBUTE_LOCATION_TEXTUREUV = 1; const GLuint ATTRIBUTE_LOCATION_NORMALS = 2; // Bind shader program, uniforms and textures // ... // Bind the vertex buffer glBindBuffer( GL_ARRAY_BUFFER, vertex_buffer_object ); // Set the vertex attributes glEnableVertexAttribArray( ATTRIBUTE_LOCATION_POSITIONS ); glVertexAttribPointer( ATTRIBUTE_LOCATION_POSITIONS, 3, GL_FLOAT, GL_FALSE, 32, 0 ); glEnableVertexAttribArray( ATTRIBUTE_LOCATION_TEXTUREUV ); glVertexAttribPointer( ATTRIBUTE_LOCATION_TEXTUREUV, 2, GL_FLOAT, GL_FALSE, 32, 12 ); glEnableVertexAttribArray( ATTRIBUTE_LOCATION_NORMALS ); glVertexAttribPointer( ATTRIBUTE_LOCATION_NORMALS, 3, GL_FLOAT, GL_FALSE, 32, 20 ); // Draw elements glDrawElements( GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0 );
const GLuint ATTRIBUTE_LOCATION_POSITIONS = 0; const GLuint ATTRIBUTE_LOCATION_TEXTUREUV = 1; const GLuint ATTRIBUTE_LOCATION_NORMALS = 2; // Bind the vertex buffer object glBindBuffer( GL_ARRAY_BUFFER, vertex_buffer_object ); // Create a VAO GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao ); // Set the vertex attributes as usual glEnableVertexAttribArray( ATTRIBUTE_LOCATION_POSITIONS ); glVertexAttribPointer( ATTRIBUTE_LOCATION_POSITIONS, 3, GL_FLOAT, GL_FALSE, 32, 0 ); glEnableVertexAttribArray( ATTRIBUTE_LOCATION_TEXTUREUV ); glVertexAttribPointer( ATTRIBUTE_LOCATION_TEXTUREUV, 2, GL_FLOAT, GL_FALSE, 32, 12 ); glEnableVertexAttribArray( ATTRIBUTE_LOCATION_NORMALS ); glVertexAttribPointer( ATTRIBUTE_LOCATION_NORMALS, 3, GL_FLOAT, GL_FALSE, 32, 20 ); // Unbind the VAO to avoid accidentally overwriting the state // Skip this if you are confident your code will not do so glBindVertexArray( 0 );
// Create a vertex array object GLuint vao; glGenVertexArrays( 1, &vao ); glBindVertexArray( vao );
// Bind shader program, uniforms and textures // ... // Bind Vertex Array Object glBindVertexArray( vao ); // Draw elements glDrawElements( GL_TRIANGLES, count, GL_UNSIGNED_SHORT, 0 );
attribute vec4 vertexPosition; attribute vec2 vertexUV; uniform mat4 matWorldViewProjection; varying vec2 outTexCoord; void main() { outTexCoord = vertexUV; gl_Position = matWorldViewProjection * vertexPosition; }
struct Vertex { Vector4 Position; Vector2 TexCoords; };
attribute vec4 vertexPosition; attribute vec2 vertexUV;
GLint handleVertexPos = glGetAttribLocation( myShaderProgram, "vertexPosition" ); glVertexAttribPointer( handleVertexPos, 4, GL_FLOAT, GL_FALSE, 0, 0 ); GLint handleVertexUV = glGetAttribLocation( myShaderProgram, "vertexUV" ); glVertexAttribPointer( handleVertexUV, 2, GL_FLOAT, GL_FALSE, 0, 0 );
layout(location = 0) in vec4 vertexPosition; layout(location = 1) in vec2 vertexUV;
#version 300 es
#version 300 es layout(location = 0) in vec4 vertexPosition; layout(location = 1) in vec2 vertexUV; uniform mat4 matWorldViewProjection; out vec2 outTexCoord; void main() { outTexCoord = vertexUV; gl_Position = matWorldViewProjection * vertexPosition; }
const int ATTRIB_POS = 0; const int ATTRIB_UV = 1; glVertexAttribPointer( ATTRIB_POS, 4, GL_FLOAT, GL_FALSE, 0, 0 ); glVertexAttribPointer( ATTRIB_UV, 2, GL_FLOAT, GL_FALSE, 0, 0 );