LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: Cornix on April 10, 2014, 21:25:27

Title: glEnd() generates invalid operation error
Post by: Cornix on April 10, 2014, 21:25:27
Hi there,

I have a strange problem.
This code is generating an InvalidOperation error:
GL11.glBegin(GL11.GL_QUADS);
GLError.throwIfNecessary(this, "glBegin(GL11.GL_QUADS)");

GL11.glColor4f(0, 0, 1, 1);
GLError.throwIfNecessary(this, "glColor4f(0, 0, 1, 1)");
GL11.glVertex4f(0, 0, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(0, 0, 0, 1)");

GL11.glColor4f(0, 1, 0, 1);
GLError.throwIfNecessary(this, "glColor4f(0, 1, 0, 1)");
GL11.glVertex4f(0, 64, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(0, 64, 0, 1)");

GL11.glColor4f(1, 1, 0, 1);
GLError.throwIfNecessary(this, "glColor4f(1, 1, 0, 1)");
GL11.glVertex4f(64, 64, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(64, 64, 0, 1)");

GL11.glColor4f(1, 0, 0, 1);
GLError.throwIfNecessary(this, "glColor4f(1, 0, 0, 1)");
GL11.glVertex4f(64, 0, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(64, 0, 0, 1)");

GL11.glEnd();
GLError.throwIfNecessary(this, "glEnd");

The exception is being thrown after the glEnd();.

However, this code is NOT generating an error and drawing just fine:
GL11.glBegin(GL11.GL_QUADS);
GLError.throwIfNecessary(this, "glBegin(GL11.GL_QUADS)");

GL11.glColor4f(0, 0, 1, 1);
GLError.throwIfNecessary(this, "glColor4f(0, 0, 1, 1)");
GL11.glVertex4f(0, 0, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(0, 0, 0, 1)");

GL11.glColor4f(0, 1, 0, 1);
GLError.throwIfNecessary(this, "glColor4f(0, 1, 0, 1)");
GL11.glVertex4f(0, 64, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(0, 64, 0, 1)");

GL11.glColor4f(1, 1, 0, 1);
GLError.throwIfNecessary(this, "glColor4f(1, 1, 0, 1)");
GL11.glVertex4f(64, 64, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(64, 64, 0, 1)");

GL11.glColor4f(1, 0, 0, 1);
GLError.throwIfNecessary(this, "glColor4f(1, 0, 0, 1)");
GL11.glVertex4f(64, 0, 0, 1);
GLError.throwIfNecessary(this, "glVertex4f(64, 0, 0, 1)");

//GL11.glEnd();
//GLError.throwIfNecessary(this, "glEnd");

But I would guess that this is supposed to throw an error.

I am quite baffled why this is. I dont have any other rendering commands in my code.

I would appreciate any help I could get.
Title: Re: glEnd() generates invalid operation error
Post by: quew8 on April 11, 2014, 22:14:44
I agree with you. The first one should not cause an error and the second should.

I know this post doesn't help but if it were me I'd be wondering if I was sane or not. So just letting you know you're at least as sane as I am.
Title: Re: glEnd() generates invalid operation error
Post by: Morin on April 12, 2014, 12:57:13
Quote from: Cornix on April 10, 2014, 21:25:27
Hi there,

I have a strange problem.
This code is generating an InvalidOperation error: (...)

I think I remember something about GL_QUADS not being supported anymore on all OpenGL implementations. Could you try GL_TRIANGLES instead to see if that throws an error as well?

I changed my own code to GL_TRIANGLES some time ago and I think it was because of that, but it's too long ago to remember.

Quote from: quew8 on April 11, 2014, 22:14:44
I agree with you. The first one should not cause an error and the second should.

The second one doesn't have a glEnd(), so depending on the implementation the commands do not get executed at all. If no commands get executed, no errors gets thrown.
Title: Re: glEnd() generates invalid operation error
Post by: quew8 on April 12, 2014, 13:21:37
Quote from: Morin on April 12, 2014, 12:57:13
Quote from: quew8 on April 11, 2014, 22:14:44
I agree with you. The first one should not cause an error and the second should.

The second one doesn't have a glEnd(), so depending on the implementation the commands do not get executed at all. If no commands get executed, no errors gets thrown.


If you read this part of the docs:
Quote
GL_INVALID_OPERATION is generated if glBegin is executed between a glBegin and the corresponding execution of glEnd.
ie if glBegin is executed twice in a row.

Which is essentially what should happen in the second example.
Title: Re: glEnd() generates invalid operation error
Post by: Cornix on April 12, 2014, 13:30:17
Yes, but the second example does not generate errors and everything gets drawn fine.
Thats why I am so confused. It is as if I have an additional glEnd() somewhere, but there is none. I only use a single glEnd() in the entire program.