📄 ogles_demo_03.cpp
字号:
/*=================================================================================
FILE: ogles_demo_03.cpp
DESCRIPTION: This file is provide as a standard sample Brew source file.
Please refer to this OpenGL(R)ES brew sample application as a
reference on how to use the standard OpenGL-ES and EGL APIs.
ABSTRACT: The ogles_demo_03 application displays a skybox with 360 degree
view that construct with six seamless textures.
AUTHOR: QUALCOMM
Copyright (c) 2004 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary/GTDR
=================================================================================*/
/*-------------------------------------------------------------------------------*
* I N C L U D E F I L E S *
*-------------------------------------------------------------------------------*/
#include "ogles_demo_03.h"
/*-------------------------------------------------------------------------------*
* FOR OEM REFERENCE ONLY, USED ONLY FOR BUILDING STATIC APPLICATION *
* Brew developers do not need this code snippet in their appliations *
*-------------------------------------------------------------------------------*/
#if defined(BREW_STATIC_APP)
extern "C"
{
int ogles_demo_03_CreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj);
static int ogles_demo_03_Load(IShell *ps, void * pHelpers, IModule ** pMod);
// Constant Data...
static const AEEAppInfo gai_ogles_demo_03 = { AEECLSID_OGLES_DEMO_03, OGLES_DEMO_03_RES_FILE, IDS_APPNAME, 0, 0, 0, 0, AFLAG_GAME };
PFNMODENTRY ogles_demo_03_GetModInfo(IShell * ps, AEECLSID ** ppClasses, AEEAppInfo ** pApps, uint16 * pnApps, uint16 * pwMinPriv)
{
*pApps = (AEEAppInfo *)&gai_ogles_demo_03;
*pnApps = 1;
return((PFNMODENTRY)ogles_demo_03_Load);
}
static int ogles_demo_03_Load(IShell *ps, void * pHelpers, IModule ** pMod)
{
return( AEEStaticMod_New((int16)(sizeof(AEEMod)),ps,pHelpers,pMod,ogles_demo_03_CreateInstance,NULL) );
}
}
#endif //BREW_STATIC_APP
/*-------------------------------------------------------------------------------*
* B E G I N P R O G R A M *
*-------------------------------------------------------------------------------*/
/*===========================================================================
FUNCTION: AEEClsCreateInstance
DESCRIPTION:
This function will create an instance for the ogles_demo_03 application
PROTOTYPE:
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
PARAMETERS:
ClsId : 32-bit ClassID of the requested interface
pIShell : pointer to the IShell Interface object
po : pointer to the IModlue Interface object
ppObj : pointer to the memory to fill with the pointer to the object
DEPENDENCIES
none
RETURN VALUE
AEE_SUCCESS : if initialize was successful
EFAILED : if error occured
===========================================================================*/
#if defined(BREW_STATIC_APP)
int ogles_demo_03_CreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
#else
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
#endif
{
*ppObj = NULL;
if(ClsId == AEECLSID_OGLES_DEMO_03)
{
if( AEEApplet_New(sizeof(ogles_demo_03), ClsId, pIShell, po, (IApplet**)ppObj,
(AEEHANDLER)ogles_demo_03::HandleEvent,(PFNFREEAPPDATA)ogles_demo_03::Destroy)== TRUE )
{
return AEE_SUCCESS;
}
}
return EFAILED;
}
/*===========================================================================
FUNCTION: ogles_demo_03::Init
DESCRIPTION:
This function will initalize the ogles_demo_03 application
PROTOTYPE:
boolean ogles_demo_03::Init()
PARAMETERS:
none
DEPENDENCIES
none
RETURN VALUE
TRUE : if initialize was successful
FALSE : if error occured
===========================================================================*/
boolean ogles_demo_03::Init(void)
{
DBGPRINTF("[Init] _X_INIT ROUTINE STARTED");
// IGL and IEGL
if( ISHELL_CreateInstance(m_applet.m_pIShell, AEECLSID_GL, (void **)&m_pIGL) != SUCCESS )
return FALSE;
else
// To use the standard OpenGL|ES APIs must call IGL_Init()
IGL_Init(m_pIGL);
if( ISHELL_CreateInstance(m_applet.m_pIShell, AEECLSID_EGL, (void **)&m_pIEGL) != SUCCESS )
return FALSE;
else
// To use the standard EGL APIs must call IEGL_Init()
IEGL_Init(m_pIEGL);
// File I/O
if( ISHELL_CreateInstance( m_applet.m_pIShell, AEECLSID_FILEMGR, (void **)(&m_pIFileMgr) ) != SUCCESS )
{
CleanUp();
return FALSE;
}
// device frame buffer info
if( IDISPLAY_GetDeviceBitmap(m_applet.m_pIDisplay, &m_pDDBitmap) != SUCCESS )
{
CleanUp();
return FALSE;
}
if( IBITMAP_GetInfo(m_pDDBitmap, &m_DDBitmapInfo, sizeof(AEEBitmapInfo)) != SUCCESS )
{
CleanUp();
return FALSE;
}
// Setup GL/EGL
SetupEGL();
SetupGL();
counter = 0;
isLoaded = 0;
LoadTextures();
#ifdef AEE_SIMULATOR
m_BoxspinFactor = 1; //skybox auto spining
m_frame_time = 50;
m_skyboxspin=1; //manual moving
#else
m_BoxspinFactor = 12; //skybox auto spining
m_frame_time =25;
m_skyboxspin=1; //manual moving
#endif
m_boxauto=TRUE;
DBGPRINTF("[Init] _X_INIT ROUTINE OVER");
return TRUE;
}
/*===========================================================================
FUNCTION: ogles_demo_03::Destroy
DESCRIPTION:
This function provides a wrapper for the Brew exit routine.
PROTOTYPE:
void ogles_demo_03::Destroy(ogles_demo_03* p)
PARAMETERS:
p: pointer to the ogles_demo_03 application instance
DEPENDENCIES
static fucntion
RETURN VALUE
none
===========================================================================*/
void ogles_demo_03::Destroy(ogles_demo_03* p)
{
p->CleanUp();
}
/*===========================================================================
FUNCTION: ogles_demo_03::CleanUp
DESCRIPTION:
This function frees all resource for the application upon exit.
PROTOTYPE:
void ogles_demo_03::CleanUp()
PARAMETERS:
none
DEPENDENCIES
none
RETURN VALUE
none
===========================================================================*/
void ogles_demo_03::CleanUp(void)
{
FreeTextureData();
if (m_pDDBitmap) IBITMAP_Release( m_pDDBitmap );
if (m_pIFileMgr) IFILEMGR_Release( m_pIFileMgr );
if( eglMakeCurrent( EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT ) == EGL_FALSE || eglGetError() != EGL_SUCCESS ){}
if( eglDestroyContext( m_eglDisplay, m_eglContext ) == EGL_FALSE || eglGetError() != EGL_SUCCESS ){}
if( eglDestroySurface( m_eglDisplay, m_eglSurface ) == EGL_FALSE || eglGetError() != EGL_SUCCESS ){}
if( eglTerminate( m_eglDisplay ) == EGL_FALSE || eglGetError() != EGL_SUCCESS ){}
// MUST CALL IGL/IEGL RELEASE LAST, NO EGL OR GL calls will work after you release the interfaces.
if (m_pIEGL) IEGL_Release( m_pIEGL );
if (m_pIGL) IGL_Release( m_pIGL );
}
/*===========================================================================
FUNCTION: ogles_demo_03::FreeTextureData
DESCRIPTION:
This function frees the texture data
PROTOTYPE:
void ogles_demo_03::FreeTextureData()
PARAMETERS:
none
DEPENDENCIES
none
RETURN VALUE
none
===========================================================================*/
void ogles_demo_03::FreeTextureData(void)
{
glDeleteTextures(1, &m_boxTopTexture);
glDeleteTextures(1, &m_boxBottomTexture);
glDeleteTextures(1, &m_boxLeftTexture);
glDeleteTextures(1, &m_boxRightTexture);
glDeleteTextures(1, &m_boxFrontTexture);
glDeleteTextures(1, &m_boxBackTexture);
for (int i=0; i<6; i++)
FREE(imageData[i]);
*imageData = NULL;
}
/*===========================================================================
FUNCTION: ogles_demo_03::HandleEvent
DESCRIPTION:
All events to the ogles_demo_03 application are handled in this function.
PROTOTYPE:
boolean ogles_demo_03::HandleEvent( ogles_demo_03 *p, AEEEvent event, uint16 wParam, uint32 dwParam )
PARAMETERS:
p : pointer to a ogles_demo_03 application instance
event : the event that needs to be handled
wParam : Event specific data.
dwParam : Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE : If the event has been processed
FALSE : If the event was not vaild or processed
===========================================================================*/
boolean ogles_demo_03::HandleEvent( ogles_demo_03 *p, AEEEvent event, uint16 wParam, uint32 dwParam )
{
switch (event)
{
case EVT_APP_START:
case EVT_APP_RESUME:
// intialize the applet
p->Init();
// p->RenderSkybox();
// p->m_frame_time=1;
NextFrame(p);
DBGPRINTF("initialized");
return TRUE;
break;
case EVT_APP_SUSPEND:
p->CleanUp();
ISHELL_CancelTimer( p->m_applet.m_pIShell, NULL, (void *)p );
return TRUE;
case EVT_APP_NO_SLEEP:
return TRUE;
case EVT_COMMAND:
break;
case EVT_KEY_PRESS:
p->m_key_state = 1;
p->m_key_wParam = wParam;
if (p->KeyEvent(wParam))
return HandleEvent(p, EVT_KEY, wParam, dwParam);
else
return TRUE;
break;
case EVT_KEY_RELEASE:
p->m_key_state =0;
p->m_key_wParam = wParam;
return TRUE;
break;
case EVT_KEY:
return (p->KeyEvent(wParam));
break;
default:
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION: ogles_demo_03::KeyEvent
DESCRIPTION:
All key events to the ogles_demo_03 application are handled in this function.
PROTOTYPE:
boolean ogles_demo_03::KeyEvent( uint16 wParam)
PARAMETERS:
wParam: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE : If the event has been processed
FALSE : If the event was not vaild or processed
===========================================================================*/
boolean ogles_demo_03::KeyEvent(uint16 wParam)
{
switch(wParam)
{
case AVK_CLR:
ISHELL_CancelTimer( m_applet.m_pIShell, NULL, (void *)this ) ;
return FALSE;
break;
case AVK_SELECT:
m_boxauto=TRUE;
return TRUE;
break;
case AVK_LEFT:
m_boxauto=FALSE;
m_skyboxRotX-=m_skyboxspin;
return TRUE;
case AVK_RIGHT:
m_boxauto=FALSE;
m_skyboxRotX+=m_skyboxspin;
return TRUE;
case AVK_UP:
//m_boxbounce++;
//if (m_boxbounce>=1)
//{
m_skyboxRotY+=m_skyboxspin;
// m_boxbounce=0;
//}
return TRUE;
case AVK_DOWN:
//m_boxbounce++;
//if (m_boxbounce>=1)
//{
m_skyboxRotY-=m_skyboxspin;
// m_boxbounce=0;
//}
return TRUE;
case AVK_1:
//m_boxbounce++;
//if (m_boxbounce>=3)
//{
m_skyboxMove+=m_skyboxspin;
// m_boxbounce=0;
//}
return TRUE;
case AVK_2:
//m_boxbounce++;
//if (m_boxbounce>=3)
//{
m_skyboxMove-=m_skyboxspin;
// m_boxbounce=0;
//}
return TRUE;
case AVK_3:
case AVK_4:
case AVK_5:
case AVK_6:
case AVK_7:
case AVK_8:
case AVK_9:
case AVK_STAR:
case AVK_0:
case AVK_POUND:
default:
return FALSE;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -