Molecule Viewer
 All Classes Functions Variables Enumerations Pages
Utilities.cpp
1 #include "common.hpp"
2 #include <fstream>
3 
4 
5 //Global variables!
6 //-------------------
7 int height;
8 int width;
9 int occlusionQuality;
10 
11 
12 
13 bool FileExists(const string &filename) {
14  std::ifstream ifile(filename.c_str());
15  return ifile;
16 }
17 
18 
19 void SetOcclusionQuality(int quality) {
20  occlusionQuality = quality;
21 }
22 int GetOcclusionQuality() {
23  return occlusionQuality;
24 }
25 
26 
27 
28 void SetWindowHeight(int h) {
29  height = h;
30 }
31 
32 int GetWindowHeight() {
33  return height;
34 }
35 
36 void SetWindowWidth(int w) {
37  width = w;
38 }
39 
40 int GetWindowWidth() {
41  return width;
42 }
43 
44 
45 string ReadFile(const string &filename) {
46  std::ifstream ifile(filename.c_str());
47  return string(std::istreambuf_iterator<char>(ifile), std::istreambuf_iterator<char>());
48 }
49 
50 
51 void GetErrors(void) {
52  GLenum error = glGetError();
53 
54  if (error != GL_NO_ERROR) {
55  switch (error) {
56  case GL_INVALID_ENUM:
57  cerr << "GL: enum argument out of range." << endl;
58  break;
59  case GL_INVALID_VALUE:
60  cerr << "GL: Numeric argument out of range." << endl;
61  break;
62  case GL_INVALID_OPERATION:
63  cerr << "GL: Operation illegal in current state." << endl;
64  break;
65  case GL_INVALID_FRAMEBUFFER_OPERATION:
66  cerr << "GL: Framebuffer object is not complete." << endl;
67  break;
68  case GL_OUT_OF_MEMORY:
69  cerr << "GL: Not enough memory left to execute command." << endl;
70  break;
71  default:
72  cerr << "GL: Unknown error." << endl;
73  }
74  }
75 }