Example #1
0
        /// <summary>
        /// This method shows a message box, if an OpenGl error ocurres.
        /// <list type="Table">
        /// <item>
        ///	InvalidEnum:An unacceptable value has been specified for an enumerated argument. The offending function has been ignored.
        ///	</item>
        /// <item>
        /// InvalidValue : A numeric argument is out of range. The offending function has been ignored.
        /// </item>
        ///<item>
        ///InvalidOperation : The specified operation is not allowed in the current state. The offending function has been ignored.
        /// </item>
        /// <item>
        ///StackOverflow : This function would cause a stack overflow. The offending function has been ignored.
        /// </item>
        /// <item>
        ///StackUnderflow : This function would cause a stack underflow. The offending function has been ignored.
        /// </item>
        /// <item>
        ///OutOfMemory : There is not enough memory left to execute the function. The state of OpenGL has been left undefined.
        /// </item>
        /// </list>
        /// </summary>
        ///
        public static void CheckError()
        {
            OpenTK.Graphics.OpenGL.ErrorCode errorCode = ErrorCode.NoError;
            try
            {
                errorCode = GL.GetError();
            }
            catch (Exception)
            {
                throw;
            }


            if (errorCode != OpenTK.Graphics.OpenGL.ErrorCode.NoError)
            {
                switch (errorCode)
                {
                case ErrorCode.InvalidEnum:
                    MessageBox.Show("InvalidEnum - An unacceptable value has been specified for an enumerated argument.  The offending function has been ignored.", "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                case ErrorCode.InvalidValue:
                    MessageBox.Show("InvalidValue - A numeric argument is out of range.  The offending function has been ignored.", "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                case ErrorCode.InvalidOperation:
                    MessageBox.Show("InvalidOperation - The specified operation is not allowed in the current state.  The offending function has been ignored.", "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                case ErrorCode.StackOverflow:
                    MessageBox.Show("StackOverflow - This function would cause a stack overflow.  The offending function has been ignored.", "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                case ErrorCode.StackUnderflow:
                    MessageBox.Show("StackUnderflow - This function would cause a stack underflow.  The offending function has been ignored.", "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                case ErrorCode.OutOfMemory:
                    MessageBox.Show("OutOfMemory - There is not enough memory left to execute the function.  The state of OpenGL has been left undefined.", "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;

                default:
                    MessageBox.Show("Unknown GL error.  This should never happen.", "OpenGL Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    break;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Gets Opengl errors
        /// </summary>
        /// <param name="message">Message to display with the error</param>
        /// <returns>True on error</returns>
        public static bool GetLastError(string message)
        {
            TK.ErrorCode error = TK.GL.GetError();
            if (error == TK.ErrorCode.NoError)
            {
                return(false);
            }


            System.Diagnostics.StackFrame stack = new System.Diagnostics.StackFrame(1, true);

            string msg = message + " => " + error.ToString();


            Trace.WriteLine("\"" + stack.GetFileName() + ":" + stack.GetFileLineNumber() + "\" => GL error : " + msg + " (" + error + ")");

            return(true);
        }