Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: catching OpenGL errors...

  1. #1
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    catching OpenGL errors...

    Hello,

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

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

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: catching OpenGL errors...

    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.

  3. #3
    Intern Contributor
    Join Date
    Feb 2005
    Location
    Israel
    Posts
    84

    Re: catching OpenGL errors...

    Hi,

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

    Ido
    Ido Ilan

  4. #4
    Senior Member OpenGL Pro sqrt[-1]'s Avatar
    Join Date
    Jun 2002
    Location
    Australia
    Posts
    1,006

    Re: catching OpenGL errors...

    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/

  5. #5
    Senior Member OpenGL Pro dletozeun's Avatar
    Join Date
    Jan 2006
    Location
    FRANCE
    Posts
    1,370

    Re: catching OpenGL errors...

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •