PDA

View Full Version : Error:Multiple triangles inside one glBegin-glEnd



Oliver Demetz
06-18-2009, 01:07 AM
Hi, I've got a strange problem:
I am rendering a bunch of triangles.
If I put each triangle in its own glBegin()-glEnd()-block, no error occurs:


foreach(Triangle* t, triangles)
{
t->glRender();
}
//...
void Triangle::glRender()
{
glBegin(GL_TRIANGLES);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, _c1->p1xNormalized()*0.75f, 1.0f-_c1->p1yNormalized());
qt_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, _c1->p1xNormalized()*0.75f, 1.0f-_c1->p1yNormalized());
glVertex3f(_c1->p2x(), _c1->p2y(),0);

qt_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, _c2->p1xNormalized()*0.75f, 1.0f-_c2->p1yNormalized());
qt_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, _c2->p1xNormalized()*0.75f, 1.0f-_c2->p1yNormalized());
glVertex3f(_c2->p2x(), _c2->p2y(),0);

qt_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, _c3->p1xNormalized()*0.75f, 1.0f-_c3->p1yNormalized());
qt_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, _c3->p1xNormalized()*0.75f, 1.0f-_c3->p1yNormalized());
glVertex3f(_c3->p2x(), _c3->p2y(),0);
glEnd();
}

But what should be more efficient is to only have one glBegin()-End() like that:


glBegin(GL_TRIANGLES);
foreach(Triangle* t, triangles)
{
t->glRender();
}
glEnd();
//...
void Triangle::glRender()
{
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, _c1->p1xNormalized()*0.75f, 1.0f-_c1->p1yNormalized());
qt_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, _c1->p1xNormalized()*0.75f, 1.0f-_c1->p1yNormalized());
glVertex3f(_c1->p2x(), _c1->p2y(),0);

qt_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, _c2->p1xNormalized()*0.75f, 1.0f-_c2->p1yNormalized());
qt_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, _c2->p1xNormalized()*0.75f, 1.0f-_c2->p1yNormalized());
glVertex3f(_c2->p2x(), _c2->p2y(),0);

qt_glMultiTexCoord2fARB(GL_TEXTURE0_ARB, _c3->p1xNormalized()*0.75f, 1.0f-_c3->p1yNormalized());
qt_glMultiTexCoord2fARB(GL_TEXTURE1_ARB, _c3->p1xNormalized()*0.75f, 1.0f-_c3->p1yNormalized());
glVertex3f(_c3->p2x(), _c3->p2y(),0);
}

The error that I am complaining about now is as follows:
Using the second implementation, glGetError returns only once after the first run of this code a GL_INVALID_OPERATION!!!
Again: this INVALID_OPERATION is only thrown once (per process lifecycle). But also the displayed stuff looks correct. I do not want to deploy code that throws an error, can you please help me?
I made sure that no texture is uninitialized or empty, also I checked that a multiple of 3 vertecies are handed over to the gl-system. Also glGetError is *not* called withing the glBegin-End block, it is the first statement after glEnd().

Thanks in advance,
Best regards,
Oliver

Abdallah DIB
06-18-2009, 02:07 AM
if u are sure that all u have do it is correct then that means that the GL_INVALID_OPERATION comes from another part of ur code . try to call the glGetError befor drawing ur triangles .

Oliver Demetz
06-18-2009, 02:36 AM
Hi,
I did that!
Each and every gl*-statement is followed by a glGetError()-test.
What I do not understand is that the problem only occurs after the *first* run through the foreach-loop. All paint-events after the first one run without error.
Here is a debug-log (GLintercept) of the interesting rendering from above:


glMatrixMode(GL_MODELVIEW)
glGetError()=GL_NO_ERROR
glEnable(GL_BLEND)
glGetError()=GL_NO_ERROR
glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA)
glGetError()=GL_NO_ERROR
glColor4f(1.000000,1.000000,1.000000,1.000000)
glGetError()=GL_NO_ERROR
glMatrixMode(GL_COLOR)
glPushMatrix()
glLoadMatrixf([1.000000,0.000000,0.000000,0.000000,0.000000,1.000 000,0.000000,0.000000,0.000000,0.000000,1.000000,0 .000000,0.000000,0.000000,0.000000,1.000000])
glMatrixMode(GL_MODELVIEW)
glGenTextures(1,0x5fda4b4)
glBindTexture(GL_TEXTURE_2D,3)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,9729.000000)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,9729.000000)
glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,1024,1024,0,G L_RGBA,GL_UNSIGNED_BYTE,0x6fd0020)
glMatrixMode(GL_COLOR)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glGetError()=GL_NO_ERROR
glGenTextures(1,0x5fda4b8)
glBindTexture(GL_TEXTURE_2D,4)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,9729.000000)
glTexParameterf(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,9729.000000)
glTexImage2D(GL_TEXTURE_2D,0,GL_ALPHA,1024,1024,0, GL_ALPHA,GL_UNSIGNED_BYTE,0x6ec0020)
glGetError()=GL_NO_ERROR
glActiveTextureARB(GL_TEXTURE0)
glGetError()=GL_NO_ERROR
glEnable(GL_TEXTURE_2D)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_2D,3)
glGetError()=GL_NO_ERROR
glTexEnvi(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_MO DULATE)
glGetError()=GL_NO_ERROR
glActiveTextureARB(GL_TEXTURE1)
glGetError()=GL_NO_ERROR
glEnable(GL_TEXTURE_2D)
glGetError()=GL_NO_ERROR
glBindTexture(GL_TEXTURE_2D,4)
glGetError()=GL_NO_ERROR
glGetError()=GL_NO_ERROR
glBegin(GL_TRIANGLES)
wglGetProcAddress("glMultiTexCoord2fARB")=0x1002a170
glMultiTexCoord2fARB(GL_TEXTURE0,0.750000,1.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.750000,1.000000 )
glVertex3f(768.000000,0.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.000000,1.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.000000,1.000000 )
glVertex3f(0.000000,0.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.371094,0.456055 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.371094,0.456055 )
glVertex3f(380.000000,557.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.371094,0.456055 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.371094,0.456055 )
glVertex3f(380.000000,557.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.000000,1.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.000000,1.000000 )
glVertex3f(0.000000,0.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.000000,0.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.000000,0.000000 )
glVertex3f(0.000000,1024.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.750000,1.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.750000,1.000000 )
glVertex3f(768.000000,0.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.371094,0.456055 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.371094,0.456055 )
glVertex3f(380.000000,557.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.750000,0.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.750000,0.000000 )
glVertex3f(768.000000,1024.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.371094,0.456055 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.371094,0.456055 )
glVertex3f(380.000000,557.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.000000,0.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.000000,0.000000 )
glVertex3f(0.000000,1024.000000,0.000000)
glMultiTexCoord2fARB(GL_TEXTURE0,0.750000,0.000000 )
glMultiTexCoord2fARB(GL_TEXTURE1,0.750000,0.000000 )
glVertex3f(768.000000,1024.000000,0.000000)
glEnd() glGetError() =GL_INVALID_OPERATION
glGetError()=GL_INVALID_OPERATION
glGetError()=GL_NO_ERROR
glGetError()=GL_NO_ERROR
glDisable(GL_TEXTURE_2D)
glGetError()=GL_NO_ERROR
glActiveTextureARB(GL_TEXTURE0)
glGetError()=GL_NO_ERROR
glDisable(GL_TEXTURE_2D)
glGetError()=GL_NO_ERROR

regards
Oliver

ZbuffeR
06-18-2009, 02:50 AM
Try without the glMultiTexCoord2fARB : does the error disappear ?

This is the only thing that is done only once per run, the wglGetProcAddress for this extension :

glBegin(GL_TRIANGLES)
wglGetProcAddress("glMultiTexCoord2fARB")=0x1002a170 ////// <--
glMultiTexCoord2fARB(GL_TEXTURE0,0.750000,1.000000 )

Maybe calling it once out of the glBegin/glEnd might help ?
No idea why this would throw a gl error anyway ...

scratt
06-18-2009, 02:56 AM
Just another thought.. If for some reason you called glBegin somewhere else, and then came into this code that would give you an error at

glBegin(GL_TRIANGLES)

which you would not see (with the code above) until after the glEnd().

Just a thought.

Otherwise I also have no idea also.

Oliver Demetz
06-18-2009, 03:10 AM
Try without the glMultiTexCoord2fARB : does the error disappear ?

This is the only thing that is done only once per run, the wglGetProcAddress for this extension :

glBegin(GL_TRIANGLES)
wglGetProcAddress("glMultiTexCoord2fARB")=0x1002a170 ////// <--
glMultiTexCoord2fARB(GL_TEXTURE0,0.750000,1.000000 )

Maybe calling it once out of the glBegin/glEnd might help ?
No idea why this would throw a gl error anyway ...
Thank you, that was the problem!
Thanks a lot!
I thought the call to wglGetProcAdress was just an "internal matter" with no effect on the openGL system, but it isn't.

Thanks again,
best regards,
Oliver