gl.cpp
Go to the documentation of this file.
1 #include "quori_face/gl.hpp"
2 #include <GL/gl3w.h>
3 #include <GLFW/glfw3.h>
4 #include <GL/glu.h>
5 
6 #include <stdexcept>
7 #include <iostream>
8 
9 #include "trace.hpp"
10 
11 using namespace quori_face;
12 
13 namespace
14 {
15  bool is_inited(false);
16 
17  __attribute__((constructor))
18  bool init()
19  {
20  // FIXME: This isn't thread-safe
21  if (is_inited) return true;
22 
23  if (!QUORI_FACE_TRACE(glfwInit()))
24  {
25  std::cerr << "GLFW initialization failed" << std::endl;
26  exit(1);
27  return false;
28  }
29 
30  QUORI_FACE_TRACE(glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3));
31  QUORI_FACE_TRACE(glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2));
32  QUORI_FACE_TRACE(glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE));
33 
34  is_inited = true;
35  return true;
36  }
37 
38  __attribute__((destructor))
39  void deinit()
40  {
41  if (!is_inited) return;
42 
43  QUORI_FACE_TRACE(glfwTerminate());
44  }
45 }
46 
48 {
49  const GLenum error = glGetError();
50  if (error == GL_NO_ERROR) return;
51  throw std::runtime_error(reinterpret_cast<const char *>(gluErrorString(error)));
52 }
GL_NO_ERROR
#define GL_NO_ERROR
Definition: glcorearb.h:114
trace.hpp
GLenum
unsigned int GLenum
Definition: glcorearb.h:62
quori_face
Definition: Cache.hpp:9
gl3w.h
glGetError
#define glGetError
Definition: gl3w.h:932
QUORI_FACE_TRACE
#define QUORI_FACE_TRACE(stmt)
Definition: quori_face/trace.hpp:16
quori_face::checkGlError
void checkGlError()
Throws a std::runtime_error if the OpenGL error flag is set.
Definition: gl.cpp:47
gl.hpp
init
void init(const M_string &remappings)


quori_face
Author(s):
autogenerated on Wed Mar 2 2022 00:53:20