青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

隨筆 - 505  文章 - 1034  trackbacks - 0
<2007年2月>
28293031123
45678910
11121314151617
18192021222324
25262728123
45678910


子曾經曰過:編程無他,唯手熟爾!

常用鏈接

留言簿(94)

隨筆分類(649)

隨筆檔案(505)

相冊

BCB

Crytek

  • crymod
  • Crytek's Offical Modding Portal

Game Industry

OGRE

other

Programmers

Qt

WOW Stuff

搜索

  •  

積分與排名

  • 積分 - 923675
  • 排名 - 14

最新隨筆

最新評論

閱讀排行榜

評論排行榜


效果:


//-----------------------------------------------------------------------------
// File: Meshes.cpp
//
// Desc: For advanced geometry, most apps will prefer to load pre-authored
//       meshes from a file. Fortunately, when using meshes, D3DX does most of
//       the work for this, parsing a geometry file and creating vertx buffers
//       (and index buffers) for us. This tutorial shows how to use a D3DXMESH
//       object, including loading it from a file and rendering it. One thing
//       D3DX does not handle for us is the materials and textures for a mesh,
//       so note that we have to handle those manually.
//
//       Note: one advanced (but nice) feature that we don't show here is that
//       when cloning a mesh we can specify the FVF. So, regardless of how the
//       mesh was authored, we can add/remove normals, add more texture
//       coordinate sets (for multi-texturing), etc.
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#include <Windows.h>
#include 
<mmsystem.h>
#include 
<d3dx9.h>
#pragma warning( disable : 
4996 ) // disable deprecated warning 
#include <strsafe.h>
#pragma warning( 
default : 4996 ) 




//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
LPDIRECT3D9             g_pD3D           = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE9       g_pd3dDevice     = NULL; // Our rendering device

LPD3DXMESH              g_pMesh          
= NULL; // Our mesh object in sysmem
D3DMATERIAL9*           g_pMeshMaterials = NULL; // Materials for our mesh
LPDIRECT3DTEXTURE9*     g_pMeshTextures  = NULL; // Textures for our mesh
DWORD                   g_dwNumMaterials = 0L;   // Number of mesh materials




//-----------------------------------------------------------------------------
// Name: InitD3D()
// Desc: Initializes Direct3D
//-----------------------------------------------------------------------------
HRESULT InitD3D( HWND hWnd )
{
    
// Create the D3D object.
    if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )
        
return E_FAIL;

    
// Set up the structure used to create the D3DDevice. Since we are now
    
// using more complex geometry, we will create a device with a zbuffer.
    D3DPRESENT_PARAMETERS d3dpp; 
    ZeroMemory( 
&d3dpp, sizeof(d3dpp) );
    d3dpp.Windowed 
= TRUE;
    d3dpp.SwapEffect 
= D3DSWAPEFFECT_DISCARD;
    d3dpp.BackBufferFormat 
= D3DFMT_UNKNOWN;
    d3dpp.EnableAutoDepthStencil 
= TRUE;
    d3dpp.AutoDepthStencilFormat 
= D3DFMT_D16;

    
// Create the D3DDevice
    if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd,
                                      D3DCREATE_SOFTWARE_VERTEXPROCESSING,
                                      
&d3dpp, &g_pd3dDevice ) ) )
    {
        
return E_FAIL;
    }

    
// Turn on the zbuffer
    g_pd3dDevice->SetRenderState( D3DRS_ZENABLE, TRUE );

    
// Turn on ambient lighting 
    g_pd3dDevice->SetRenderState( D3DRS_AMBIENT, 0xffffffff );

    
return S_OK;
}

//-----------------------------------------------------------------------------
// Name: InitGeometry()
// Desc: Load the mesh and build the material and texture arrays
//-----------------------------------------------------------------------------
HRESULT InitGeometry()
{
    LPD3DXBUFFER pD3DXMtrlBuffer;

    
// Load the mesh from the specified file
    
// 從指定文件加載網格
    if( FAILED( D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM, 
                                   g_pd3dDevice, NULL, 
                                   
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, 
                                   
&g_pMesh ) ) )
    {
        
// If model is not in current folder, try parent folder
        if( FAILED( D3DXLoadMeshFromX( "..\\Tiger.x", D3DXMESH_SYSTEMMEM, 
                                    g_pd3dDevice, NULL, 
                                    
&pD3DXMtrlBuffer, NULL, &g_dwNumMaterials, 
                                    
&g_pMesh ) ) )
        {
            MessageBox(NULL, 
"Could not find tiger.x""Meshes.exe", MB_OK);
            
return E_FAIL;
        }
    }

    
// We need to extract the material properties and texture names from the 
    
// pD3DXMtrlBuffer
    
// 從pD3DXMtrlBuffer里面析取出材質屬性和紋理名字
    D3DXMATERIAL* d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
    g_pMeshMaterials 
= new D3DMATERIAL9[g_dwNumMaterials]; // 放材質
    if( g_pMeshMaterials == NULL )
        
return E_OUTOFMEMORY;
    g_pMeshTextures  
= new LPDIRECT3DTEXTURE9[g_dwNumMaterials]; // 放紋理
    if( g_pMeshTextures == NULL )
        
return E_OUTOFMEMORY;

    
for( DWORD i=0; i<g_dwNumMaterials; i++ )
    {
        
// Copy the material
        
// 拷貝材質
        g_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;

        
// Set the ambient color for the material (D3DX does not do this)
        g_pMeshMaterials[i].Ambient = g_pMeshMaterials[i].Diffuse;

        g_pMeshTextures[i] 
= NULL;
        
if( d3dxMaterials[i].pTextureFilename != NULL && 
            lstrlen(d3dxMaterials[i].pTextureFilename) 
> 0 )
        {
            
// Create the texture
            
// 創建紋理
            if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, 
                                                d3dxMaterials[i].pTextureFilename, 
                                                
&g_pMeshTextures[i] ) ) )
            {
                
// If texture is not in current folder, try parent folder
                const TCHAR* strPrefix = TEXT("..\\");
                TCHAR strTexture[MAX_PATH];
                StringCchCopy( strTexture, MAX_PATH, strPrefix );
                StringCchCat( strTexture, MAX_PATH, d3dxMaterials[i].pTextureFilename );
                
// If texture is not in current folder, try parent folder
                if( FAILED( D3DXCreateTextureFromFile( g_pd3dDevice, 
                                                    strTexture, 
                                                    
&g_pMeshTextures[i] ) ) )
                {
                    MessageBox(NULL, 
"Could not find texture map""Meshes.exe", MB_OK);
                }
            }
        }
    }

    
// Done with the material buffer
    pD3DXMtrlBuffer->Release();

    
return S_OK;
}


//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
    
if( g_pMeshMaterials != NULL ) 
        delete[] g_pMeshMaterials;

    
if( g_pMeshTextures )
    {
        
for( DWORD i = 0; i < g_dwNumMaterials; i++ )
        {
            
if( g_pMeshTextures[i] )
                g_pMeshTextures[i]
->Release();
        }
        delete[] g_pMeshTextures;
    }
    
if( g_pMesh != NULL )
        g_pMesh
->Release();
    
    
if( g_pd3dDevice != NULL )
        g_pd3dDevice
->Release();

    
if( g_pD3D != NULL )
        g_pD3D
->Release();
}



//-----------------------------------------------------------------------------
// Name: SetupMatrices()
// Desc: Sets up the world, view, and projection transform matrices.
//-----------------------------------------------------------------------------
VOID SetupMatrices()
{
    
// Set up world matrix
    D3DXMATRIXA16 matWorld;
    D3DXMatrixRotationY( 
&matWorld, timeGetTime()/1000.0f );
    g_pd3dDevice
->SetTransform( D3DTS_WORLD, &matWorld );

    
// Set up our view matrix. A view matrix can be defined given an eye point,
    
// a point to lookat, and a direction for which way is up. Here, we set the
    
// eye five units back along the z-axis and up three units, look at the 
    
// origin, and define "up" to be in the y-direction.
    D3DXVECTOR3 vEyePt( 0.0f3.0f,-5.0f );
    D3DXVECTOR3 vLookatPt( 
0.0f0.0f0.0f );
    D3DXVECTOR3 vUpVec( 
0.0f1.0f0.0f );
    D3DXMATRIXA16 matView;
    D3DXMatrixLookAtLH( 
&matView, &vEyePt, &vLookatPt, &vUpVec );
    g_pd3dDevice
->SetTransform( D3DTS_VIEW, &matView );

    
// For the projection matrix, we set up a perspective transform (which
    
// transforms geometry from 3D view space to 2D viewport space, with
    
// a perspective divide making objects smaller in the distance). To build
    
// a perpsective transform, we need the field of view (1/4 pi is common),
    
// the aspect ratio, and the near and far clipping planes (which define at
    
// what distances geometry should be no longer be rendered).
    D3DXMATRIXA16 matProj;
    D3DXMatrixPerspectiveFovLH( 
&matProj, D3DX_PI/41.0f1.0f100.0f );
    g_pd3dDevice
->SetTransform( D3DTS_PROJECTION, &matProj );
}




//-----------------------------------------------------------------------------
// Name: Render()
// Desc: Draws the scene
//-----------------------------------------------------------------------------
VOID Render()
{
    
// Clear the backbuffer and the zbuffer
    g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, 
                         D3DCOLOR_XRGB(
0,0,255), 1.0f0 );
    
    
// Begin the scene
    if( SUCCEEDED( g_pd3dDevice->BeginScene() ) )
    {
        
// Setup the world, view, and projection matrices
        SetupMatrices();

        
// Meshes are divided into subsets, one for each material. Render them in
        
// a loop
        
// 網格被劃分成子集,每個子集對應著一個材質
        for( DWORD i=0; i<g_dwNumMaterials; i++ )
        {
            
// Set the material and texture for this subset
            g_pd3dDevice->SetMaterial( &g_pMeshMaterials[i] );
            g_pd3dDevice
->SetTexture( 0, g_pMeshTextures[i] );
        
            
// Draw the mesh subset
            g_pMesh->DrawSubset( i );
        }

        
// End the scene
        g_pd3dDevice->EndScene();
    }

    
// Present the backbuffer contents to the display
    g_pd3dDevice->Present( NULL, NULL, NULL, NULL );
}




//-----------------------------------------------------------------------------
// Name: MsgProc()
// Desc: The window's message handler
//-----------------------------------------------------------------------------
LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
    
switch( msg )
    {
        
case WM_DESTROY:
            Cleanup();
            PostQuitMessage( 
0 );
            
return 0;
    }

    
return DefWindowProc( hWnd, msg, wParam, lParam );
}




//-----------------------------------------------------------------------------
// Name: WinMain()
// Desc: The application's entry point
//-----------------------------------------------------------------------------
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    
// Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L0L
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      
"D3D Tutorial", NULL };
    RegisterClassEx( 
&wc );

    
// Create the application's window
    HWND hWnd = CreateWindow( "D3D Tutorial""D3D Tutorial 06: Meshes"
                              WS_OVERLAPPEDWINDOW, 
100100300300,
                              NULL, NULL, wc.hInstance, NULL );

    
// Initialize Direct3D
    if( SUCCEEDED( InitD3D( hWnd ) ) )
    { 
        
// Create the scene geometry
        if( SUCCEEDED( InitGeometry() ) )
        {
            
// Show the window
            ShowWindow( hWnd, SW_SHOWDEFAULT );
            UpdateWindow( hWnd );

            
// Enter the message loop
            MSG msg; 
            ZeroMemory( 
&msg, sizeof(msg) );
            
while( msg.message!=WM_QUIT )
            {
                
if( PeekMessage( &msg, NULL, 0U0U, PM_REMOVE ) )
                {
                    TranslateMessage( 
&msg );
                    DispatchMessage( 
&msg );
                }
                
else
                    Render();
            }
        }
    }

    UnregisterClass( 
"D3D Tutorial", wc.hInstance );
    
return 0;
}

posted on 2007-02-16 18:28 七星重劍 閱讀(818) 評論(0)  編輯 收藏 引用 所屬分類: Game Graphics
青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲日韩成人| 在线综合亚洲欧美在线视频| 午夜激情亚洲| 国产伦精品一区二区三区| 亚洲在线一区二区| 亚洲一区久久| 国产一区二区日韩精品| 久久综合伊人| 欧美成年视频| 亚洲女性喷水在线观看一区| 亚洲字幕一区二区| 一区在线免费观看| 亚洲精品乱码久久久久久蜜桃91| 欧美激情综合亚洲一二区| 亚洲一区观看| 欧美一区三区三区高中清蜜桃| 国内揄拍国内精品少妇国语| 两个人的视频www国产精品| 男人插女人欧美| 亚洲天堂成人在线视频| 午夜在线电影亚洲一区| 亚洲国产成人精品久久久国产成人一区| 欧美电影免费观看网站| 欧美日韩中文精品| 久久久久久久久久久久久女国产乱| 久久精品视频在线| 99精品国产在热久久下载| 亚洲制服欧美中文字幕中文字幕| 国产在线观看91精品一区| 欧美成人精品一区| 国产精品一区视频网站| 欧美刺激性大交免费视频| 欧美午夜宅男影院在线观看| 久久综合九色99| 欧美日韩精品是欧美日韩精品| 久久精品中文字幕一区| 欧美精品一线| 久久夜色精品国产| 国产精品hd| 欧美激情成人在线| 国内综合精品午夜久久资源| 亚洲日韩欧美一区二区在线| 国内精品久久久久久影视8| 99精品视频一区| 亚洲国产欧美国产综合一区| 亚洲欧美成人在线| 一本一本a久久| 麻豆精品在线视频| 久久狠狠亚洲综合| 国产精品久久久久77777| 免费日韩视频| 亚洲激情视频在线| 午夜一区二区三区不卡视频| 久久精品二区| 午夜久久黄色| 欧美日韩国产限制| 亚洲缚视频在线观看| 韩日欧美一区二区三区| 亚洲小视频在线观看| 日韩一级不卡| 欧美精品亚洲二区| 欧美国产日韩在线| 亚洲高清免费| 久久综合伊人77777麻豆| 久久久久久精| 好吊色欧美一区二区三区四区| 亚洲欧美日韩综合aⅴ视频| 亚洲网站视频福利| 欧美深夜影院| 亚洲午夜精品视频| 午夜精品福利在线| 国产精品亚发布| 午夜电影亚洲| 久久久亚洲国产美女国产盗摄| 国产欧美日韩视频一区二区三区 | 欧美寡妇偷汉性猛交| 激情一区二区| 久久伊人精品天天| 欧美高清免费| 一区二区三区导航| 国产精品毛片| 欧美一区二区三区婷婷月色 | 亚洲女同在线| 国产手机视频精品| 久久精品亚洲| 最新国产精品拍自在线播放| 亚洲少妇诱惑| 国产午夜精品全部视频在线播放| 欧美在线视频免费播放| 美国十次了思思久久精品导航| 亚洲国产精品视频一区| 欧美精品在线观看91| 亚洲一区二区三区在线| 美日韩精品免费| 日韩一二三在线视频播| 国产精品一区二区在线观看不卡| 久久久精品动漫| 亚洲茄子视频| 欧美制服丝袜第一页| 亚洲第一精品福利| 国产精品国产三级国产专播精品人 | 黑人巨大精品欧美黑白配亚洲 | 香蕉久久夜色精品| 欧美承认网站| 亚洲欧美中日韩| 亚洲二区视频| 国产精品一区二区黑丝| 欧美成人激情视频免费观看| 亚洲一区二区欧美| 欧美激情性爽国产精品17p| 亚洲专区免费| 亚洲国产日韩一区| 国产欧美亚洲日本| 欧美日韩亚洲另类| 久久综合激情| 午夜精品一区二区三区在线播放| 亚洲国产一区二区三区青草影视 | 欧美一区亚洲一区| 亚洲日本电影在线| 国产主播在线一区| 国产精品欧美久久| 欧美金8天国| 另类春色校园亚洲| 欧美在线一级va免费观看| 99爱精品视频| 亚洲国内在线| 欧美激情亚洲自拍| 久久精品91| 亚洲私人影院在线观看| 在线国产欧美| 亚洲日本在线视频观看| 久久久久国色av免费观看性色| 一本色道久久加勒比精品 | 久久综合亚州| 欧美一激情一区二区三区| 一本久道久久综合狠狠爱| 欧美国产精品劲爆| 欧美国产三区| 欧美激情一区二区| 欧美国产日韩在线观看| 麻豆精品视频在线观看| 久久精品一级爱片| 午夜精品理论片| 午夜一区二区三视频在线观看| 亚洲天堂免费观看| 亚洲午夜精品| 一本色道久久综合亚洲精品按摩 | 亚洲欧美日韩视频二区| 亚洲视频一区二区| 在线一区亚洲| 亚洲性夜色噜噜噜7777| 亚洲午夜国产成人av电影男同| 日韩一级精品视频在线观看| 亚洲精品乱码久久久久久蜜桃91| 亚洲高清av| 日韩视频―中文字幕| 亚洲精品一区二区三区四区高清| 亚洲黄网站在线观看| 亚洲欧洲日夜超级视频| 99在线精品视频| 亚洲性感激情| 久久成人久久爱| 鲁大师成人一区二区三区| 蜜臀久久久99精品久久久久久| 猛男gaygay欧美视频| 亚洲二区精品| 一区二区欧美日韩| 亚洲欧美日韩综合国产aⅴ| 久久国产精品久久久| 六月婷婷一区| 国产精品99免视看9| 国产亚洲成av人片在线观看桃| 亚洲成人自拍视频| 一区二区高清视频| 久久国产88| 亚洲国产精品精华液网站| 在线一区二区视频| 久久久国产精品一区二区中文| 欧美激情一区二区三区不卡| 欧美视频中文字幕在线| 韩日视频一区| 亚洲视频一二| 麻豆久久精品| 制服丝袜激情欧洲亚洲| 久久久久国产一区二区| 欧美日韩一区高清| 激情六月综合| 亚洲欧美激情一区二区| 欧美v日韩v国产v| 亚洲综合日本| 欧美女主播在线| 1000精品久久久久久久久| 亚洲在线视频观看| 欧美韩国一区| 久久成人免费电影| 国产精品视频yy9099| 亚洲精品字幕| 免费欧美高清视频| 午夜精品免费在线| 国产精品久久二区|