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

📄 winmain.cpp

📁 大家好!这是一个网络游戏源码
💻 CPP
字号:
//-----------------------------------------------------------------------------
//  File: WinMain.cpp

//-----------------------------------------------------------------------------



#include <windows.h>
#include <math.h>
#include <stdio.h>

#include "runner_game.h"

#include "graph.h"
#include "D3D_app.h"
#include "game_editor.h" 
#include "d3dx.h"

#include "resource.h"
 
GAME_EDITOR		*g_pEditor = NULL;

//-----------------------------------------------------------------------------
// Name: class MY_D3D_APP
// Desc: Application class. The base class provides just about all the
//       functionality we want, so we're just supplying stubs to interface with
//       the non-C++ functions of the app.
//-----------------------------------------------------------------------------

class MY_D3D_APP : public D3D_APP
{
protected:
    HRESULT OneTimeSceneInit();
    HRESULT InitDeviceObjects();
    HRESULT DeleteDeviceObjects();
    HRESULT Render();
    HRESULT FrameMove( FLOAT fTimeKey );
    HRESULT FinalCleanup();
    VOID    CheckKeyState();
public:
    MY_D3D_APP();
    LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
};




//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: Entry point to the program. Initializes everything, and goes into a
//       message-processing loop. Idle time is used to render the scene.
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR strCmdLine, INT )
{
    InitRunner();
	
	Out("%s\n" , "Program Begin");
	MY_D3D_APP d3dApp;

    if( FAILED( d3dApp.Create( hInst, strCmdLine ) ) )
        return 0;

    Out("%s\n" , "App Created succesful , Now Running...");
	return d3dApp.Run();
}




//-----------------------------------------------------------------------------
// Name: CMyD3DApplication()
// Desc: Application constructor. Sets attributes for the app.
//-----------------------------------------------------------------------------
MY_D3D_APP::MY_D3D_APP():D3D_APP()
{
    m_strWindowTitle  = TEXT( "Runner Test I" );
    m_bAppUseZBuffer  = TRUE;
    m_bShowStats      = TRUE;
    m_fnConfirmDevice = NULL;
}


//-----------------------------------------------------------------------------
// Name: OneTimeSceneInit()
// Desc: Called during initial app startup, this function performs all the
//       permanent initialization.
//-----------------------------------------------------------------------------
HRESULT MY_D3D_APP::OneTimeSceneInit()
{
    
	//D3DUtil_SetIdentityMatrix( m_matSave );
    //D3DUtil_SetIdentityMatrix( m_matRotate );
    return S_OK;
}

	
//-----------------------------------------------------------------------------
// Name: FrameMove()
// Desc: Called once per frame, the call is the entry point for animating
//       the scene.
//-----------------------------------------------------------------------------
HRESULT MY_D3D_APP::FrameMove( FLOAT fTimeKey )
{
	
	g_pEditor->Run();
	
	//g_pSceneView->SetView();
	//g_pSceneView->CaluGridInfo();
	
	return S_OK;
}




//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Called once per frame, the call is the entry point for 3d
//       rendering. This function sets up render states, clears the
//       viewport, and renders the scene.
//-----------------------------------------------------------------------------
HRESULT MY_D3D_APP::Render()
{
    
	// Clear the viewport
    m_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER,
                         RGB(128 , 128 , 128) , 1.0f, 0L );
	// Begin the scene 
    if( SUCCEEDED( m_pd3dDevice->BeginScene() ) )
    {
     	g_pEditor->DrawAll();
		
		m_pd3dDevice->EndScene(); 
    } 

    return S_OK; 
}


//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: Initialize scene objects.
//-----------------------------------------------------------------------------

HRESULT MY_D3D_APP::InitDeviceObjects()
{
    // Load a DirectX .X file the first time around----------------------------------------------------------------------------------------------	

	static BOOL bFirstInstance = TRUE;
    if( bFirstInstance ) 
    {
        Pause( TRUE );
        
		D3DXInitialize(); 
	
		InitGeneralColor();
		GetMemoryI(g_pEditor , GAME_EDITOR);
		g_pEditor->Init();
		
		
		Pause( FALSE );
        bFirstInstance = FALSE; 
    }

    // Setup a material
    D3DMATERIAL7 mtrl;
    D3DUtil_InitMaterial( mtrl, 1.0f, 1.0f, 1.0f);
    mtrl.diffuse.a = 0.2f;
	mtrl.ambient.a = 0.2f;
	
	m_pd3dDevice->SetMaterial( &mtrl );

    // Setup the textures
    //D3DTextr_RestoreAllTextures( m_pd3dDevice );
    
	m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_COLOROP,   D3DTOP_MODULATE );
    
	m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MINFILTER, D3DTFN_POINT );
    m_pd3dDevice->SetTextureStageState( 0, D3DTSS_MAGFILTER, D3DTFG_POINT );
    
	m_pd3dDevice->SetRenderState( D3DRENDERSTATE_DITHERENABLE,   TRUE );
    m_pd3dDevice->SetRenderState( D3DRENDERSTATE_SPECULARENABLE, FALSE );
    m_pd3dDevice->SetRenderState( D3DRENDERSTATE_ZENABLE,        TRUE );
    m_pd3dDevice->SetRenderState( D3DRENDERSTATE_NORMALIZENORMALS, TRUE );

    m_pd3dDevice->SetRenderState( D3DRENDERSTATE_CULLMODE,  D3DCULL_NONE);
	m_pd3dDevice->SetRenderState( D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD );
	m_pd3dDevice->SetRenderState( D3DRENDERSTATE_FILLMODE,  D3DFILL_SOLID );
		
	
	// Set the projection matrix
    D3DVIEWPORT7 vp;
    m_pd3dDevice->GetViewport(&vp);
    FLOAT fAspect = ((FLOAT)vp.dwHeight) / vp.dwWidth;

    D3DMATRIX matProj;
    D3DUtil_SetProjectionMatrix( matProj, g_PI/4, fAspect, 1.0f, 100 );
    m_pd3dDevice->SetTransform( D3DTRANSFORMSTATE_PROJECTION, &matProj );
  
    
	// Set up the light
    
	if( m_pDeviceInfo->ddDeviceDesc.dwVertexProcessingCaps &
                                                D3DVTXPCAPS_DIRECTIONALLIGHTS )
    {
        D3DLIGHT7 light;
        D3DUtil_InitLight( light, D3DLIGHT_DIRECTIONAL, 0.0f, -1.0f, -1.0f );
        m_pd3dDevice->SetLight( 0, &light );
        m_pd3dDevice->LightEnable( 0, TRUE );
        m_pd3dDevice->SetRenderState( D3DRENDERSTATE_LIGHTING, TRUE );
        m_pd3dDevice->SetRenderState(  D3DRENDERSTATE_AMBIENT, 0x00000000 );
    }
    else
	m_pd3dDevice->SetRenderState(  D3DRENDERSTATE_AMBIENT, 0xffffffff );
	//m_pd3dDevice->SetRenderState( D3DRENDERSTATE_LIGHTING, FALSE);
    
    return S_OK;
}




//-----------------------------------------------------------------------------
// Name: CMyD3DApplication::DeleteDeviceObjects()
// Desc: Called when the app is exitting, or the device is being changed,
//       this function deletes any device dependant objects.
//-----------------------------------------------------------------------------
HRESULT MY_D3D_APP::DeleteDeviceObjects()
{
    g_pEditor->ReleaseDeviceObj();
	
	return S_OK;
}




//-----------------------------------------------------------------------------
// Name: FinalCleanup()
// Desc: Called before the app exits, this function gives the app the chance
//       to cleanup after itself.
//-----------------------------------------------------------------------------
HRESULT MY_D3D_APP::FinalCleanup()
{
	g_pEditor->Release();
	EndRunner(); 
	
	D3DXUninitialize();  
	return S_OK;   
}




//----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: App custom WndProc function for handling mouse and keyboard input.
//----------------------------------------------------------------------------
LRESULT MY_D3D_APP::MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam,
                                    LPARAM lParam )
{
    switch( uMsg )
    {
        case WM_COMMAND:
            break;
		case WM_LBUTTONDOWN:
            {
			 	g_pEditor->HandleMouse(1);
				break;
			}
		case WM_RBUTTONDOWN:
			{
				g_pEditor->HandleMouse(2);
				break;
			}
		case WM_LBUTTONUP:
			break;
		case WM_KEYDOWN:
			{
				CheckKeyState();
				break;
			}

    }

    // Fall through to the app's main windows proc function
    return D3D_APP::MsgProc( hWnd, uMsg, wParam, lParam );
}

VOID MY_D3D_APP::CheckKeyState()	{}

⌨️ 快捷键说明

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