📄 textures_blending.c
字号:
/*=================================================================================
FILE: textures_blending.c
SERVICES: Functionality for the textures/blending tutorials.
DESCRIPTION: This file contains all the initialization, event handlers and
other functions specific to the textures/blending tutorials.
Copyright (c) 1999-2003 QUALCOMM Incorporated.
All Rights Reserved.
QUALCOMM Proprietary/GTDR
=================================================================================*/
/* include files */
#include "textures_blending.h"
/* local function prototypes */
static boolean TutorI3D_TexturesBlendingRenderHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam);
static boolean TutorI3D_TexturesBlendingAlphaHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam);
static boolean TutorI3D_TexturesBlendingPerspectiveHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam);
static boolean OnTextureBlendingRender(TutorI3D* pMe);
static boolean OnTextureBlendingAlphaBlending(TutorI3D* pMe);
static boolean OnTextureBlendingPerspective(TutorI3D* pMe);
static void GetWrapString(char* chBuf, AEE3DTextureWrapType wrapType);
static int16 GetNextTextureID(int16 texIn);
/*===========================================================================
FUNCTION: TutorI3D_InitTexturesBlendingScreen
DESCRIPTION
Initializes the textures and blending screen. This function sets up the
rectangles, menus, variables, etc. needed for this screen.
PROTOTYPE:
boolean TutorI3D_InitTexturesBlendingScreen(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture
DEPENDENCIES
none
RETURN VALUE
TRUE: if initialization was successful
FALSE: if failed
SIDE EFFECTS
none
===========================================================================*/
boolean TutorI3D_InitTexturesBlendingScreen(TutorI3D* pMe)
{
AEEMenuColors menuColors;
MEMSET(&menuColors, 0, sizeof(AEEMenuColors));
// Set the clipping rectangle for 3D drawing functions
// while in the sub states.
SETAEERECT (&pMe->screen3DRect, DRAWING_AREA_3D_UP_LEFT_X,
DRAWING_AREA_3D_UP_LEFT_Y,
DRAWING_AREA_3D_WIDTH,
DRAWING_AREA_3D_HEIGHT-5);
// Set the rectangle for the sub menus (bottom of screen)
SETAEERECT (&pMe->menuBottomRect, pMe->screen3DRect.x, DRAWING_AREA_3D_HEIGHT-5,
pMe->di.cxScreen, pMe->di.cyScreen - (DRAWING_AREA_3D_HEIGHT-5));
// Rectangle where the API function is written at top of the screen
SETAEERECT(&pMe->menuTopRect, pMe->screen3DRect.x, pMe->screen3DRect.y,
pMe->screen3DRect.dx, pMe->charHeight + 3);
// The 3D draw area defined by screen3DRect minus the API name rectangle
// at the top of the screen (menuTopRect).
SETAEERECT(&pMe->screenAPI3DRect, pMe->screen3DRect.x,
pMe->menuTopRect.y + pMe->menuTopRect.dy,
pMe->screen3DRect.dx,
pMe->menuBottomRect.y - (pMe->menuTopRect.y + pMe->menuTopRect.dy ));
// create lighting menu instance
if(ISHELL_CreateInstance(pMe->a.m_pIShell, AEECLSID_SOFTKEYCTL,
(void **)&pMe->m_pSubMenu) != SUCCESS)
{
return FALSE;
}
IMENUCTL_SetActive( pMe->m_pSubMenu, FALSE );
IMENUCTL_Reset(pMe->m_pSubMenu);
IMENUCTL_DeleteAll(pMe->m_pSubMenu);
IMENUCTL_SetRect (pMe->m_pSubMenu, &pMe->menuBottomRect);
// direction and color sub menu item
IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
IDS_TEXTURE_RENDERING, IDS_TEXTURE_RENDERING,
NULL, (uint32) NULL);
// material sub menu item
IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
IDS_ALPHA_BLENDING, IDS_ALPHA_BLENDING,
NULL, (uint32) NULL);
IMENUCTL_AddItem(pMe->m_pSubMenu, TUTORI3D_RES_FILE,
IDS_PERSPECTIVE_CORRECTION, IDS_PERSPECTIVE_CORRECTION,
NULL, (uint32) NULL);
// yellow on black for selected items
menuColors.cSelBack = CLR_BLACK;
menuColors.cSelText = CLR_YELLOW;
menuColors.wMask = MC_SEL_BACK | MC_SEL_TEXT ;
IMENUCTL_SetColors(pMe->m_pSubMenu, &menuColors);
I3D_SetClipRect(pMe->m_p3D, &pMe->screen3DRect);
pMe->xrot = 0;
pMe->yrot = 0;
pMe->zrot = 0;
return TRUE;
}
/*===========================================================================
FUNCTION: TutorI3D_DrawTexturesBlendingMenu
DESCRIPTION
Redraws the textures lighting menu to the screen and sets it active.
The rect for the menu is pMe->menuBottomRect
PROTOTYPE:
boolean TutorI3D_DrawTexturesBlendingMenu(TutorI3D* pMe)
PARAMETERS:
pMe: [in]: Pointer to TutorI3D sturcture
DEPENDENCIES
none
RETURN VALUE
TRUE: if menu was redrawn
FALSE: if there was an error
SIDE EFFECTS
none
===========================================================================*/
boolean TutorI3D_DrawTexturesBlendingMenu(TutorI3D* pMe)
{
AECHAR szBuf[30];
// Fill back menu background with same color as unselected menu item background
IDISPLAY_FillRect(pMe->a.m_pIDisplay, &pMe->menuBottomRect, CLR_SYS_ITEM);
if(!IMENUCTL_Redraw(pMe->m_pSubMenu))
{
return FALSE;
}
// Seperate from draw area with a line
IDISPLAY_DrawHLine(pMe->a.m_pIDisplay, pMe->menuBottomRect.x, pMe->menuBottomRect.y, pMe->menuBottomRect.dx);
// Draw title
if(ISHELL_LoadResString(pMe->a.m_pIShell, TUTORI3D_RES_FILE, IDS_TEXTURES_BLENDING,
szBuf, sizeof(szBuf)) == 0)
{
return FALSE;
}
if(IDISPLAY_DrawText(pMe->a.m_pIDisplay, AEE_FONT_NORMAL, szBuf,
-1, (pMe->menuBottomRect.x + pMe->menuBottomRect.dx)/2,
pMe->menuBottomRect.y + 3, NULL,
IDF_ALIGN_CENTER | IDF_TEXT_TRANSPARENT) != SUCCESS)
{
DBGPRINTF("Error: Textures&Blending menu title not displayed");
}
// allow commands
IMENUCTL_SetActive( pMe->m_pSubMenu, TRUE );
return TRUE;
}
/*===========================================================================
FUNCTION
TutorI3D_TexturesBlendingHandleEvent
DESCRIPTION
This is the Event Handler for the textures/blending screen. All events
while in the textures/blending state or a substate of the textures/blending
state are processed by this event handler.
PROTOTYPE:
boolean TutorI3D_TexturesBlendingHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam)
PARAMETERS:
pMe [In] : Pointer to TutorI3D sturcture
ecode [In]: Specifies the Event sent to the event handler
wParam, dwParam [In]: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the event handler has processed the event
FALSE: If the event handler did not process the event
SIDE EFFECTS
none
===========================================================================*/
boolean TutorI3D_TexturesBlendingHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam)
{
/* Send event to appropriate sub event handler or handle event here, depending
on the current state. */
if(pMe->state == STATE_TEXTURES_BLENDING_RENDER)
{
return TutorI3D_TexturesBlendingRenderHandleEvent(pMe, event, wParam, dwParam);
}
else if(pMe->state == STATE_TEXTURES_BLENDING_ALPHA)
{
return TutorI3D_TexturesBlendingAlphaHandleEvent(pMe, event, wParam, dwParam);
}
else if(pMe->state == STATE_TEXTURES_BLENDING_PERSPECTIVE)
{
return TutorI3D_TexturesBlendingPerspectiveHandleEvent(pMe, event, wParam, dwParam);
}
else if (pMe->state == STATE_TEXTURES_BLENDING)
{
switch(event)
{
case EVT_KEY:
switch(wParam)
{
case AVK_CLR:
/* The User has requested to go back to the main menu.
First: Close the current menu (Free associated memory)
Second: set the next state we're going to.
Third: set the changeState flag here to indicate
we're going back a state. Once the current 3D frame
has finished rendering (ie. when we receive the
AEE3D_EVENT_FRAME_UPDATE_DISPLAY), we actually
change states.
The reason we do this is because we don't want to
change states immediately when the user
requests to go back a state. This is because we're going
to be drawing to the frame buffer (menus, etc.) when going
back a state. So what we do is, we wait for the current 3D
frame to finish rendering first, then switch states when we know
it's ok to draw to the frame buffer.
When going forward states, the menus, text, etc. are drawn either
before the rendering for the frame begins
(ie. before I3D_StartFrame() is called) or after it has completed.
(ie. in the respective ManipulateBuf functions).
*/
TutorI3D_CloseMenu(&pMe->m_pSubMenu);
pMe->nextState = STATE_MAIN;
pMe->changeState = TRUE;
break;
default:
return IMENUCTL_HandleEvent(pMe->m_pSubMenu, EVT_KEY,
wParam, dwParam);
}
return TRUE;
case EVT_COMMAND:
switch(wParam)
{
// these tutorials use different models, so
// initialize the appropriate model for the tutorials
// before changing states
case IDS_TEXTURE_RENDERING:
IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
TutorI3D_InitCube(pMe);
pMe->state = STATE_TEXTURES_BLENDING_RENDER;
OnTextureBlendingRender(pMe);
break;
case IDS_ALPHA_BLENDING:
IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
TutorI3D_InitCube(pMe);
pMe->state = STATE_TEXTURES_BLENDING_ALPHA;
OnTextureBlendingAlphaBlending(pMe);
break;
case IDS_PERSPECTIVE_CORRECTION:
IMENUCTL_SetActive(pMe->m_pSubMenu, FALSE);
TutorI3D_InitField(pMe);
pMe->state = STATE_TEXTURES_BLENDING_PERSPECTIVE;
OnTextureBlendingPerspective(pMe);
break;
default:
return FALSE;
}
return TRUE;
default:
return FALSE;
}
}
else
return FALSE;
}
/*===========================================================================
FUNCTION
TutorI3D_TexturesBlendingRenderHandleEvent
DESCRIPTION
This is the Event Handler for the texture rendering tutorial. All events
while in the textures rendering state are processed by this event handler.
PROTOTYPE:
static boolean TutorI3D_TexturesBlendingRenderHandleEvent(TutorI3D* pMe,
AEEEvent event,
uint16 wParam,
uint32 dwParam)
PARAMETERS:
pMe [In] : Pointer to TutorI3D sturcture
ecode [In]: Specifies the Event sent to the event handler
wParam, dwParam [In]: Event specific data.
DEPENDENCIES
none
RETURN VALUE
TRUE: If the event handler has processed the event
FALSE: If the event handler did not process the event
SIDE EFFECTS
none
===========================================================================*/
static boolean TutorI3D_TexturesBlendingRenderHandleEvent(TutorI3D* pMe, AEEEvent event,
uint16 wParam, uint32 dwParam)
{
switch(event)
{
case EVT_KEY:
{
AEE3DTexture texture;
switch(wParam)
{
// toggle horizontal wrap mode
case AVK_1:
{
I3D_GetTexture(pMe->m_p3D, &texture);
if(texture.Wrap_s == AEE3D_TEXTURE_WRAP_REPEAT)
texture.Wrap_s = AEE3D_TEXTURE_WRAP_MIRROR;
else if(texture.Wrap_s == AEE3D_TEXTURE_WRAP_MIRROR)
texture.Wrap_s = AEE3D_TEXTURE_WRAP_CLAMP;
else if(texture.Wrap_s == AEE3D_TEXTURE_WRAP_CLAMP)
texture.Wrap_s = AEE3D_TEXTURE_WRAP_BORDER;
else if(texture.Wrap_s == AEE3D_TEXTURE_WRAP_BORDER)
texture.Wrap_s = AEE3D_TEXTURE_WRAP_REPEAT;
I3D_SetTexture(pMe->m_p3D, &texture);
}
break;
// toggle vertical wrap mode
case AVK_2:
{
I3D_GetTexture(pMe->m_p3D, &texture);
if(texture.Wrap_t == AEE3D_TEXTURE_WRAP_REPEAT)
texture.Wrap_t = AEE3D_TEXTURE_WRAP_MIRROR;
else if(texture.Wrap_t == AEE3D_TEXTURE_WRAP_MIRROR)
texture.Wrap_t = AEE3D_TEXTURE_WRAP_CLAMP;
else if(texture.Wrap_t == AEE3D_TEXTURE_WRAP_CLAMP)
texture.Wrap_t = AEE3D_TEXTURE_WRAP_BORDER;
else if(texture.Wrap_t == AEE3D_TEXTURE_WRAP_BORDER)
texture.Wrap_t = AEE3D_TEXTURE_WRAP_REPEAT;
I3D_SetTexture(pMe->m_p3D, &texture);
}
break;
// toggle the texture image
case AVK_3:
{
IBitmap* textureImage=NULL;
pMe->textureID = GetNextTextureID(pMe->textureID);
// load the next texture
textureImage = ISHELL_LoadResBitmap(pMe->a.m_pIShell,
TUTORI3D_RES_FILE,pMe->textureID);
if(textureImage)
{
I3D_GetTexture(pMe->m_p3D, &texture);
texture.pImage = textureImage;
I3D_SetTexture(pMe->m_p3D, &texture);
IBITMAP_Release(textureImage);
}
else
DBGPRINTF("Error: Resource not found");
}
break;
// toggle render mode
case AVK_4:
{
AEE3DRenderType renderType;
I3D_GetRenderMode(pMe->m_p3D, &renderType);
if(renderType == AEE3D_RENDER_FLAT_SHADING)
renderType = AEE3D_RENDER_FLAT_TEXTURE_FAST_SHADING;
else if(renderType == AEE3D_RENDER_FLAT_TEXTURE_FAST_SHADING)
renderType = AEE3D_RENDER_FLAT_TEXTURE_SHADING;
else if(renderType == AEE3D_RENDER_FLAT_TEXTURE_SHADING)
renderType = AEE3D_RENDER_SMOOTH_SHADING;
else if(renderType == AEE3D_RENDER_SMOOTH_SHADING)
renderType = AEE3D_RENDER_SMOOTH_TEXTURE_FAST_SHADING;
else if(renderType == AEE3D_RENDER_SMOOTH_TEXTURE_FAST_SHADING)
renderType = AEE3D_RENDER_SMOOTH_TEXTURE_SHADING;
else if(renderType == AEE3D_RENDER_SMOOTH_TEXTURE_SHADING)
renderType = AEE3D_RENDER_TEXTURE_REPLACE;
else if(renderType == AEE3D_RENDER_TEXTURE_REPLACE)
renderType = AEE3D_RENDER_FLAT_SHADING;
I3D_SetRenderMode(pMe->m_p3D, renderType);
}
break;
case AVK_5:
{
if(pMe->showTexture == FALSE)
pMe->showTexture = TRUE;
else if(pMe->showTexture == TRUE)
pMe->showTexture = FALSE;
}
break;
// Show/Hide Commands
case AVK_POUND:
{
if(pMe->showHelp == FALSE)
pMe->showHelp = TRUE;
else if(pMe->showHelp == TRUE)
pMe->showHelp = FALSE;
}
break;
case AVK_CLR:
{
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -