Advertisement
Guest User

OpenGL C++ wrapper

a guest
May 8th, 2016
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.05 KB | None | 0 0
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <GL/glew.h>
  4. #include <GL/gl.h>
  5.  
  6. void __glPrintError(const char *file, const int line) {
  7.     auto error = glGetError();
  8.     if (error != GL_NO_ERROR) {
  9.         std::cerr << "GL: "
  10.         << gluErrorString(error)
  11.         << std::endl
  12.         << "\tat "
  13.         << file
  14.         << ":"
  15.         << line
  16.         << std::endl;
  17.     }
  18. }
  19.  
  20. template<typename Function, typename ... Args>
  21. auto __glFunction(const char *file, const int line, Function f, Args ...args) ->
  22. typename std::enable_if<!std::is_void<decltype(f(args...))>::value, decltype(f(args...))>::type {
  23.  
  24.     auto result = f(args...);
  25.     __glPrintError(file, line);
  26.     return result;
  27. };
  28.  
  29. template<typename Function, typename ... Args>
  30. auto __glFunction(const char *file, const int line, Function f, Args ...args) ->
  31. typename std::enable_if<std::is_void<decltype(f(args...))>::value, void>::type {
  32.  
  33.     f(args...);
  34.     __glPrintError(file, line);
  35. };
  36.  
  37. #define gl(function, ...) __glFunction(__FILE__, __LINE__, function, ##__VA_ARGS__)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement