OpenGL 3/4 glVertexAttribPointer stride and offset miscalculation

前端 未结 2 701
说谎
说谎 2021-02-01 07:55

I am having a problem getting my vertex array pointed to properly:

const float vertices[] = {
/* position */ 0.75f, 0.75f, 0.0f, 1.0f, /* color */ 1         


        
2条回答
  •  臣服心动
    2021-02-01 08:14

    Stride and offset are specified in bytes. You are using an interleaved vertex array with position and color both as 4 floats. To get from th i-th element in a particular attribute array to the next one, there is the distance of 8 floats, so stride should be 8*sizeof(GLfloat). The offset is the byte position of the first element of each attribute array in the buffer, so in your example for position it is 0, and for color, it is 4*sizeof(GLfloat)

提交回复
热议问题