00001 #include "utility.h" 00002 #include <fstream> 00003 00004 #include <iostream> 00005 00006 #include "common.h" 00007 00008 bool file_exists(const string &filename) 00009 { 00010 std::ifstream ifile(filename.c_str()); 00011 return ifile.good(); 00012 } 00013 00014 string read_file(const string &filename) 00015 { 00016 std::ifstream ifile(filename.c_str()); 00017 00018 return string(std::istreambuf_iterator<char>(ifile), 00019 std::istreambuf_iterator<char>()); 00020 } 00021 00022 void my_get_errors(const char *location) 00023 { 00024 GLenum error = glGetError(); 00025 00026 if (error != GL_NO_ERROR) { 00027 cerr << "Error at " << location << ": "; 00028 switch (error) { 00029 case GL_INVALID_ENUM: 00030 cerr << "GL: enum argument out of range." << endl; 00031 break; 00032 case GL_INVALID_VALUE: 00033 cerr << "GL: Numeric argument out of range." << endl; 00034 break; 00035 case GL_INVALID_OPERATION: 00036 cerr << "GL: Operation illegal in current state." << endl; 00037 break; 00038 case GL_STACK_OVERFLOW: 00039 cerr << "GL: Stack overflow." << endl; 00040 break; 00041 case GL_STACK_UNDERFLOW: 00042 cerr << "GL: Stack underflow." << endl; 00043 break; 00044 case GL_OUT_OF_MEMORY: 00045 cerr << "GL: Not enough memory left to execute command." << endl; 00046 break; 00047 default: 00048 cerr << "GL: Unknown error." << endl; 00049 } 00050 } 00051 }