View Full Version : glVertex3f throws GL_INVALID_OPERATION error?

Folkert van Heusden
03-02-2012, 11:00 AM

I have some trivial code which displays a line-graph against a quad with a background-texture. The line is drawn using glDrawElements() and the background-quad-with-texture like this:

// this is the end of the line-drawer so that you can see
// that it is terminated as it should.
// EC() is a #define which calls function ec() with __FILE__ and __LINE__ as parameters. this then checks if glGetError returns an error code
// double h_width=320, h_height=200;
glDisableClientState(GL_COLOR_ARRAY); EC();
glDisableClientState(GL_VERTEX_ARRAY); EC();

glBindBuffer(GL_ARRAY_BUFFER, 0); EC();

// start of quad with texture
glEnable(GL_TEXTURE_2D); EC();
glBindTexture(GL_TEXTURE_2D, texture); EC();

glBegin(GL_QUADS); EC();
glTexCoord2f(0.0, 0.0); EC();
glVertex3f(-h_width, h_height, 0.0); EC();
glTexCoord2f(1.0, 0.0); EC();
glVertex3f(h_width, h_height, 0.0); EC();
glTexCoord2f(1.0, 1.0); EC();
glVertex3f(h_width, -h_height, 0.0); EC();
glTexCoord2f(0.0, 1.0); EC();
// ***** THE FOLLOWING glVertex3f CALL FAILS
// ***** WITH ERROR 0x502:
glVertex3f(-h_width, -h_height, 0.0); EC();
glEnd(); EC();
glDisable(GL_TEXTURE_2D); EC();

Anyone an idea what might be going wrong here?
The strange part is that occasionally works.

03-02-2012, 12:39 PM
It is an invalid operation to call glGetError() between glBegin() and glEnd(). So I guess the error comes from the call to EC() itself rather than the call to glVertex.

Folkert van Heusden
03-02-2012, 12:58 PM
Hmmm ok. Then I still wonder why it is not showing any texture at all.
Well, occasionally.
Occasionally for this one graphic.

Other "objects" always have their texture applied.

Folkert van Heusden
03-02-2012, 01:29 PM
never mind, fixed it: some other bug was biting me.

03-02-2012, 01:45 PM
It would help others if you posted the solution to your problem.

Folkert van Heusden
03-03-2012, 05:51 AM
Well, the problem was not opengl-related: I gave the aspect_ratio instead of the expected height to the draw-routine. So that would give a very tiny image.