Tizen 2.1 base
[sdk/ide/native-sample.git] / samples / native / partner / cpp / Sample / Tizen C++ / GlesCube / GlesCube / project / inc / GlesCube.h
1 //
2 // Tizen C++ SDK
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Flora License, Version 1.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 //     http://www.tizenopensource.org/license
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an AS IS BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #ifndef _GLES_CUBE_H_
19 #define _GLES_CUBE_H_
20
21
22 #include <new>
23 #include <FBase.h>
24 #include <FSystem.h>
25 #include <FGraphics.h>
26 #include <FUi.h>
27 #include <FApp.h>
28 #include <FGraphicsOpengl2.h>
29
30
31 struct Matrix
32 {
33         Osp::Graphics::Opengl::GLfloat m[4][4];
34 };
35
36 class GlesCube :
37         public Osp::App::Application,
38         public Osp::System::IScreenEventListener,
39         public Osp::Ui::IKeyEventListener,
40         public Osp::Base::Runtime::ITimerEventListener
41 {
42 public:
43         static Osp::App::Application* CreateInstance(void);
44
45         GlesCube(void);
46         ~GlesCube(void);
47
48         virtual bool OnAppInitializing(Osp::App::AppRegistry& appRegistry);
49         virtual bool OnAppTerminating(Osp::App::AppRegistry& appRegistry, bool forcedTermination = false);
50         virtual void OnForeground(void);
51         virtual void OnBackground(void);
52         virtual void OnLowMemory(void);
53         virtual void OnBatteryLevelChanged(Osp::System::BatteryLevel batteryLevel);
54         virtual void OnKeyPressed(const Osp::Ui::Control& source, Osp::Ui::KeyCode keyCode);
55         virtual void OnKeyReleased(const Osp::Ui::Control& source, Osp::Ui::KeyCode keyCode);
56         virtual void OnKeyLongPressed(const Osp::Ui::Control& source, Osp::Ui::KeyCode keyCode);
57
58         virtual void OnScreenOn(void);
59         virtual void OnScreenOff(void);
60
61         virtual void OnTimerExpired(Osp::Base::Runtime::Timer& timer);
62         bool Draw(void);
63
64 private:
65         bool InitEGL(void);
66         bool InitGL(void);
67         void DestroyGL(void);
68         void Update(void);
69         void Cleanup(void);
70
71         void LoadIdentity(Matrix* pResult);
72         void Frustum(Matrix* pResult, float left, float right, float bottom, float top, float nearZ, float farZ);
73         void Perspective(Matrix* pResult, float fovY, float aspect, float nearZ, float farZ);
74         void Translate(Matrix* pResult, Osp::Graphics::Opengl::GLfloat tx, Osp::Graphics::Opengl::GLfloat ty,
75                         Osp::Graphics::Opengl::GLfloat tz);
76         void Rotate(Matrix* pResult, Osp::Graphics::Opengl::GLfloat angle, Osp::Graphics::Opengl::GLfloat x,
77                         Osp::Graphics::Opengl::GLfloat y, Osp::Graphics::Opengl::GLfloat z);
78         void Multiply(Matrix* pResult, Matrix* pSrcA, Matrix* pSrcB);
79
80 private:
81         Osp::Graphics::Opengl::EGLDisplay  __eglDisplay;
82         Osp::Graphics::Opengl::EGLSurface  __eglSurface;
83         Osp::Graphics::Opengl::EGLConfig   __eglConfig;
84         Osp::Graphics::Opengl::EGLContext  __eglContext;
85         Osp::Graphics::Opengl::GLuint      __programObject;
86         Osp::Graphics::Opengl::GLint       __idxPosition;
87         Osp::Graphics::Opengl::GLint       __idxColor;
88         Osp::Graphics::Opengl::GLint       __idxMVP;
89         Osp::Graphics::Opengl::GLfloat     __angle;
90         Osp::Base::Runtime::Timer*         __pTimer;
91         Matrix                             __matMVP;
92
93         Osp::Ui::Controls::Form*           __pForm;
94 };
95
96 #endif // __GLES_CUBE_H__