Reputation: 2593
i have been trying to use glVertexAttribP with GL_UNSIGNED_INT_2_10_10_10_REV but stuck up at some point.
here is my code
GLuint red=0,green=511,blue=511,alpha=3;
GLuint val = 0;
val = val | (alpha << 30);
val = val | (blue << 20);
val = val | (green << 10);
val = val | (red << 0);
GLfloat vertices[]={-0.9f, -0.9f, 0.0f,1.0f,
-0.9f, 0.6f, 0.0f,1.0f,
0.6f,0.6f,0.0f,1.0f,
0.6f,-0.9f,0.0f,1.0f};
GLuint test_data[]={val,val,val,val};
glGenBuffers(1, &BufferId);
glBindBuffer(GL_ARRAY_BUFFER, BufferId);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
glEnableVertexAttribArray(glGetAttribLocation(shader_data.psId,"position"));
glVertexAttribPointer(glGetAttribLocation(shader_data.psId,"position"),4,GL_FLOAT,GL_FALSE, 0,0);
glGenBuffers(1, &BufferId1);
glBindBuffer(GL_ARRAY_BUFFER, BufferId1);
glBufferData(GL_ARRAY_BUFFER, sizeof(test_data), test_data, GL_STATIC_DRAW);
glEnableVertexAttribArray(glGetAttribLocation(shader_data.psId,"color"));
//glVertexAttribPointer(glGetAttribLocation(shader_data.psId,"color"), 4,GL_INT_2_10_10_10_REV,GL_TRUE, 0,0);
glVertexAttribP4uiv(glGetAttribLocation(shader_data.psId,"color"),GL_UNSIGNED_INT_2_10_10_10_REV ,GL_TRUE,0);
glDrawArrays(GL_TRIANGLE_FAN,0,4);
it gives Access violation at glDraw call. code works fine with glVertexAttribPointer. what am i missing here?
Upvotes: 0
Views: 976
Reputation: 474366
glEnableVertexAttribArray(glGetAttribLocation(shader_data.psId,"color"));
This tells OpenGL that you're using an array as the source for your attribute data. But you're not. Hence the crash: OpenGL will try to access an array that doesn't exist.
Disable the array instead of enabling it.
Upvotes: 2
Reputation: 4712
Are you sure sizeof(vertices) and sizeof(test_data) gives you the correct size?
I'm wondering if it gives you the size of the pointer instead of the size of the content.
It might also be a scope problem.
Upvotes: 0