PDA

View Full Version : Probably a context problem



christus
11-22-2004, 11:23 AM
I have wrote an application that uses selection mode ( glRenderMode(GL_SELECTION) ). It draws some objects, and user is able to point some of them by clicking them. Everything is ok, when I run it on my PC (Win XP + Radeon 9100), it also works fine on Win XP or Win2k + GeForceMX440. ButÖ at school, on Win98 or XP (I donít know graphic card) it fails to render correctly. Itís ok until user clicks to select sth, then graphics stops refreshing, wglMakeCurrent returns false. Problem is, I canít write code and test it there, only at home, where it is running correctly, but I need it to work there. I would be very thankful for any suggestions.

Aeluned
11-22-2004, 01:14 PM
nah, if the code works fine on your home machine sounds more like a graphics card driver bug.

find out what card you have in there and download the newest drivers for it (if you don't have install privileges get the lab guy/gal to install them).

11-23-2004, 07:20 PM
Do something like this after you call SwapBuffers() to print out your errors:


GLenum glerr = glGetError();
while(glerr != GL_NO_ERROR) {
printf("glGetError: %s\n",gluErrorString(glerr));
glerr = glGetError();
}

11-23-2004, 07:24 PM
Or something like this:


switch(glerr) {
case GL_NO_ERROR:
printf( "GL_ERROR: GL_NO_ERROR");
break;
case GL_INVALID_ENUM:
printf( "GL_ERROR: GL_INVALID_ENUM");
break;
case GL_INVALID_VALUE:
printf( "GL_ERROR: GL_INVALID_VALUE");
break;
case GL_INVALID_OPERATION:
printf( "GL_ERROR: GL_INVALID_OPERATION");
break;
case GL_STACK_OVERFLOW:
printf( "GL_ERROR: GL_STACK_OVERFLOW");
break;
case GL_STACK_UNDERFLOW:
printf( "GL_ERROR: GL_STACK_UNDERFLOW");
break;
case GL_OUT_OF_MEMORY:
printf( "GL_ERROR: GL_OUT_OF_MEMORY");
break;
default:
printf( "GL_ERROR: Unknown: %08X", glerr );
break;
}

christus
11-25-2004, 01:09 PM
I've added that code, and it returns GL_INVALID_OPERATION :( . What does it mean? I guess nothing good. What am I possibly doing wrong?

hgb
11-26-2004, 12:34 AM
From: glRenderMode (blue book) (http://rush3d.com/reference/opengl-bluebook-1.0/ch05.html#id5530227)


GL_INVALID_OPERATION is generated if glSelectBuffer is called while the render mode is GL_SELECT, or if glRenderMode is called with argument GL_SELECT before glSelectBuffer is called at least once. Dont know what is it, but is a start.. I guess :) .

But that can be clarificated a little looking at: glSelectBuffer (http://rush3d.com/reference/opengl-bluebook-1.0/ch05.html#id5532330)
OpenGL Blue Book (http://rush3d.com/reference/opengl-bluebook-1.0/) OpenGL Reed Book (http://rush3d.com/reference/opengl-redbook-1.1/)

I have obtained that links from a guy posting here too.

christus
11-26-2004, 05:48 AM
:cool: that what I call a concrete information. But I think my selection function is OK, as far as it goes for that part. I think Iíll just paste my rendering function, maybe Iím doing sth foolish. Iím quite new to OpenGL, so Iím not sure anything Ií doing. Here's the code:

void __fastcall TForm1 :: Render(void)
{
float xp,yp,zp;

if (ApplicationClosing == true) return;

if(wglMakeCurrent(hdc, hrc) == false)
{
ShowMessage("Context lost.");
Application->Terminate();
}
glMatrixMode( GL_MODELVIEW);

glPushMatrix();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glLightfv( GL_LIGHT0, GL_POSITION, swiatlo_position);

glTranslatef(XTranslation,YTranslation,ZTranslatio n);
glRotatef(angle+XRotation+float(XDelta),0,1,0);

glInitNames();
glPushName(0);

for (unsigned int i = 1; i <= Scena->ObjectCount; i++)
{
if (ActiveMod >-1)
{
glPushMatrix();
glLoadIdentity;

glTranslatef(Form1->Modifiers[ActiveMod].Translation[Scena->Displays[i-1].SequenceID-1].X,
Form1->Modifiers[ActiveMod].Translation[Scena->Displays[i-1].SequenceID-1].Y,
Form1->Modifiers[ActiveMod].Translation[Scena->Displays[i-1].SequenceID-1].Z);
glTranslatef(Scena->ObjectList[i-1].Midpoint.X,
Scena->ObjectList[i-1].Midpoint.Y,
Scena->ObjectList[i-1].Midpoint.Z);
glRotatef(Form1->Modifiers[ActiveMod].Rotation[Scena->Displays[i-1].SequenceID-1].X,1,0,0);
glTranslatef(-Scena->ObjectList[i-1].Midpoint.X,
-Scena->ObjectList[i-1].Midpoint.Y,
-Scena->ObjectList[i-1].Midpoint.Z);
}

if (i == Selected) glColor3f(1,0.2,0.2);
else glColor3f(0.7,0.7,0.7);
if (i < 26) glLoadName(i);
else glLoadName(0xFF);

glCallList(i);

if (ActiveMod >-1)
{
glPopMatrix();
}
}

glPopMatrix();
glFlush();
SwapBuffers(hdc);

GLenum glerr = glGetError();
}

11-26-2004, 02:33 PM
You have to put glGetError(); in a while loop until there are no errors left.
See the OpenGL docs why.

And you can put it anywhere in your code. The reason why I put mine after SwapBuffers()
is because I use it as a one time 'catch-all errors' test. You can put it elsewhere
and narrow in what command is causing your error.

christus
11-29-2004, 10:30 AM
Now it has occurred that glCallList(i) causes GL_INVALID_OPERATION, I have changed it to
if (glIsList(i)) glCallList(i) of course without any effect. Without calling displaylists there is GL_NO_ERROR. When calling a displaylist, itís drawn correctly but there is a GL_INVALID_OPERATION. Iím greedy for further suggestions :)

ZbuffeR
11-29-2004, 11:56 PM
Maybe the GL code in the display list that trigger the error ?
Instead of calling the DL, just put the gl commands to find out which one generate the error.