I’m a begginer with glsl.I tried to load and use shaders in my program.According to gDEbugger,my shaders have been compiled successfully and the program has been linked successfully too.
But when I use a VBO to render something, an OPENGL error occurred,
Function Name: glDrawArrays
Error code: GL_INVALID_OPERATION.
Error description:
The specified operation is not allowed in the current state. The offending function is ignored, having no side effect other than to set the error flag.
Here are my source code:
glUseProgram(p);
glEnableClientState(GL_VERTEX_ARRAY);
//VBO
GLuint iVertexBuffer = 0;
glGenBuffers(1, &iVertexBuffer);
glBindBuffer(GL_ARRAY_BUFFER, iVertexBuffer);
length=length*sizeof(VertexArray);
glBufferData(GL_ARRAY_BUFFER, length,VertexArray, GL_STATIC_DRAW);
delete [] VertexArray;
glBindBuffer(GL_ARRAY_BUFFER, iVertexBuffer);
glVertexPointer( 2, GL_INT, 0, (char *) NULL );
length=imageInUseSize[1]*2+1;
glDrawArrays(GL_TRIANGLE_FAN,0,length);
glUseProgram(0);
int length=imageInUseSize[1]*4+2;
int *VertexArray=new int[length];
The length of the vertexarray is imageInUseSize[1]*4+2,and the number of vertices is imageInUseSize[1]*2+1.
IS it wrong?
And also the using of uniforms is an invalid operation?
Sorry, you simply need to post more code (use the code tags!) or debug that more thoroughly.
For example things not visible inside your code snippet:
length=length*sizeof(VertexArray);
What is length before this point?
The sizeof() on the array variable already returns the total number of bytes in that array. So unless length is 1 before, this accesses the array out of bounds in glBufferData (=> could crash).
glUniform only works on the currently bound program (obviously because it has no program object as parameter), you must issue glUniform calls AFTER glUseProgram(yourprogram).
PACK_ALIGNMENT is related to pixel store, not vertex arrays.
And what have display lists to do with any of the above?
Other things to try: Does the code above run if you use standard vertex arrays and no VBO?
the length before this point is int length=imageInUseSize[1]*4+2
The display list has nothing with my code.I just tried to extent other people’s class library.And I find an error(invalid operation) when it comes to glcalllist,but I think it would have no side effect,is that right?
Instead of
length = length * sizeof(VertexArray);
use
length = sizeof(VertexArray);
or
length *= sizeof(VertexArray[0]); // a float
or
length *= sizeof(float);
Thank you! I traced my program.
float *VertexArray=new float[ 1310]
glBufferData(GL_ARRAY_BUFFER, 5240,VertexArray, GL_STATIC_DRAW);
glDrawArrays(GL_TRIANGLE_FAN,0,655)
Maybe it’s not because the length of arrays.
I tried vertex at a time,still,when it came to glEnd ,invalid operation.I’m so confused. Maybe it’s because of glcalllist above.
I seemed to understand what’s wrong,but I don’t know how to solve the problem.I found my codes are in the display list, the display list is an invalid operation ,So whatever I draw would be wrong