Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glEnableVertexAttribArray Produces "Invalid Value" - OpenGL 3.1

  1. #1
    Intern Contributor
    Join Date
    Apr 2014
    Posts
    67

    glEnableVertexAttribArray Produces "Invalid Value" - OpenGL 3.1

    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.

    Code :
    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);
    	}
    }
    Last edited by tmason; 05-14-2014 at 11:35 AM. Reason: Wrong tag...

  2. #2
    Intern Contributor
    Join Date
    Apr 2014
    Posts
    67
    Fixed, I was using the wrong numbers/variables for glVertexAttribPointer...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •