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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -