Skip to content

Instantly share code, notes, and snippets.

@PoisonousJohn
Created December 19, 2012 19:16
Show Gist options
  • Save PoisonousJohn/4339608 to your computer and use it in GitHub Desktop.
Save PoisonousJohn/4339608 to your computer and use it in GitHub Desktop.
If I pass Vertex structure to shader attribute then it works, but if I'm passing one dimensional array, then it doesn't work
typedef struct {
float Position[3];
float Color[4];
} Vertex;
const Vertex Vertices[] = {
{{1, -1, -7}, {1, 0, 0, 1}},
{{1, 1, -7}, {0, 1, 0, 1}},
{{-1, 1, -7}, {0, 0, 1, 1}},
{{-1, -1, -7}, {0, 0, 0, 1}}
};
...
const float cylinderVertices[] = {
0.8, -0.8, -7,
0.8, 0.8, -7,
-0.8, -0.8, -7,
-0.8, 0.8, -7,
};
GLuint vertexBuffer;
glGenBuffers(1, &vertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer);
glBufferData(GL_ARRAY_BUFFER, 4, cylinderVertices, GL_STATIC_DRAW);
...
glVertexAttribPointer(_positionSlot, 3, GL_FLOAT, GL_FALSE, 4, 0);
glDrawArrays(GL_LINE_STRIP, 0, 4);
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment