liballofw
opengl.h
Go to the documentation of this file.
1 #ifndef ALLOFW_OPENGL_H
2 #define ALLOFW_OPENGL_H
3 
4 #include "common.h"
5 #include "config.h"
6 #include "math/geometry.h"
7 
8 #ifdef __APPLE__
9 #include <OpenGL/gl3.h>
10 #include <OpenGL/gl3ext.h>
11 #else
12 #define GL_GLEXT_PROTOTYPES
13 #include <GL/gl.h>
14 #include <GL/glext.h>
15 #endif
16 
17 // OpenGL Window and Context Creation.
18 
19 namespace allofw {
20 
21  class OpenGLWindow {
22  public:
23 
24  struct Hint {
26  bool fullscreen;
28  int width;
29  int height;
30 
31  Hint() {
32  active_stereo = false;
33  fullscreen = false;
34  hide_cursor = false;
35  width = 900;
36  height = 600;
37  }
38  };
39 
40  class Delegate {
41  public:
42  // General window events.
43  virtual void onMove(int x, int y);
44  virtual void onResize(int width, int height);
45  virtual void onClose();
46  virtual void onRefresh();
47  virtual void onFocus(int focused);
48  virtual void onIconify(int iconified);
49  virtual void onFramebufferSize(int width, int height);
50  // Keyboard evnets.
51  virtual void onKeyboard(const char* key, const char* action, const char* modifiers, int scancode);
52  // Mouse events.
53  virtual void onCursorPosition(double x, double y);
54  virtual void onMouseButton(const char* button, const char* action, const char* modifiers);
55  virtual void onCursorEnter(bool entered);
56  virtual void onScroll(double xoffset, double yoffset);
57  virtual ~Delegate() { }
58  };
59 
60  // Set window delegate.
61  virtual void setDelegate(Delegate* delegate) = 0;
62 
63  // Active the window's OpenGL context.
64  virtual void makeContextCurrent() = 0;
65 
66  // Swap buffers.
67  virtual void swapBuffers() = 0;
68 
69  // Process all pending events.
70  virtual void pollEvents() = 0;
71 
72  // Wait for events.
73  virtual void waitEvents() = 0;
74 
75  // Get framebuffer size. For high-resolution display, this might be different to the window size.
76  virtual Size2i getFramebufferSize() = 0;
77 
78  // Input handling.
79  virtual void enableKeyboardInput() = 0;
80  virtual void enableMouseInput() = 0;
81 
82  // Should the window be closed?
83  virtual bool shouldClose() = 0;
84  // Flag for close, after this, shouldClose() return true.
85  virtual void close() = 0;
86 
87  // Static methods to create a window.
88  static OpenGLWindow* Create(Hint hint, const char* title);
89  static OpenGLWindow* Create(Configuration* config);
90  static void Destroy(OpenGLWindow* window);
91 
92  protected:
93  virtual ~OpenGLWindow();
94  };
95 }
96 
97 #endif
virtual void enableKeyboardInput()=0
Definition: opengl.h:21
int height
Definition: opengl.h:29
Hint()
Definition: opengl.h:31
virtual void pollEvents()=0
virtual void close()=0
virtual Size2i getFramebufferSize()=0
Definition: allofw.h:12
virtual void enableMouseInput()=0
virtual bool shouldClose()=0
int width
Definition: opengl.h:28
bool active_stereo
Definition: opengl.h:25
virtual void swapBuffers()=0
Definition: opengl.h:24
Definition: opengl.h:40
virtual void makeContextCurrent()=0
YAML-based configuration reader.
Definition: config.h:12
static void Destroy(OpenGLWindow *window)
static OpenGLWindow * Create(Hint hint, const char *title)
virtual void waitEvents()=0
virtual ~Delegate()
Definition: opengl.h:57
virtual void setDelegate(Delegate *delegate)=0
bool fullscreen
Definition: opengl.h:26
bool hide_cursor
Definition: opengl.h:27