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

Winapi c++: DialogBox hangs when breaking a loop -

vb.net - Font adding using PDFsharp -

javascript - jQuery iScroll clickable list elements while retaining scroll? -