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

📄 textures_blending.c

📁 用brew开发3D的例程
💻 C
📖 第 1 页 / 共 3 页
字号:
					User request to return to previous state. Set the next state, 
					and a flag, and wait until the current frame finishes rendering 
					before switching states. For information on why we do this, 
					read the comment in the parent event handler for the AVK_CLR event.
				*/
					pMe->nextState = STATE_TEXTURES_BLENDING;
					pMe->changeState = TRUE;
				}
				break;
				
				default:
					return FALSE;
			}
			
		} // end case EVT_KEY	
		return TRUE;


		case EVT_COMMAND:
			return TRUE;


		default: 
			return FALSE;

	} // end switch(event)


}

/*===========================================================================

FUNCTION 
	TutorI3D_TexturesBlendingAlphaHandleEvent

DESCRIPTION
	This is the Event Handler for the alpha blending tutorial. All events 
	while in the textures and blending alpha state are processed by this event handler. 

PROTOTYPE:
	static boolean TutorI3D_TexturesBlendingAlphaHandleEvent(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_TexturesBlendingAlphaHandleEvent(TutorI3D* pMe, AEEEvent event, 
												   uint16 wParam, uint32 dwParam)
{
	
	switch(event)
	{
		
		case EVT_KEY_RELEASE:
			pMe->keyIsPressed = FALSE;
			return TRUE;
			
		

		case EVT_KEY:
		{
				
			switch(wParam)
			{
					
				/*	5 levels of alpha exist in I3D over the 0-255 range. 
					The ranges for each level from transparent to opaque are:

					0-31	transparent
					32-95	
					96-159
					160-223
					224-255	opaque
				*/

				case AVK_UP:	// increase alpha
				{
					if(pMe->alphaValue <= 31)
						pMe->alphaValue = 64;
					else if(pMe->alphaValue <= 95)
						pMe->alphaValue = 128;
					else if(pMe->alphaValue <= 159)
						pMe->alphaValue = 192;
					else if(pMe->alphaValue <= 223)
						pMe->alphaValue = 255;
					else 
						pMe->alphaValue = 0;
				}
				break;

				case AVK_DOWN:		// decrease alpha
				{
				
					if(pMe->alphaValue >= 224)
						pMe->alphaValue = 192;
					else if(pMe->alphaValue >= 160)
						pMe->alphaValue = 128;
					else if(pMe->alphaValue >= 96)
						pMe->alphaValue = 64;
					else if(pMe->alphaValue >= 32)
						pMe->alphaValue = 0;
					else 
						pMe->alphaValue = 255;
				}
				break;
				
				case AVK_1:
				{
					if(pMe->alphaEnabled)
					{
						I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_BLENDING, FALSE);
						pMe->alphaEnabled = FALSE;
					}
					else
					{
						I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_BLENDING, TRUE);
						pMe->alphaEnabled = TRUE;
					}
				}
				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:
				{
					// disable alpha blending before exiting
					I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_BLENDING, FALSE);
					pMe->alphaEnabled = FALSE;
					
				/* 
					User request to return to previous state. Set the next state, 
					and a flag, and wait until the current frame finishes rendering 
					before switching states. For information on why we do this, 
					read the comment in the parent event handler for the AVK_CLR event.
				*/
					pMe->nextState = STATE_TEXTURES_BLENDING;
					pMe->changeState = TRUE;
				}
				break;
				
				default:
					return FALSE;
			}
			
		} // end case EVT_KEY	
		
		return TRUE;


		case EVT_COMMAND:
			return TRUE;


		default: 
			return FALSE;

	} // end switch(event)

}

/*===========================================================================

FUNCTION 
	TutorI3D_TexturesBlendingPerspectiveHandleEvent

DESCRIPTION
	This is the Event Handler for the perspective correction tutorial. All events 
	while in the textures and blending pers. corr. state are processed by this 
	event handler. 

PROTOTYPE:
	static boolean TutorI3D_TexturesBlendingPerspectiveHandleEvent(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_TexturesBlendingPerspectiveHandleEvent(TutorI3D* pMe, 
															   AEEEvent event, 
															   uint16 wParam, 
															   uint32 dwParam)
{
	switch(event)
	{
		
		case EVT_KEY:
		{
				
			switch(wParam)
			{
				// toggle perspective correction on/off
				case AVK_1:
				{
					if(pMe->perspectiveCorrEnabled)
					{
						I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_PERSPECTIVE_CORRECTION, FALSE);
						pMe->perspectiveCorrEnabled = FALSE;					
					}
					else
					{
						I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_PERSPECTIVE_CORRECTION, TRUE);
						pMe->perspectiveCorrEnabled = TRUE;
					}
				}
				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:
				{
					// disable perspective correction before exiting
					I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_PERSPECTIVE_CORRECTION, FALSE);
					pMe->perspectiveCorrEnabled = FALSE;

				/* 
					User request to return to previous state. Set the next state, 
					and a flag, and wait until the current frame finishes rendering 
					before switching states. For information on why we do this, 
					read the comment in the parent event handler for the AVK_CLR event.
				*/
					pMe->nextState = STATE_TEXTURES_BLENDING;
					pMe->changeState = TRUE;
				}
				break;
				
				default:
					return FALSE;
			}
			
		} // end case EVT_KEY	
		return TRUE;


		case EVT_COMMAND:
			return TRUE;


		default: 
			return FALSE;

	} // end switch(event)

}
/*===========================================================================

FUNCTION 
	OnTextureBlendingRender

DESCRIPTION
	 This function is called when the texture rendering menu item 
	 is selected. Anything to do when first entering this tutorial should be 
	 done here, ie. tutorial specific initializations. 

PROTOTYPE:
	static boolean OnTextureBlendingRender(TutorI3D* pMe)

PARAMETERS:
	pMe [In] : Pointer to TutorI3D sturcture
	
DEPENDENCIES
  none

RETURN VALUE
  TRUE: If succeded
  FALSE: If there was an error

SIDE EFFECTS
  none
===========================================================================*/

static boolean OnTextureBlendingRender(TutorI3D* pMe)
{
	AEE3DTexture texture;

	/* set a default texture */
	pMe->textureID = IDB_TEXTURE_WOOD;
	
	texture.type = AEE3D_TEXTURE_DIFFUSED;
	texture.SamplingMode = AEE3D_TEXTURE_SAMPLING_NEAREST;
	texture.Wrap_s = AEE3D_TEXTURE_WRAP_REPEAT;
	texture.Wrap_t = AEE3D_TEXTURE_WRAP_REPEAT;
	texture.BorderColorIndex = 255;
	texture.pImage = ISHELL_LoadResBitmap(pMe->a.m_pIShell,TUTORI3D_RES_FILE,
										  pMe->textureID);
	
	if(!texture.pImage)
	{
		DBGPRINTF("Error: Resource not found");
	}
	else
	{

		I3D_SetTexture(pMe->m_p3D, &texture);
        IBITMAP_Release(texture.pImage);
	}
	
	// start with texture replace render mode 
	if(I3D_SetRenderMode(pMe->m_p3D, AEE3D_RENDER_TEXTURE_REPLACE) != SUCCESS)
	{
		DBGPRINTF("Error: setting render mode");
	}

		
	return TRUE;
}

/*===========================================================================

FUNCTION 
	OnTextureBlendingAlphaBlending

DESCRIPTION
	 This function is called when the alpha blending menu item 
	 is selected. Anything to do when first entering this tutorial should be 
	 done here, ie. tutorial specific initializations. 

PROTOTYPE:
	static boolean OnTextureBlendingAlphaBlending(TutorI3D* pMe)

PARAMETERS:
	pMe [In] : Pointer to TutorI3D sturcture
	
DEPENDENCIES
  none

RETURN VALUE
  TRUE: If succeded
  FALSE: If there was an error

SIDE EFFECTS
  none
===========================================================================*/
static boolean OnTextureBlendingAlphaBlending(TutorI3D* pMe)
{
	ObjType* model;
	// start in smooth shading render mode for this tutorial
	if(I3D_SetRenderMode(pMe->m_p3D, AEE3D_RENDER_SMOOTH_SHADING) != SUCCESS)
	{
		DBGPRINTF("Error: setting render mode");
	}

	// enable alpha blending
	if(I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_BLENDING, TRUE) != SUCCESS)
	{
		DBGPRINTF("Error: enabling alpha blending");
	}
	// set flag to indicate alpha blending enabled. 
	pMe->alphaEnabled = TRUE;

	model = TutorI3D_GetModel(pMe,pMe->drawModel);

	if(model)
	{	
		pMe->alphaValue = model->Model->a;	// use first vertex alpha as current alpha.
	}	
	else
		return FALSE;						// failed to get model
	
	
		
	return TRUE;
}

/*===========================================================================

FUNCTION 
	OnTextureBlendingPerspective

DESCRIPTION
	 This function is called when the perspective correction menu item 
	 is selected. Anything to do when first entering this tutorial should be 
	 done here, ie. tutorial specific initializations. 

PROTOTYPE:
	static boolean OnTextureBlendingPerspective(TutorI3D* pMe)

PARAMETERS:
	pMe [In] : Pointer to TutorI3D sturcture
	
DEPENDENCIES
  none

RETURN VALUE
  TRUE: If succeded
  FALSE: If there was an error

SIDE EFFECTS
  none
===========================================================================*/
static boolean OnTextureBlendingPerspective(TutorI3D* pMe)
{
	
	// start in smooth shading render mode for this tutorial
/*	if(I3D_SetRenderMode(pMe->m_p3D, AEE3D_RENDER_SMOOTH_SHADING) != SUCCESS)
	{
		DBGPRINTF("Error: setting render mode");
	}
*/
	// enable perspective correction
	if(I3D_Enable(pMe->m_p3D, AEE3D_CAPABILITY_PERSPECTIVE_CORRECTION, TRUE) != SUCCESS)
	{
		DBGPRINTF("Error: enabling perspective correction");
	}
	// set flag to indicate perspective correction enabled. 
	pMe->perspectiveCorrEnabled= TRUE;
	
	

	return TRUE;
}


/*===========================================================================

  FUNCTION: TexturesBlendingRenderManipulateBuf
  
	DESCRIPTION
	   This function adds text and 2D graphics to the frame buffer after
	   3D frame render is complete for the texture rendering tutorial.
	  
	PROTOTYPE:
	  void TexturesBlendingRenderManipulateBuf(TutorI3D* pMe)
		
	PARAMETERS:
	  pMe: [in]: Pointer to TutorI3D sturcture
	  		  
	DEPENDENCIES
	  none
				  
	RETURN VALUE
	  none
					
	SIDE EFFECTS
	  none
===========================================================================*/

void TexturesBlendingRenderManipulateBuf(TutorI3D* pMe)
{

	AECHAR szBuf[80];
	char chBuf[80];
	AEE3DRenderType renderType;
	AEE3DTexture	texture;
	
	
	//int8 colCharStart=-1;	// index of first color character on the line 
	IFont* oldFont;
	int oldFontHeight;
	RGBVAL rgb=0;
	int textWidth;
	
	int nLine=0;	// # of lines used to output text
	int maxWidth;
	int xText;
	int yText;

	if(!pMe)

⌨️ 快捷键说明

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