📄 ogles_demo_01.cpp
字号:
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION: ogles_demo_01::CmdEvent
DESCRIPTION:
All menu select events are handled in this function.
PROTOTYPE:
boolean ogles_demo_01::CmdEvent( 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_01::CmdEvent( uint16 wParam)
{
switch( wParam )
{
case IDS_TRI:
{
m_eState = MM_TRIANGLE;
IMENUCTL_SetActive( m_pMenuCtl, FALSE );
NextFrame( this );
return TRUE;
break;
}
default:
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION: ogles_demo_01::KeyEvent
DESCRIPTION:
All key events to the ogles_demo_01 application are handled in this function.
PROTOTYPE:
boolean ogles_demo_01::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_01::KeyEvent( uint16 wParam)
{
// Handle special case of going back to previous menu
if (wParam == AVK_CLR)
{
if (m_eState == MM_MAINMENU || m_eState == MM_EXIT)
{
m_eState = MM_EXIT;
ISHELL_CancelTimer( m_applet.m_pIShell, NULL, (void *)this ) ;
IMENUCTL_SetActive( m_pMenuCtl, FALSE );
return TRUE;
}
else
{
m_eState = MM_MAINMENU;
ISHELL_CancelTimer( m_applet.m_pIShell, NULL, (void *)this ) ;
IMENUCTL_SetActive( m_pMenuCtl, TRUE );
return FALSE;
}
}
/* Only one menu item so ignore checking other menu states
switch(m_eState)
{
case MM_TRIANGLE:
default:
break;
}
*/
switch(wParam)
{
case AVK_SELECT:
case AVK_LEFT:
case AVK_RIGHT:
case AVK_UP:
case AVK_DOWN:
case AVK_1:
case AVK_2:
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 TRUE;
break;
}
return FALSE;
}
/*===========================================================================
FUNCTION: ogles_demo_01::SetupEGL
DESCRIPTION:
This routine is used for EGL setup.
PROTOTYPE:
boolean ogles_demo_01::SetupEGL()
PARAMETERS:
none
DEPENDENCIES
none
RETURN VALUE
TRUE: if no errors
FALSE: if an error occured
===========================================================================*/
boolean ogles_demo_01::SetupEGL()
{
EGLConfig myConfig;
EGLint ncfg = 1;
EGLint params[5] = {EGL_NONE,EGL_NONE,EGL_NONE,EGL_NONE,EGL_NONE};
//
// Init State Data
//
m_eglDisplay = EGL_NO_DISPLAY;
m_eglSurface = EGL_NO_SURFACE;
m_eglContext = EGL_NO_CONTEXT;
// Main Display
m_eglDisplay = eglGetDisplay( m_applet.m_pIDisplay );
if( m_eglDisplay == EGL_NO_DISPLAY || eglGetError() != EGL_SUCCESS )
return FALSE;
if( eglInitialize( m_eglDisplay, NULL, NULL ) == EGL_FALSE || eglGetError() != EGL_SUCCESS )
return FALSE;
// Get Configuration
eglGetConfigs( m_eglDisplay, &myConfig, 1, &ncfg );
// Window Surface
{
//IBitmap *pIBitmapDDB;
IDIB *pDIB;
if( IBITMAP_QueryInterface(m_pDDBitmap, AEECLSID_DIB, (void**)&pDIB) != SUCCESS )
return EFAILED;
m_eglSurface = eglCreateWindowSurface( m_eglDisplay, myConfig, pDIB, params );
IDIB_Release( pDIB );
if( m_eglSurface == EGL_NO_SURFACE || eglGetError() != EGL_SUCCESS )
return FALSE;
}
// Context
m_eglContext = eglCreateContext( m_eglDisplay, myConfig, 0, 0 );
if( m_eglContext == EGL_NO_CONTEXT || eglGetError() != EGL_SUCCESS )
return FALSE;
if( eglMakeCurrent( m_eglDisplay, m_eglSurface, m_eglSurface, m_eglContext ) == EGL_FALSE || eglGetError() != EGL_SUCCESS )
return FALSE;
return TRUE;
}
/*===========================================================================
FUNCTION: ogles_demo_01::SetupGL
DESCRIPTION:
This routine is used for GL setup.
PROTOTYPE:
boolean ogles_demo_01::SetupGL()
PARAMETERS:
none
DEPENDENCIES
none
RETURN VALUE
TRUE: if no errors
FALSE: if an error occured
===========================================================================*/
boolean ogles_demo_01::SetupGL()
{
// Smooth shading
glShadeModel( GL_SMOOTH );
// Depth Test
glEnable( GL_DEPTH_TEST );
// Perspective Correction
glHint( GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST );
// GL Initialization
glViewport( 0, 0, GetScreenWidth(), GetScreenHeight() );
// Init Projection Matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glDisable(GL_LIGHTING);
glDisable(GL_BLEND);
// GL Initialization
glViewport( 0, 0, GetScreenWidth(), GetScreenHeight() );
// Init Projection Matrix
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
glFrustumx( ITOX(-5), ITOX(5),
ITOX(-5), ITOX(5),
ITOX(10),ITOX(100) );
glMatrixMode( GL_MODELVIEW );
glLoadIdentity();
if (glGetError() != GL_NO_ERROR) return FALSE;
return TRUE;
}
/*===========================================================================
FUNCTION: ogles_demo_01::RenderTriangle
DESCRIPTION:
This routine will render a triangle
PROTOTYPE:
void ogles_demo_01::RenderTriangle()
PARAMETERS:
none
DEPENDENCIES
static fucntion
RETURN VALUE
none
===========================================================================*/
void ogles_demo_01::RenderTriangle()
{
int v= ITOX(2);
// Clear everything
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
glPushMatrix();
glLoadIdentity();
glTranslatex( 0, 0, ITOX(-15));
// Triangle
{
int face[9] =
{
-v, -v, v,
v, -v, v,
-v, v, v
};
int color[12] =
{
0, ITOX(1), ITOX(1), 0,
ITOX(1) , 0,ITOX(1), 0,
ITOX(1) , 0, 0, 0
};
uint8 index[3] = {0,1,2};
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);
glVertexPointer(3, GL_FIXED, 0, face);
glColorPointer(4, GL_FIXED, 0, color);
glDrawElements(GL_TRIANGLES, 3, GL_UNSIGNED_BYTE, index);
}
glPopMatrix();
}
/*===========================================================================
FUNCTION: ogles_demo_01::NextFrame
DESCRIPTION:
This routine sets up the frame timer, and then renders the next frame
PROTOTYPE:
void ogles_demo_01::NextFrame(ogles_demo_01* p)
PARAMETERS:
p: pointer to the ogles_demo_01 application instance
DEPENDENCIES
static fucntion
RETURN VALUE
none
===========================================================================*/
void ogles_demo_01::NextFrame(ogles_demo_01* p)
{
p->RenderFrame();
ISHELL_SetTimer( p->m_applet.m_pIShell, 1,(PFNNOTIFY) NextFrame,(void*)p);
}
/*===========================================================================
FUNCTION: ogles_demo_01::RenderFrame
DESCRIPTION:
The main rendering routine for the ogles_demo_01 application
PROTOTYPE:
void ogles_demo_01::RenderFrame()
PARAMETERS:
none
DEPENDENCIES
none
RETURN VALUE
none
===========================================================================*/
void ogles_demo_01::RenderFrame()
{
switch(m_eState)
{
case MM_TRIANGLE:
RenderTriangle( );
break;
default:
break;
}
// Swap the Buffers
eglSwapBuffers( m_eglDisplay, m_eglSurface );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -