| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- #include <iostream>
- #include <GL/glew.h>
- #include <GL/glu.h>
- #include "Common.h"
- #include "App.h"
- #include "Util.h"
- // for the colors and formating see http://www.dreamincode.net/forums/showtopic75171.htm
- static const char* terminalColors [MT_NUM + 1] = {
- "\033[1;31;6m", // error
- "\033[1;33;6m", // warning
- "\033[1;31;6m", // fatal
- "\033[1;31;6m", // dbg error
- "\033[1;32;6m", // info
- "\033[0;;m" // default color
- };
- //======================================================================================================================
- // msgPrefix =
- //======================================================================================================================
- ostream& msgPrefix(MsgType msgType, const char* file, int line, const char* func)
- {
- if(app == NULL)
- ::exit(1);
- // select c stream
- ostream* cs;
- switch(msgType)
- {
- case MT_ERROR:
- case MT_WARNING:
- case MT_FATAL:
- case MT_DEBUG_ERR:
- cs = &cerr;
- break;
- case MT_INFO:
- cs = &cout;
- break;
- default:
- break;
- }
- // print terminal color
- if(app->isTerminalColoringEnabled())
- {
- (*cs) << terminalColors[msgType];
- }
- // print message info
- switch(msgType)
- {
- case MT_ERROR:
- (*cs) << "Error";
- break;
- case MT_WARNING:
- (*cs) << "Warning";
- break;
- case MT_FATAL:
- (*cs) << "Fatal";
- break;
- case MT_DEBUG_ERR:
- (*cs) << "Debug Err";
- break;
- case MT_INFO:
- (*cs) << "Info";
- break;
- default:
- break;
- }
- // print caller info
- (*cs) << " (" << Util::cutPath(file) << ":" << line << " " << Util::getFunctionFromPrettyFunction(func) << "): ";
- return (*cs);
- }
- //======================================================================================================================
- // msgSuffix =
- //======================================================================================================================
- ostream& msgSuffix(ostream& cs)
- {
- if(app == NULL)
- ::exit(1);
- if(app->isTerminalColoringEnabled())
- cs << terminalColors[MT_NUM];
- cs << endl;
- return cs;
- }
- //======================================================================================================================
- // msgSuffixFatal =
- //======================================================================================================================
- ostream& msgSuffixFatal(ostream& cs)
- {
- msgSuffix(cs);
- ::exit(1);
- return cs;
- }
- //======================================================================================================================
- // msgGlError =
- //======================================================================================================================
- bool msgGlError(const char* file, int line, const char* func)
- {
- GLenum errId = glGetError();
- if(errId == GL_NO_ERROR) return true;
- msgPrefix(MT_ERROR, file, line, func) << "OpenGL Err: " << gluErrorString(errId) << msgSuffix;
- return false;
- }
|