-
invalid operation after glUseProgram
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);
Thank you in advance.
-
Senior Member
OpenGL Guru
Re: invalid operation after glUseProgram
First, avoid GL_INT vertex array data, that might not be accelerated. Use GL_FLOAT.
There are a little too many "length" variables with different meanings inside that snippet to know what's going on.
Is the length=imageInUseSize[1]*2+1; matching the number of vertices you put into the draw buffer earlier with length=length*sizeof(VertexArray);
Are all other attribute arrays disabled?
-
Re: invalid operation after glUseProgram
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?
GLint loc1,loc2,loc3,loc4,loc5,loc6,loc7,loc8,loc9,loc10 ,loc11,loc12,loc13,loc14,loc15;
loc1 = glGetUniformLocation(p,"centerscale");
glUniform1f(loc1,centerScale);
loc2=glGetUniformLocation(p,"offset");
glUniform2f(loc2,offsetX,offsetY);
loc3=glGetUniformLocation(p,"imageViewportSize");
glUniform2f(loc3,static_cast<float>(imageViewportS ize[0]),
static_cast<float>(imageViewportSize[1]));
-
Re: invalid operation after glUseProgram
I'm sure all the other array attributes are disabled.
GL_LIST_MODE is GL_COMPILE, does it matter?
light,blend,texture1d,GL_PACK_ALIGNMENT are true
-
Senior Member
OpenGL Guru
Re: invalid operation after glUseProgram
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?
-
Re: invalid operation after glUseProgram
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?
I have tried just vertex array,failed too
-
Re: invalid operation after glUseProgram
Thank you, Relic! Finally find my problem, before drawing something ,I should give the uniforms.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules