PDA

View Full Version : glEnableVertexAttribArray Produces "Invalid Value" - OpenGL 3.1



tmason
05-14-2014, 11:35 AM
Hello,

I guess I have a weird problem which I am not sure how to fix. This code seems to have worked before but now I get a blank screen.

I get an "invalid value" right after all of my glEnableVertexAttribArray function calls.

Any idea why that might be?

Thank you for your time.



void LoadIntoOpenGL() {

GLenum errCode;
const GLubyte *errString;

if (AssociatedItem < 1) {
glGenVertexArrays(1, &Pointer_VAO);
glBindVertexArray(Pointer_VAO);

// Create Vertex Buffer Object
glGenBuffers(1, &Vertex_VBO);

if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}

// Save vertex attributes into GPU
glBindBuffer(GL_ARRAY_BUFFER, Vertex_VBO);
if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}
glBufferData(GL_ARRAY_BUFFER, TotalVertexCount * Vertex_Stride * sizeof(GLfloat), &AllVertices[0], GL_STATIC_DRAW);
if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}
glEnableVertexAttribArray(Vertex_VBO);
if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}

glVertexAttribPointer(Vertex_VBO, Vertex_Stride, GL_FLOAT, GL_FALSE, 0, 0);

if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}

delete[] Vertices;

if (HasNormals)
{
glGenBuffers(1, &Normal_VBO);
glBindBuffer(GL_ARRAY_BUFFER, Normal_VBO);
glBufferData(GL_ARRAY_BUFFER, TotalVertexCount * Normal_Stride * sizeof(GLfloat), &AllNormals[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(Normal_VBO);
glVertexAttribPointer(Normal_VBO, Normal_Stride, GL_FLOAT, GL_FALSE, 0, 0);

if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}

delete[] Normals;
}

if (HasUVs)
{
glGenBuffers(1, &UV_VBO);
glBindBuffer(GL_ARRAY_BUFFER, UV_VBO);
glBufferData(GL_ARRAY_BUFFER, TotalVertexCount * UV_Stride * sizeof(GLfloat), &AllUVs[0], GL_STATIC_DRAW);
glEnableVertexAttribArray(UV_VBO);
glVertexAttribPointer(UV_VBO, UV_Stride, GL_FLOAT, GL_FALSE, 0, 0);

if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}

delete[] UVs;
}

glGenBuffers(1, &Index_VBO);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Index_VBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, TotalPolygonCount * Triangle_Vertex_Count * sizeof(GLuint), &ALLIndices[0], GL_STATIC_DRAW);

if ((errCode = glGetError()) != GL_NO_ERROR) {
errString = gluErrorString(errCode);
fprintf(stderr, "OpenGL Error: %s\n", errString);
}

delete[] Indices;
glBindVertexArray(0);
}
}

tmason
05-14-2014, 01:04 PM
Fixed, I was using the wrong numbers/variables for glVertexAttribPointer...