Probably a context problem

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.

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).

Do something like this after you call SwapBuffers() to print out your errors:

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

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;
 }

I’ve added that code, and it returns GL_INVALID_OPERATION :frowning: . What does it mean? I guess nothing good. What am I possibly doing wrong?

From: glRenderMode (blue book)

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 :slight_smile: .

But that can be clarificated a little looking at: glSelectBuffer
OpenGL Blue Book OpenGL Reed Book

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

: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,ZTranslation);
 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();
}
 

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.

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 :slight_smile:

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.