PDA

View Full Version : catching OpenGL errors...



dletozeun
08-27-2007, 11:20 AM
Hello,

I am trying to catch OpenGL errors.
So, I wrote a class that do this job:


class OGLlog : public Log
{
public:
OGLlog(char* fn);

/**
* @brief returns 1 if an OpenGL error occurred, 0 otherwise
*/
static int printError(char* fn)
{
GLenum glErr;
int retCode = 0;

glErr = glGetError();

ofstream f(fn, ios::app);
if(f.is_open())
{
tm now;
time_t t;

time(&t);
now=*localtime(&t);

while (glErr != GL_NO_ERROR)
{
f<<now.tm_hour<<":"<<now.tm_min<<":"<<now.tm_sec<<" /!\\ GL ERROR: "<<gluErrorString(glErr)<<endl;
retCode = 1;
glErr = glGetError();
}
}
else return -1;

f.close();

return retCode;
}
};And now, this is the problem: When I call the printError function, My program stays stuck in the while loop that check if an ogl error remains!
I always have the opengl invalid operation error.

The more strange is that error occurs, even in the beginning of my program, where I did not call any opengl function!

I think that a fresh eye will see the big mistake I have made!

Thanks a lot.

Bob
08-27-2007, 11:39 AM
If you by "at the beginning of the program" means before you set up the rendereing context, then that's perfectly normal behaviour. You cannot call any OpenGL functions before a rendering context is propely configured. If you call glGetError before the rendering context is configured, it will return GL_INVALID_OPERATION if I remember correct, becuse it's an invalid operation to call it without a rendering context.

Ido_Ilan
08-27-2007, 01:17 PM
Hi,

As Bob said just check if an RC is current:
if (wglGetCurrentContex() != null) ....

Ido

sqrt[-1]
08-28-2007, 02:35 AM
FYI: If you are trying to find OpenGL errors, this can be done automatically via tools like:

http://www.opengl.org/sdk/tools/GLIntercept/

http://www.opengl.org/sdk/tools/gDEBugger/

dletozeun
08-28-2007, 03:28 AM
Ok thank you guys, I understand know. It is just like you said, I did not define the rendering context :) I did know it is mandatory...

thank you sqrt[-1], for these links, it may be useful.