Better app shutdown, file cleanup, init work on adding touch events
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
namespace lime {
|
||||
|
||||
|
||||
class TizenApplication : public Tizen::App::UiApp, public Tizen::System::IScreenEventListener, public Tizen::Ui::IKeyEventListener, public Tizen::Base::Runtime::ITimerEventListener {
|
||||
class TizenApplication : public Tizen::App::UiApp, public Tizen::System::IScreenEventListener, public Tizen::Ui::IKeyEventListener, public Tizen::Base::Runtime::ITimerEventListener, public Tizen::Ui::ITouchEventListener {
|
||||
|
||||
public:
|
||||
|
||||
@@ -39,6 +39,12 @@ namespace lime {
|
||||
virtual void OnScreenOff (void);
|
||||
virtual void OnScreenOn (void);
|
||||
virtual void OnTimerExpired (Tizen::Base::Runtime::Timer& timer);
|
||||
virtual void OnTouchCanceled (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo);
|
||||
virtual void OnTouchFocusIn (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo);
|
||||
virtual void OnTouchFocusOut (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo);
|
||||
virtual void OnTouchMoved (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo);
|
||||
virtual void OnTouchPressed (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo);
|
||||
virtual void OnTouchReleased (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo);
|
||||
|
||||
private:
|
||||
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef PLATFORM_TIZEN_TIZEN_UI_APP_H
|
||||
#define PLATFORM_TIZEN_TIZEN_UI_APP_H
|
||||
|
||||
|
||||
#include "platform/tizen/TizenFrame.h"
|
||||
#include <FApp.h>
|
||||
#include <FBase.h>
|
||||
#include <FSystem.h>
|
||||
#include <FUi.h>
|
||||
#include <FUiIme.h>
|
||||
#include <FGraphics.h>
|
||||
//#include <gl.h>
|
||||
#include <FGrpGlPlayer.h>
|
||||
|
||||
//#include "GlRendererTemplate.h"
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
class TizenUIApp : public Tizen::App::UiApp, public Tizen::System::IScreenEventListener, public Tizen::Ui::IKeyEventListener {
|
||||
|
||||
public:
|
||||
|
||||
static Tizen::App::UiApp* CreateInstance (void);
|
||||
|
||||
TizenUIApp (void);
|
||||
virtual ~TizenUIApp (void);
|
||||
|
||||
virtual bool OnAppInitialized (void);
|
||||
virtual bool OnAppInitializing (Tizen::App::AppRegistry& appRegistry);
|
||||
virtual bool OnAppTerminating (Tizen::App::AppRegistry& appRegistry, bool forcedTermination = false);
|
||||
virtual bool OnAppWillTerminate (void);
|
||||
virtual void OnBackground (void);
|
||||
virtual void OnBatteryLevelChanged (Tizen::System::BatteryLevel batteryLevel);
|
||||
virtual void OnForeground (void);
|
||||
virtual void OnLowMemory (void);
|
||||
virtual void OnKeyLongPressed (const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
|
||||
virtual void OnKeyPressed (const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
|
||||
virtual void OnKeyReleased (const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode);
|
||||
virtual void OnScreenOff (void);
|
||||
virtual void OnScreenOn (void);
|
||||
|
||||
private:
|
||||
|
||||
//Tizen::Graphics::Opengl::GlPlayer* __player;
|
||||
//Tizen::Graphics::Opengl::IGlRenderer* __renderer;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -1,33 +0,0 @@
|
||||
#ifndef PLATFORM_TIZEN_TIZEN_UI_FRAME_H
|
||||
#define PLATFORM_TIZEN_TIZEN_UI_FRAME_H
|
||||
|
||||
|
||||
#include <FApp.h>
|
||||
#include <FBase.h>
|
||||
#include <FSystem.h>
|
||||
#include <FUi.h>
|
||||
#include <FUiIme.h>
|
||||
#include <FGraphics.h>
|
||||
#include <gl.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
class TizenUIFrame : public Tizen::Ui::Controls::Frame {
|
||||
|
||||
public:
|
||||
|
||||
TizenUIFrame (void);
|
||||
virtual ~TizenUIFrame (void);
|
||||
|
||||
virtual result OnInitializing (void);
|
||||
virtual result OnTerminating (void);
|
||||
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
@@ -25,7 +25,7 @@ namespace lime {
|
||||
|
||||
if (sgWidth == 0 && sgHeight == 0) {
|
||||
|
||||
// Hard code for now
|
||||
// Hard-code screen size for now
|
||||
|
||||
sgWidth = 720;
|
||||
sgHeight = 1280;
|
||||
@@ -39,60 +39,10 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
void StartAnimation () {
|
||||
|
||||
Event poll (etPoll);
|
||||
sgTizenFrame->HandleEvent (poll);
|
||||
|
||||
/*while (!glfwWindowShouldClose(sgGLFWFrame->GetWindow()))
|
||||
{
|
||||
glfwPollEvents();
|
||||
|
||||
int i, count;
|
||||
for (int joy = 0; joy < MAX_JOYSTICKS; joy++)
|
||||
{
|
||||
if (glfwJoystickPresent(joy) == GL_TRUE)
|
||||
{
|
||||
// printf("joystick %s\n", glfwGetJoystickName(joy));
|
||||
|
||||
const float *axes = glfwGetJoystickAxes(joy, &count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
Event joystick(etJoyAxisMove);
|
||||
joystick.id = joy;
|
||||
joystick.code = i;
|
||||
joystick.value = axes[i];
|
||||
sgGLFWFrame->HandleEvent(joystick);
|
||||
}
|
||||
|
||||
const unsigned char *pressed = glfwGetJoystickButtons(joy, &count);
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
Event joystick(pressed[i] == GLFW_PRESS ? etJoyButtonDown : etJoyButtonUp);
|
||||
joystick.id = joy;
|
||||
joystick.code = i;
|
||||
sgGLFWFrame->HandleEvent(joystick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Event poll(etPoll);
|
||||
sgGLFWFrame->HandleEvent(poll);
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
void StartAnimation () {}
|
||||
void PauseAnimation () {}
|
||||
void ResumeAnimation () {}
|
||||
|
||||
|
||||
void StopAnimation () {
|
||||
|
||||
//GLFWwindow *window = sgGLFWFrame->GetWindow();
|
||||
//glfwDestroyWindow(window);
|
||||
//glfwTerminate();
|
||||
|
||||
}
|
||||
void StopAnimation () {}
|
||||
|
||||
|
||||
TizenApplication::TizenApplication (void) {
|
||||
@@ -120,7 +70,18 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
//DestroyGL();
|
||||
Event close (etQuit);
|
||||
sgTizenFrame->HandleEvent (close);
|
||||
|
||||
Event lostFocus (etLostInputFocus);
|
||||
sgTizenFrame->HandleEvent (lostFocus);
|
||||
|
||||
Event deactivate (etDeactivate);
|
||||
sgTizenFrame->HandleEvent (deactivate);
|
||||
|
||||
Event kill (etDestroyHandler);
|
||||
sgTizenFrame->HandleEvent (kill);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -142,9 +103,9 @@ namespace lime {
|
||||
GetAppFrame ()->GetFrame ()->AddControl (mForm);
|
||||
|
||||
mForm->AddKeyEventListener (*this);
|
||||
mForm->AddTouchEventListener (*this);
|
||||
|
||||
bool ok = limeEGLCreate (mForm, sgWidth, sgHeight, 2, (sgFlags & wfDepthBuffer) ? 16 : 0, (sgFlags & wfStencilBuffer) ? 8 : 0, 0);
|
||||
//AppLog ("EGL OK? %d\n", ok);
|
||||
|
||||
mTimer = new (std::nothrow) Tizen::Base::Runtime::Timer;
|
||||
mTimer->Construct (*this);
|
||||
@@ -152,7 +113,6 @@ namespace lime {
|
||||
Tizen::System::PowerManager::AddScreenEventListener (*this);
|
||||
|
||||
sgTizenFrame = new TizenFrame (sgWidth, sgHeight);
|
||||
//sgTizenFrame = createWindowFrame (inTitle, inWidth, inHeight, inFlags);
|
||||
sgCallback (sgTizenFrame);
|
||||
|
||||
return true;
|
||||
@@ -177,6 +137,12 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
Event lostFocus (etLostInputFocus);
|
||||
sgTizenFrame->HandleEvent (lostFocus);
|
||||
|
||||
Event deactivate (etDeactivate);
|
||||
sgTizenFrame->HandleEvent (deactivate);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -191,6 +157,12 @@ namespace lime {
|
||||
|
||||
}
|
||||
|
||||
Event activate (etActivate);
|
||||
sgTizenFrame->HandleEvent (activate);
|
||||
|
||||
Event gotFocus (etGotInputFocus);
|
||||
sgTizenFrame->HandleEvent (gotFocus);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -230,360 +202,37 @@ namespace lime {
|
||||
|
||||
mTimer->Start (10);
|
||||
|
||||
//AppLog("POLL\n");
|
||||
Event poll (etPoll);
|
||||
sgTizenFrame->HandleEvent (poll);
|
||||
|
||||
/*Update();
|
||||
}
|
||||
|
||||
if (!Draw())
|
||||
{
|
||||
AppLog("[GlesCube] GlesCube::Draw() failed.");
|
||||
}*/
|
||||
|
||||
void TizenApplication::OnTouchCanceled (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo) {}
|
||||
void TizenApplication::OnTouchFocusIn (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo) {}
|
||||
void TizenApplication::OnTouchFocusOut (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo) {}
|
||||
|
||||
|
||||
void TizenApplication::OnTouchMoved (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo) {
|
||||
|
||||
AppLog ("OnTouchMoved: (%d x %d)", currentPosition.x, currentPosition.y);
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*bool
|
||||
GlesCube::InitEGL(void)
|
||||
{
|
||||
EGLint numConfigs = 1;
|
||||
void TizenApplication::OnTouchPressed (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo) {
|
||||
|
||||
EGLint eglConfigList[] =
|
||||
{
|
||||
EGL_RED_SIZE, 8,
|
||||
EGL_GREEN_SIZE, 8,
|
||||
EGL_BLUE_SIZE, 8,
|
||||
EGL_ALPHA_SIZE, 8,
|
||||
EGL_DEPTH_SIZE, 8,
|
||||
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
|
||||
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
|
||||
EGL_NONE
|
||||
};
|
||||
AppLog ("OnTouchPressed: (%d x %d)", currentPosition.x, currentPosition.y);
|
||||
|
||||
EGLint eglContextList[] =
|
||||
{
|
||||
EGL_CONTEXT_CLIENT_VERSION, 2,
|
||||
EGL_NONE
|
||||
};
|
||||
|
||||
eglBindAPI(EGL_OPENGL_ES_API);
|
||||
|
||||
__eglDisplay = eglGetDisplay((EGLNativeDisplayType)EGL_DEFAULT_DISPLAY);
|
||||
TryCatch(__eglDisplay != EGL_NO_DISPLAY, , "[GlesCube] eglGetDisplay() failed.");
|
||||
|
||||
TryCatch(!(eglInitialize(__eglDisplay, null, null) == EGL_FALSE || eglGetError() != EGL_SUCCESS), , "[GlesCube] eglInitialize() failed.");
|
||||
|
||||
TryCatch(!(eglChooseConfig(__eglDisplay, eglConfigList, &__eglConfig, 1, &numConfigs) == EGL_FALSE ||
|
||||
eglGetError() != EGL_SUCCESS), , "[GlesCube] eglChooseConfig() failed.");
|
||||
|
||||
TryCatch(numConfigs, , "[GlesCube] eglChooseConfig() failed. because of matching config doesn't exist");
|
||||
|
||||
__eglSurface = eglCreateWindowSurface(__eglDisplay, __eglConfig, (EGLNativeWindowType)__pForm, null);
|
||||
TryCatch(!(__eglSurface == EGL_NO_SURFACE || eglGetError() != EGL_SUCCESS), , "[GlesCube] eglCreateWindowSurface() failed.");
|
||||
|
||||
__eglContext = eglCreateContext(__eglDisplay, __eglConfig, EGL_NO_CONTEXT, eglContextList);
|
||||
TryCatch(!(__eglContext == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS), , "[GlesCube] eglCreateContext() failed.");
|
||||
|
||||
TryCatch(!(eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) == EGL_FALSE ||
|
||||
eglGetError() != EGL_SUCCESS), , "[GlesCube] eglMakeCurrent() failed.");
|
||||
|
||||
return true;
|
||||
|
||||
CATCH:
|
||||
{
|
||||
AppLog("[GlesCube] GlesCube can run on systems which supports OpenGL ES(R) 2.0.");
|
||||
AppLog("[GlesCube] When GlesCube does not correctly execute, there are a few reasons.");
|
||||
AppLog("[GlesCube] 1. The current device(real-target or emulator) does not support OpenGL ES(R) 2.0.\n"
|
||||
" Check the Release Notes.");
|
||||
AppLog("[GlesCube] 2. The system running on emulator cannot support OpenGL(R) 2.1 or later.\n"
|
||||
" Try with other system.");
|
||||
AppLog("[GlesCube] 3. The system running on emulator does not maintain the latest graphics driver.\n"
|
||||
" Update the graphics driver.");
|
||||
}
|
||||
|
||||
DestroyGL();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GlesCube::InitGL(void)
|
||||
{
|
||||
GLint linked = GL_FALSE;
|
||||
GLuint fragShader = glCreateShader(GL_FRAGMENT_SHADER);
|
||||
GLuint vertShader = glCreateShader(GL_VERTEX_SHADER);
|
||||
void TizenApplication::OnTouchReleased (const Tizen::Ui::Control &source, const Tizen::Graphics::Point ¤tPosition, const Tizen::Ui::TouchEventInfo &touchInfo) {
|
||||
|
||||
glShaderSource(fragShader, 1, static_cast<const char**> (&FRAGMENT_TEXT), null);
|
||||
glCompileShader(fragShader);
|
||||
GLint bShaderCompiled = GL_FALSE;
|
||||
glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bShaderCompiled);
|
||||
AppLog ("OnTouchReleased: (%d x %d)", currentPosition.x, currentPosition.y);
|
||||
|
||||
TryCatch(bShaderCompiled != GL_FALSE, , "[GlesCube] bShaderCompiled = GL_FALSE");
|
||||
|
||||
glShaderSource(vertShader, 1, static_cast<const char**> (&VERTEX_TEXT), null);
|
||||
glCompileShader(vertShader);
|
||||
glGetShaderiv(vertShader, GL_COMPILE_STATUS, &bShaderCompiled);
|
||||
|
||||
TryCatch(bShaderCompiled != GL_FALSE, , "[GlesCube] bShaderCompiled == GL_FALSE");
|
||||
|
||||
__programObject = glCreateProgram();
|
||||
glAttachShader(__programObject, fragShader);
|
||||
glAttachShader(__programObject, vertShader);
|
||||
glLinkProgram(__programObject);
|
||||
glGetProgramiv(__programObject, GL_LINK_STATUS, &linked);
|
||||
|
||||
if (linked == GL_FALSE)
|
||||
{
|
||||
GLint infoLen = 0;
|
||||
glGetProgramiv(__programObject, GL_INFO_LOG_LENGTH, &infoLen);
|
||||
|
||||
if (infoLen > 1)
|
||||
{
|
||||
char* infoLog = new (std::nothrow) char[infoLen];
|
||||
glGetProgramInfoLog(__programObject, infoLen, null, infoLog);
|
||||
AppLog("[GlesCube] Linking failed. log: %s", infoLog);
|
||||
delete [] infoLog;
|
||||
}
|
||||
|
||||
TryCatch(false, , "[GlesCube] linked == GL_FALSE");
|
||||
}
|
||||
|
||||
__idxPosition = glGetAttribLocation(__programObject, "a_position");
|
||||
__idxColor = glGetAttribLocation(__programObject, "a_color");
|
||||
__idxMVP = glGetUniformLocation(__programObject, "u_mvpMatrix");
|
||||
|
||||
glUseProgram(__programObject);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
__angle = 45.0f;
|
||||
|
||||
glDeleteShader(vertShader);
|
||||
glDeleteShader(fragShader);
|
||||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
return true;
|
||||
|
||||
CATCH:
|
||||
glDeleteShader(vertShader);
|
||||
glDeleteShader(fragShader);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GlesCube::DestroyGL(void)
|
||||
{
|
||||
if (__programObject)
|
||||
{
|
||||
glDeleteProgram(__programObject);
|
||||
}
|
||||
|
||||
if (__eglDisplay)
|
||||
{
|
||||
eglMakeCurrent(__eglDisplay, null, null, null);
|
||||
|
||||
if (__eglContext)
|
||||
{
|
||||
eglDestroyContext(__eglDisplay, __eglContext);
|
||||
__eglContext = EGL_NO_CONTEXT;
|
||||
}
|
||||
|
||||
if (__eglSurface)
|
||||
{
|
||||
eglDestroySurface(__eglDisplay, __eglSurface);
|
||||
__eglSurface = EGL_NO_SURFACE;
|
||||
}
|
||||
|
||||
eglTerminate(__eglDisplay);
|
||||
__eglDisplay = EGL_NO_DISPLAY;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
GlesCube::Update(void)
|
||||
{
|
||||
FloatMatrix4 matPerspective;
|
||||
FloatMatrix4 matModelview;
|
||||
|
||||
__angle += 5.0f;
|
||||
|
||||
if (__angle >= 360.0f)
|
||||
{
|
||||
__angle -= 360.0f;
|
||||
}
|
||||
|
||||
int x, y, width, height;
|
||||
__pForm->GetBounds(x, y, width, height);
|
||||
|
||||
float aspect = float(width) / float(height);
|
||||
|
||||
Perspective(&matPerspective, 60.0f, aspect, 1.0f, 20.0f);
|
||||
|
||||
Translate(&matModelview, 0.0f, 0.0f, -2.5f);
|
||||
Rotate(&matModelview, __angle, 1.0f, 0.0f, 1.0f);
|
||||
|
||||
__matMVP = matPerspective * matModelview;
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
GlesCube::Draw(void)
|
||||
{
|
||||
if (eglMakeCurrent(__eglDisplay, __eglSurface, __eglSurface, __eglContext) == GL_FALSE ||
|
||||
eglGetError() != EGL_SUCCESS)
|
||||
{
|
||||
AppLog("[GlesCube] eglMakeCurrent() failed.");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int x, y, width, height;
|
||||
__pForm->GetBounds(x, y, width, height);
|
||||
|
||||
glViewport(0, 0, width, height);
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
glVertexAttribPointer(__idxPosition, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GL_FLOAT), VERTICES);
|
||||
glVertexAttribPointer(__idxColor, 4, GL_FLOAT, GL_FALSE, 4 * sizeof(GL_FLOAT), COLORS);
|
||||
|
||||
glEnableVertexAttribArray(__idxPosition);
|
||||
glEnableVertexAttribArray(__idxColor);
|
||||
|
||||
glUniformMatrix4fv(__idxMVP, 1, GL_FALSE, (GLfloat*)__matMVP.matrix);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_SHORT, INDICES);
|
||||
|
||||
eglSwapBuffers(__eglDisplay, __eglSurface);
|
||||
|
||||
#ifdef DISPLAY_FPS
|
||||
static float fps = 0.0f;
|
||||
static float updateInterval = 1000.0f;
|
||||
static float timeSinceLastUpdate = 0.0f;
|
||||
static float frameCount = 0;
|
||||
static long long currentTick;
|
||||
static long long lastTick;
|
||||
static bool isFirst = true;
|
||||
|
||||
if (isFirst)
|
||||
{
|
||||
SystemTime::GetTicks(currentTick);
|
||||
lastTick = currentTick;
|
||||
isFirst = false;
|
||||
}
|
||||
|
||||
frameCount++;
|
||||
SystemTime::GetTicks(currentTick);
|
||||
|
||||
float elapsed = currentTick - lastTick;
|
||||
|
||||
lastTick = currentTick;
|
||||
timeSinceLastUpdate += elapsed;
|
||||
|
||||
if (timeSinceLastUpdate > updateInterval)
|
||||
{
|
||||
if (timeSinceLastUpdate)
|
||||
{
|
||||
fps = (frameCount / timeSinceLastUpdate) * 1000.f;
|
||||
AppLog("[GlesCube] FPS: %f frames/sec", fps);
|
||||
|
||||
frameCount = 0;
|
||||
timeSinceLastUpdate -= updateInterval;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
GlesCube::Frustum(FloatMatrix4* pResult, float left, float right, float bottom, float top, float near, float far)
|
||||
{
|
||||
float diffX = right - left;
|
||||
float diffY = top - bottom;
|
||||
float diffZ = far - near;
|
||||
|
||||
if ((near <= 0.0f) || (far <= 0.0f) ||
|
||||
(diffX <= 0.0f) || (diffY <= 0.0f) || (diffZ <= 0.0f))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pResult->matrix[0][0] = 2.0f * near / diffX;
|
||||
pResult->matrix[1][1] = 2.0f * near / diffY;
|
||||
pResult->matrix[2][0] = (right + left) / diffX;
|
||||
pResult->matrix[2][1] = (top + bottom) / diffY;
|
||||
pResult->matrix[2][2] = -(near + far) / diffZ;
|
||||
pResult->matrix[2][3] = -1.0f;
|
||||
pResult->matrix[3][2] = -2.0f * near * far / diffZ;
|
||||
|
||||
pResult->matrix[0][1] = pResult->matrix[0][2] = pResult->matrix[0][3] = 0.0f;
|
||||
pResult->matrix[1][0] = pResult->matrix[1][2] = pResult->matrix[1][3] = 0.0f;
|
||||
pResult->matrix[3][0] = pResult->matrix[3][1] = pResult->matrix[3][3] = 0.0f;
|
||||
}
|
||||
|
||||
void
|
||||
GlesCube::Perspective(FloatMatrix4* pResult, float fovY, float aspect, float near, float far)
|
||||
{
|
||||
float fovRadian = fovY / 360.0f * PI;
|
||||
float top = tanf(fovRadian) * near;
|
||||
float right = top * aspect;
|
||||
|
||||
Frustum(pResult, -right, right, -top, top, near, far);
|
||||
}
|
||||
|
||||
void
|
||||
GlesCube::Translate(FloatMatrix4* pResult, float tx, float ty, float tz)
|
||||
{
|
||||
pResult->matrix[3][0] += (pResult->matrix[0][0] * tx + pResult->matrix[1][0] * ty + pResult->matrix[2][0] * tz);
|
||||
pResult->matrix[3][1] += (pResult->matrix[0][1] * tx + pResult->matrix[1][1] * ty + pResult->matrix[2][1] * tz);
|
||||
pResult->matrix[3][2] += (pResult->matrix[0][2] * tx + pResult->matrix[1][2] * ty + pResult->matrix[2][2] * tz);
|
||||
pResult->matrix[3][3] += (pResult->matrix[0][3] * tx + pResult->matrix[1][3] * ty + pResult->matrix[2][3] * tz);
|
||||
}
|
||||
|
||||
void
|
||||
GlesCube::Rotate(FloatMatrix4* pResult, float angle, float x, float y, float z)
|
||||
{
|
||||
FloatMatrix4 rotate;
|
||||
|
||||
float cos = cosf(angle * PI / 180.0f);
|
||||
float sin = sinf(angle * PI / 180.0f);
|
||||
float cos1 = 1.0f - cos;
|
||||
|
||||
FloatVector4 vector(x, y, z, 0.0f);
|
||||
vector.Normalize();
|
||||
x = vector.x;
|
||||
y = vector.y;
|
||||
z = vector.z;
|
||||
|
||||
rotate.matrix[0][0] = (x * x) * cos1 + cos;
|
||||
rotate.matrix[0][1] = (x * y) * cos1 - z * sin;
|
||||
rotate.matrix[0][2] = (z * x) * cos1 + y * sin;
|
||||
rotate.matrix[0][3] = 0.0f;
|
||||
|
||||
rotate.matrix[1][0] = (x * y) * cos1 + z * sin;
|
||||
rotate.matrix[1][1] = (y * y) * cos1 + cos;
|
||||
rotate.matrix[1][2] = (y * z) * cos1 - x * sin;
|
||||
rotate.matrix[1][3] = 0.0f;
|
||||
|
||||
rotate.matrix[2][0] = (z * x) * cos1 - y * sin;
|
||||
rotate.matrix[2][1] = (y * z) * cos1 + x * sin;
|
||||
rotate.matrix[2][2] = (z * z) * cos1 + cos;
|
||||
|
||||
rotate.matrix[2][3] = rotate.matrix[3][0] = rotate.matrix[3][1] = rotate.matrix[3][2] = 0.0f;
|
||||
rotate.matrix[3][3] = 1.0f;
|
||||
|
||||
*pResult *= rotate;
|
||||
}*/
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,204 +0,0 @@
|
||||
#include <Display.h>
|
||||
#include "platform/tizen/TizenUIApp.h"
|
||||
#include "platform/tizen/TizenUIFrame.h"
|
||||
|
||||
|
||||
//using namespace Tizen::App;
|
||||
//using namespace Tizen::Base;
|
||||
//using namespace Tizen::System;
|
||||
//using namespace Tizen::Ui;
|
||||
//using namespace Tizen::Ui::Controls;
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
FrameCreationCallback sgCallback;
|
||||
unsigned int sgFlags;
|
||||
int sgHeight;
|
||||
const char *sgTitle;
|
||||
TizenFrame *sgTizenFrame;
|
||||
int sgWidth;
|
||||
|
||||
|
||||
void CreateMainFrame (FrameCreationCallback inOnFrame, int inWidth, int inHeight, unsigned int inFlags, const char *inTitle, Surface *inIcon) {
|
||||
|
||||
sgCallback = inOnFrame;
|
||||
sgWidth = inWidth;
|
||||
sgHeight = inHeight;
|
||||
sgFlags = inFlags;
|
||||
sgTitle = inTitle;
|
||||
|
||||
Tizen::Base::Collection::ArrayList args (Tizen::Base::Collection::SingleObjectDeleter);
|
||||
args.Construct ();
|
||||
result r = Tizen::App::UiApp::Execute(TizenUIApp::CreateInstance, &args);
|
||||
|
||||
}
|
||||
|
||||
|
||||
TizenUIApp::TizenUIApp (void) {}
|
||||
TizenUIApp::~TizenUIApp (void) {}
|
||||
|
||||
|
||||
Tizen::App::UiApp* TizenUIApp::CreateInstance (void) {
|
||||
|
||||
return new TizenUIApp ();
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool TizenUIApp::OnAppInitialized (void) {
|
||||
|
||||
//AppLog ("Initialized");
|
||||
|
||||
// TODO:
|
||||
// Add code to do after initialization here.
|
||||
|
||||
// Create a Frame
|
||||
TizenUIFrame* pTizenGLSampleFrame = new TizenUIFrame();
|
||||
pTizenGLSampleFrame->Construct();
|
||||
pTizenGLSampleFrame->SetBackgroundColor(Tizen::Graphics::Color(0xFF0000, false));
|
||||
pTizenGLSampleFrame->SetName(Tizen::Base::String(sgTitle));
|
||||
AddFrame(*pTizenGLSampleFrame);
|
||||
|
||||
pTizenGLSampleFrame->AddKeyEventListener(*this);
|
||||
/*{
|
||||
__player = new Tizen::Graphics::Opengl::GlPlayer;
|
||||
__player->Construct(Tizen::Graphics::Opengl::EGL_CONTEXT_CLIENT_VERSION_1_X, pTizenGLSampleFrame);
|
||||
|
||||
__player->SetFps(60);
|
||||
__player->SetEglAttributePreset(Tizen::Graphics::Opengl::EGL_ATTRIBUTES_PRESET_RGB565);
|
||||
|
||||
__player->Start();
|
||||
}
|
||||
|
||||
__renderer = new GlRendererTemplate();
|
||||
__player->SetIGlRenderer(__renderer);*/
|
||||
|
||||
sgTizenFrame = new TizenFrame (sgWidth, sgHeight);
|
||||
//sgTizenFrame = createWindowFrame (inTitle, inWidth, inHeight, inFlags);
|
||||
sgCallback (sgTizenFrame);
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool TizenUIApp::OnAppInitializing (Tizen::App::AppRegistry& appRegistry) {
|
||||
|
||||
// TODO:
|
||||
// Initialize Frame and App specific data.
|
||||
// The App's permanent data and context can be obtained from the appRegistry.
|
||||
//
|
||||
// If this method is successful, return true; otherwise, return false.
|
||||
// If this method returns false, the App will be terminated.
|
||||
|
||||
// Uncomment the following statement to listen to the screen on/off events.
|
||||
//PowerManager::SetScreenEventListener(*this);
|
||||
|
||||
// TODO:
|
||||
// Add your initialization code here
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool TizenUIApp::OnAppTerminating (Tizen::App::AppRegistry& appRegistry, bool forcedTermination) {
|
||||
|
||||
// TODO:
|
||||
// Deallocate resources allocated by this App for termination.
|
||||
// The App's permanent data and context can be saved via appRegistry.
|
||||
|
||||
/*__player->Stop ();
|
||||
|
||||
if(__renderer != null)
|
||||
{
|
||||
delete __renderer;
|
||||
}
|
||||
delete __player;*/
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
bool TizenUIApp::OnAppWillTerminate (void) {
|
||||
|
||||
// TODO:
|
||||
// Add code to do something before application termination.
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TizenUIApp::OnBackground (void) {
|
||||
|
||||
// TODO:
|
||||
// Stop drawing when the application is moved to the background.
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TizenUIApp::OnBatteryLevelChanged (Tizen::System::BatteryLevel batteryLevel) {
|
||||
|
||||
// TODO:
|
||||
// Handle any changes in battery level here.
|
||||
// Stop using multimedia features(camera, mp3 etc.) if the battery level is CRITICAL.
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TizenUIApp::OnForeground (void) {
|
||||
|
||||
// TODO:
|
||||
// Start or resume drawing when the application is moved to the foreground.
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TizenUIApp::OnKeyLongPressed (const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode) {}
|
||||
void TizenUIApp::OnKeyPressed (const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode) {}
|
||||
|
||||
|
||||
void TizenUIApp::OnKeyReleased (const Tizen::Ui::Control& source, Tizen::Ui::KeyCode keyCode) {
|
||||
|
||||
if (keyCode == Tizen::Ui::KEY_BACK || keyCode == Tizen::Ui::KEY_ESC) {
|
||||
|
||||
Terminate ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TizenUIApp::OnLowMemory (void) {
|
||||
|
||||
// TODO:
|
||||
// Free unnecessary resources or close the application.
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TizenUIApp::OnScreenOff (void) {
|
||||
|
||||
// TODO:
|
||||
// Unless there is a strong reason to do otherwise, release resources (such as 3D, media, and sensors) to allow the device
|
||||
// to enter the sleep mode to save the battery.
|
||||
// Invoking a lengthy asynchronous method within this listener method can be risky, because it is not guaranteed to invoke a
|
||||
// callback before the device enters the sleep mode.
|
||||
// Similarly, do not perform lengthy operations in this listener method. Any operation must be a quick one.
|
||||
|
||||
}
|
||||
|
||||
|
||||
void TizenUIApp::OnScreenOn (void) {
|
||||
|
||||
// TODO:
|
||||
// Get the released resources or resume the operations that were paused or stopped in OnScreenOff().
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
#include "platform/tizen/TizenUIFrame.h"
|
||||
|
||||
|
||||
//using namespace Tizen::Base;
|
||||
//using namespace Tizen::Ui;
|
||||
//using namespace Tizen::Ui::Controls;
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
TizenUIFrame::TizenUIFrame (void) {}
|
||||
TizenUIFrame::~TizenUIFrame (void) {}
|
||||
|
||||
|
||||
result TizenUIFrame::OnInitializing (void) {
|
||||
|
||||
result r = E_SUCCESS;
|
||||
|
||||
// TODO:
|
||||
// Add your initialization code here
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
|
||||
result TizenUIFrame::OnTerminating (void) {
|
||||
|
||||
result r = E_SUCCESS;
|
||||
|
||||
// TODO:
|
||||
// Add your termination code here
|
||||
|
||||
return r;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user