⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ogles_demo_01.cpp

📁 此程序需要Brew sdk2.1版本以上,是关于OpenGL的手机编程.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*=================================================================================
FILE:       ogles_demo_01.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_01 application (very simple, draw a triangle)

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_01.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_01_CreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj);
static int  ogles_demo_01_Load(IShell *ps, void * pHelpers, IModule ** pMod);

// Constant Data...
static const AEEAppInfo gai_ogles_demo_01 = { AEECLSID_OGLES_DEMO_01, OGLES_DEMO_01_RES_FILE, IDS_APPNAME, 0, 0, 0, 0, AFLAG_GAME };

PFNMODENTRY ogles_demo_01_GetModInfo(IShell * ps, AEECLSID ** ppClasses, AEEAppInfo ** pApps, uint16 * pnApps, uint16 * pwMinPriv)
{
   *pApps = (AEEAppInfo *)&gai_ogles_demo_01;
   *pnApps = 1;
   return((PFNMODENTRY)ogles_demo_01_Load);
}

static int ogles_demo_01_Load(IShell *ps, void * pHelpers, IModule ** pMod)
{
	return( AEEStaticMod_New((int16)(sizeof(AEEMod)),ps,pHelpers,pMod,ogles_demo_01_CreateInstance,NULL) );
}
}
#endif  //BREW_STATIC_APP


/*-------------------------------------------------------------------------------*
 *                          B E G I N   P R O G R A M                            *
 *-------------------------------------------------------------------------------*/

/*===========================================================================
FUNCTION: CreateInstance
  
DESCRIPTION:
   This function will create an instance for the ogles_demo_01 application 
  
PROTOTYPE:
   int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
      
PARAMETERS:
   none
            
DEPENDENCIES
  none
              
RETURN VALUE
  none
                
===========================================================================*/
#if defined(BREW_STATIC_APP)
int ogles_demo_01_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_01){
		if(  AEEApplet_New(sizeof(ogles_demo_01), ClsId, pIShell, po, (IApplet**)ppObj,
			(AEEHANDLER)ogles_demo_01::HandleEvent,(PFNFREEAPPDATA)ogles_demo_01::Destroy)== TRUE )
		{
			
			return AEE_SUCCESS;
		}
	}
	return EFAILED;
}


/*===========================================================================
FUNCTION: ogles_demo_01::Init
  
DESCRIPTION:
   This function will initalize the ogles_demo_01 application 
  
PROTOTYPE:
  boolean ogles_demo_01::Init()
      
PARAMETERS:
   none
            
DEPENDENCIES
  none
              
RETURN VALUE
  TRUE: if initialize was successful
  FALSE: if error occured
                
===========================================================================*/
boolean ogles_demo_01::Init()
{

	DBGPRINTF("_X_INIT ROUTINE STARTED");
	// IGL and IEGL
	if( ISHELL_CreateInstance(m_applet.m_pIShell, AEECLSID_GL, (void **)&m_pIGL) != SUCCESS ){
		return FALSE;
	}else 
	{
#if !defined(BREW_STATIC_APP)
		// To use the standard OpenGL|ES APIs must call IGL_Init()
		IGL_Init(m_pIGL);
#endif
	}

	if( ISHELL_CreateInstance(m_applet.m_pIShell, AEECLSID_EGL, (void **)&m_pIEGL) != SUCCESS ){
		return FALSE;
	}else
	{
#if !defined(BREW_STATIC_APP)
		// To use the standard EGL APIs must call IEGL_Init()
	   IEGL_Init(m_pIEGL);
#endif
	}


	// 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;
	}

    m_pMenuCtl = NULL;
	BuildMenu(GetScreenWidth(),GetScreenHeight());
	

	// Setup GL/EGL 
	SetupEGL(); 
	SetupGL();

	// Set the main menu to be active
	IMENUCTL_SetActive( m_pMenuCtl, TRUE );
	m_eState =MM_MAINMENU;

    return TRUE;
}


/*===========================================================================
FUNCTION: ogles_demo_01::Destroy
  
DESCRIPTION:
   This function provides a wrapper for the Brew exit routine. 
  
PROTOTYPE:
  void ogles_demo_01::Destroy(ogles_demo_01* p)
      
PARAMETERS:
   none
            
DEPENDENCIES
  static fucntion
              
RETURN VALUE
  none
                
===========================================================================*/
void ogles_demo_01::Destroy(ogles_demo_01* p)
{
	p->CleanUp();
}


/*===========================================================================
FUNCTION: ogles_demo_01::CleanUp
  
DESCRIPTION:
   This function frees all resource for the application upon exit. 
  
PROTOTYPE:
  void ogles_demo_01::CleanUp()
      
PARAMETERS:
   none
            
DEPENDENCIES
  none
              
RETURN VALUE
  none
                
===========================================================================*/
void ogles_demo_01::CleanUp()
{

	if (m_pDDBitmap)  IBITMAP_Release( m_pDDBitmap );
	if (m_pIFileMgr) IFILEMGR_Release( m_pIFileMgr );
	if (m_pMenuCtl)  IMENUCTL_Release( m_pMenuCtl  );


	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_01::BuildMenu
  
DESCRIPTION:
   All events to the ogles_demo_01 application are handled in this function. 
  
PROTOTYPE:
  boolean ogles_demo_01::BuildMenu(int screen_width,int screen_height)
      
PARAMETERS:
   screen_width: device screen width
   screen_height: device screen height
            
DEPENDENCIES
  none
              
RETURN VALUE
  TRUE: If the build was built successfully 
  FALSE: If an error occured
                
===========================================================================*/
boolean ogles_demo_01::BuildMenu(int screen_width,int screen_height)
{

	AEERect qrc;
	CtlAddItem ai;

	if (m_pMenuCtl == NULL)
	if (ISHELL_CreateInstance(m_applet.m_pIShell, AEECLSID_MENUCTL, (void **)&(m_pMenuCtl)) != SUCCESS )
	{
		return FALSE;
	}

	// Get Menu Area
	SETAEERECT( &qrc, 0, 0, screen_width, screen_height );

	// Set Menu Area
	IMENUCTL_SetRect( m_pMenuCtl, &qrc );
	
	// Set Title
	IMENUCTL_SetTitle( m_pMenuCtl, OGLES_DEMO_01_RES_FILE, IDS_MM_TITLE, NULL );
	
	// Add Items in the Menu (Common to all)
	ai.pText = NULL;
	ai.pImage = NULL;
	ai.pszResImage = ai.pszResText = OGLES_DEMO_01_RES_FILE;
	ai.wFont = AEE_FONT_NORMAL;
	ai.dwData = 0;

	// Quick Test To draw a simple triangle
	ai.wText = IDS_TRI;
	ai.wImage = IDB_TRI;
	ai.wItemID = IDS_TRI;
	IMENUCTL_AddItemEx( m_pMenuCtl, &ai );


	IMENUCTL_EnableCommand(m_pMenuCtl, TRUE);
	
	return TRUE;
	
}






/*===========================================================================
FUNCTION: ogles_demo_01::HandleEvent
  
DESCRIPTION:
   All events to the ogles_demo_01 application are handled in this function. 
  
PROTOTYPE:
  boolean ogles_demo_01::HandleEvent( ogles_demo_01 *p, AEEEvent event, uint16 wParam, uint32 dwParam )
      
PARAMETERS:
   p: pointer to a ogles_demo_01 application instance
   event: the event that needs to be handled
   wParam,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_01::HandleEvent( ogles_demo_01 *p, AEEEvent event, uint16 wParam, uint32 dwParam )
{
	
	switch (event) 
	{
	case EVT_APP_START:
		{
			// intialize the applet
			if( p->Init() == FALSE ) return FALSE;
			return TRUE;
			break;
		}
		
	case EVT_APP_SUSPEND:
		DBGPRINTF("Suspend Called");
		IMENUCTL_SetActive( p->m_pMenuCtl,FALSE);
		ISHELL_CancelTimer( p->m_applet.m_pIShell, NULL, (void *)p );
		p->CleanUp();
		return TRUE;
		
	case EVT_APP_RESUME:
		DBGPRINTF("Resume Called");
		p->Init();
		IMENUCTL_SetActive( p->m_pMenuCtl,TRUE);
		return TRUE;
		
	case EVT_APP_NO_SLEEP:
		return TRUE;
		
	case EVT_COMMAND:
		return p->CmdEvent(wParam);
		break;
		
		
	case EVT_KEY_PRESS:
		p->m_key_state = 1;
		p->m_key_wParam = wParam;	
		if (p->KeyEvent(wParam))
		{
			return IMENUCTL_HandleEvent(p->m_pMenuCtl, 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:
		if (p->m_eState == MM_EXIT)
		{
			if (p->KeyEvent(wParam))
			{
				return IMENUCTL_HandleEvent(p->m_pMenuCtl, EVT_KEY, wParam, dwParam);
			}
			else
			{
				return TRUE;
			}
			
		}
		break;
		
		
	default:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -