My Project
ParaEngineGLView.h
1 #pragma once
2 
3 
4 #include "IAttributeFields.h"
5 
6 #if (WIN32)
7  #ifndef GLFW_EXPOSE_NATIVE_WIN32
8  #define GLFW_EXPOSE_NATIVE_WIN32
9  #endif
10 
11  #ifndef GLFW_EXPOSE_NATIVE_WGL
12  #define GLFW_EXPOSE_NATIVE_WGL
13  #endif
14 
15  #include "GLFW/glfw3native.h"
16 #endif
17 
18 #include "GLType.h"
19 
20 namespace ParaEngine {
21 
27  {
28  int redBits;
29  int greenBits;
30  int blueBits;
31  int alphaBits;
32  int depthBits;
33  int stencilBits;
34  };
35 
36 
37 
38 
39  class CParaEngineGLView : public IObject
40  {
41  public:
46  static void setGLContextAttrs(GLContextAttrs& glContextAttrs);
47 
52  const GLContextAttrs& getGLContextAttrs();
53 
56 
57  public:
58  static CParaEngineGLView* create(const std::string& viewName);
59  static CParaEngineGLView* createWithRect(const std::string& viewName, const CCRect& rect, float frameZoomFactor = 1.0f);
60  static CParaEngineGLView* createWithFullScreen(const std::string& viewName);
61  static CParaEngineGLView* createWithFullScreen(const std::string& viewName, const GLFWvidmode &videoMode, GLFWmonitor *monitor);
62 
63  /*
64  *frameZoomFactor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
65  */
66  float getFrameZoomFactor() const;
67 
68  void setViewPortInPoints(float x, float y, float w, float h);
69  void setScissorInPoints(float x, float y, float w, float h);
70 
71  bool windowShouldClose();
72  void pollEvents();
73  GLFWwindow* getWindow() const { return _mainWindow; }
74 
75  bool isOpenGLReady();
76  void end();
77  void swapBuffers();
78  void setIMEKeyboardState(bool bOpen);
79 
80  /*
81  * Set zoom factor for frame. This method is for debugging big resolution (e.g.new ipad) app on desktop.
82  */
83  void setFrameZoomFactor(float zoomFactor);
84 
88  void setCursorVisible(bool isVisible);
89 
93  void enableRetina(bool enabled);
94 
96  bool isRetinaEnabled() const { return _isRetinaEnabled; };
97 
99  int getRetinaFactor() const { return _retinaFactor; }
100 
101  void setViewName(const std::string viewname) { _viewName = viewname; }
102 
108  const CCRect& getViewPortRect() const;
109 
110 
113  bool IsKeyPressed(DWORD nKey);
114 
121  void setFrameSize(float width, float height);
122 
124  void SetWindowText(const char* pChar);
125 
126 
127  void FixWindowSize(bool fixed);
128 #ifdef WIN32
129  HWND getWin32Window() { return glfwGetWin32Window(_mainWindow); };
130 #endif /* (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) */
131  protected:
133  virtual ~CParaEngineGLView();
134 
135  bool initWithRect(const std::string& viewName, const CCRect& rect, float frameZoomFactor);
136  bool initWithFullScreen(const std::string& viewName);
137  bool initWithFullscreen(const std::string& viewname, const GLFWvidmode &videoMode, GLFWmonitor *monitor);
138 
139  bool initGlew();
140 
141  void updateFrameSize();
142 
143  // GLFW callbacks
144  void onGLFWError(int errorID, const char* errorDesc);
145  void onGLFWMouseCallBack(GLFWwindow* window, int button, int action, int modify);
146  void onGLFWMouseMoveCallBack(GLFWwindow* window, double x, double y);
147  void onGLFWMouseScrollCallback(GLFWwindow* window, double x, double y);
148  void onGLFWKeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
149  void onGLFWCharCallback(GLFWwindow* window, unsigned int character);
150  void onGLFWWindowPosCallback(GLFWwindow* windows, int x, int y);
151  void onGLFWframebuffersize(GLFWwindow* window, int w, int h);
152  void onGLFWWindowSizeFunCallback(GLFWwindow *window, int width, int height);
153  void onGLFWWindowIconifyCallback(GLFWwindow* window, int iconified);
154 
161  const Size& getFrameSize() const;
162 
163 
164 
165  protected:
166 
167  GLFWwindow* _mainWindow;
168  GLFWmonitor* _monitor;
169 
170  bool _isRetinaEnabled;
171  bool _isInRetinaMonitor;
172  int _retinaFactor; // Should be 1 or 2
173 
174  bool _captured;
175  bool _supportTouch;
176 
177  float _mouseX;
178  float _mouseY;
179 
180  float _frameZoomFactor;
181 
182  std::string _viewName;
183 
184  // real screen size
185  Size _screenSize;
186 
187  // resolution size, it is the size appropriate for the app resources.
188  Size _designResolutionSize;
189 
190  // the view port size
191  CCRect _viewPortRect;
192 
193  float _scaleX;
194  float _scaleY;
195 
196  friend class GLFWEventHandler;
197  };
198 
199 } // end namespace
Definition: GLType.h:217
bool isRetinaEnabled() const
Check whether retina display is enabled.
Definition: ParaEngineGLView.h:96
int getRetinaFactor() const
Get retina factor.
Definition: ParaEngineGLView.h:99
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ParaEngineGLView.h:39
Definition: ParaEngineGLView.cpp:286
base class for object, such as CBaseObject, IAttributeObject, GUI object.
Definition: PERef.h:287
There are six opengl Context Attrs.
Definition: ParaEngineGLView.h:26
static GLContextAttrs _glContextAttrs
The OpenGL context attrs.
Definition: ParaEngineGLView.h:55
Definition: GLType.h:237