attributes - OpenGL 3/4 glVertexAttribPointer stride and offset miscalculation -


i having problem getting vertex array pointed properly:

const float vertices[] = { /* position */ 0.75f, 0.75f, 0.0f, 1.0f, /* color */ 1.0f, 0.0f, 0.0f, 1.0f, /* position */ 0.75f, -0.75f, 0.0f, 1.0f, /* color */ 0.0f, 1.0f, 0.0f, 1.0f, /* position */ -0.75f, -0.75f, 0.0f, 1.0f, /* color */ 0.0f, 0.0f, 1.0f, 1.0f, };  ...  glbindbuffer(gl_array_buffer, vertexbufferobject); glenablevertexattribarray(0); glenablevertexattribarray(1); glvertexattribpointer(0, 4, gl_float, gl_false, 0, 0); glvertexattribpointer(1, 4, gl_float, gl_false, 0, (void*)16);  gldrawarrays(gl_triangles, 0, 3);  gldisablevertexattribarray(0); gldisablevertexattribarray(1); 

i not understand how stride , offset work. correct way of going using glvertexattribpointer() in situation?

stride , offset specified in bytes. using interleaved vertex array position , color both 4 floats. th i-th element in particular attribute array next one, there distance of 8 floats, stride should 8*sizeof(glfloat). offset byte position of first element of each attribute array in buffer, in example position 0, , color, 4*sizeof(glfloat)


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -