亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? d3dxcreatemeshfvf.cpp

?? Direct 9.0 游戲編程 包括PDF書籍和源代碼
?? CPP
字號:
//////////////////////////////////////////////////////////////////////////////////////////////////
// 
// File: d3dxcreatemeshfvf.cpp
// 
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0 
//
// Desc: Demonstrates how to create an empty ID3DXMesh object with D3DXCreateMeshFVF, 
//       how to fill the vertex, index, and attribute buffers, how to optimize a mesh
//       and gnerate an attribute table, and how to render it.
//          
//////////////////////////////////////////////////////////////////////////////////////////////////

#include "d3dUtility.h"
#include <fstream>
#include <vector>

//
// Globals
//

IDirect3DDevice9* Device = 0; 

const int Width  = 640;
const int Height = 480;

ID3DXMesh*         Mesh = 0;
const DWORD        NumSubsets = 3;
IDirect3DTexture9* Textures[3] = {0, 0, 0};// texture for each subset

std::ofstream OutFile; // used to dump mesh data to file

//
// Prototypes
//

void dumpVertices(std::ofstream& outFile, ID3DXMesh* mesh);
void dumpIndices(std::ofstream& outFile, ID3DXMesh* mesh);
void dumpAttributeBuffer(std::ofstream& outFile, ID3DXMesh* mesh);
void dumpAdjacencyBuffer(std::ofstream& outFile, ID3DXMesh* mesh);
void dumpAttributeTable(std::ofstream& outFile, ID3DXMesh* mesh);

//
// Classes and Structures
//
struct Vertex
{
	Vertex(){}
	Vertex(float x, float y, float z, 
		float nx, float ny, float nz, float u, float v)
	{
		 _x = x;   _y = y;   _z = z;
		_nx = nx; _ny = ny; _nz = nz;
		 _u = u;   _v = v;
	}

	float _x, _y, _z, _nx, _ny, _nz, _u, _v;

	static const DWORD FVF;
};
const DWORD Vertex::FVF = D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1;

//
// Framework functions
//
bool Setup()
{
	HRESULT hr = 0;

	//
	// We are going to fill the empty mesh with the geometry of a box,
	// so we need 12 triangles and 24 vetices.
	//

	hr = D3DXCreateMeshFVF(
		12,
		24,
		D3DXMESH_MANAGED,
		Vertex::FVF,
		Device,
		&Mesh);

	if(FAILED(hr))
	{
		::MessageBox(0, "D3DXCreateMeshFVF() - FAILED", 0, 0);
		return false;
	}

	//
	// Fill in vertices of a box
	//
	Vertex* v = 0;
	Mesh->LockVertexBuffer(0, (void**)&v);

	// fill in the front face vertex data
	v[0] = Vertex(-1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 0.0f);
	v[1] = Vertex(-1.0f,  1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 0.0f, 1.0f);
	v[2] = Vertex( 1.0f,  1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 1.0f);
	v[3] = Vertex( 1.0f, -1.0f, -1.0f, 0.0f, 0.0f, -1.0f, 1.0f, 0.0f);

	// fill in the back face vertex data
	v[4] = Vertex(-1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f);
	v[5] = Vertex( 1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f);
	v[6] = Vertex( 1.0f,  1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f);
	v[7] = Vertex(-1.0f,  1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f);

	// fill in the top face vertex data
	v[8]  = Vertex(-1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f);
	v[9]  = Vertex(-1.0f, 1.0f,  1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f);
	v[10] = Vertex( 1.0f, 1.0f,  1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f);
	v[11] = Vertex( 1.0f, 1.0f, -1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f);

	// fill in the bottom face vertex data
	v[12] = Vertex(-1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 0.0f);
	v[13] = Vertex( 1.0f, -1.0f, -1.0f, 0.0f, -1.0f, 0.0f, 0.0f, 1.0f);
	v[14] = Vertex( 1.0f, -1.0f,  1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 1.0f);
	v[15] = Vertex(-1.0f, -1.0f,  1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f);

	// fill in the left face vertex data
	v[16] = Vertex(-1.0f, -1.0f,  1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	v[17] = Vertex(-1.0f,  1.0f,  1.0f, -1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
	v[18] = Vertex(-1.0f,  1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 1.0f);
	v[19] = Vertex(-1.0f, -1.0f, -1.0f, -1.0f, 0.0f, 0.0f, 1.0f, 0.0f);

	// fill in the right face vertex data
	v[20] = Vertex( 1.0f, -1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
	v[21] = Vertex( 1.0f,  1.0f, -1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
	v[22] = Vertex( 1.0f,  1.0f,  1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f);
	v[23] = Vertex( 1.0f, -1.0f,  1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);

	Mesh->UnlockVertexBuffer();

	//
	// Define the triangles of the box
	//
	WORD* i = 0;
	Mesh->LockIndexBuffer(0, (void**)&i);

	// fill in the front face index data
	i[0] = 0; i[1] = 1; i[2] = 2;
	i[3] = 0; i[4] = 2; i[5] = 3;

	// fill in the back face index data
	i[6] = 4; i[7]  = 5; i[8]  = 6;
	i[9] = 4; i[10] = 6; i[11] = 7;

	// fill in the top face index data
	i[12] = 8; i[13] =  9; i[14] = 10;
	i[15] = 8; i[16] = 10; i[17] = 11;

	// fill in the bottom face index data
	i[18] = 12; i[19] = 13; i[20] = 14;
	i[21] = 12; i[22] = 14; i[23] = 15;

	// fill in the left face index data
	i[24] = 16; i[25] = 17; i[26] = 18;
	i[27] = 16; i[28] = 18; i[29] = 19;

	// fill in the right face index data
	i[30] = 20; i[31] = 21; i[32] = 22;
	i[33] = 20; i[34] = 22; i[35] = 23;

	Mesh->UnlockIndexBuffer();

	//
	// Specify the subset each triangle belongs to, in this example
	// we will use three subsets, the first two faces of the cube specified
	// will be in subset 0, the next two faces will be in subset 1 and
	// the the last two faces will be in subset 2.
	//
	DWORD* attributeBuffer = 0;
	Mesh->LockAttributeBuffer(0, &attributeBuffer);

	for(int a = 0; a < 4; a++)
		attributeBuffer[a] = 0;

	for(int b = 4; b < 8; b++)
		attributeBuffer[b] = 1;

	for(int c = 8; c < 12; c++)
		attributeBuffer[c] = 2;

	Mesh->UnlockAttributeBuffer();

	//
	// Optimize the mesh to generate an attribute table.
	//

	std::vector<DWORD> adjacencyBuffer(Mesh->GetNumFaces() * 3);
	Mesh->GenerateAdjacency(0.0f, &adjacencyBuffer[0]);

	hr = Mesh->OptimizeInplace(		
		D3DXMESHOPT_ATTRSORT |
		D3DXMESHOPT_COMPACT  |
		D3DXMESHOPT_VERTEXCACHE,
		&adjacencyBuffer[0],
		0, 0, 0);

	//
	// Dump the Mesh Data to file.
	//

	OutFile.open("Mesh Dump.txt");

	dumpVertices(OutFile, Mesh);
	dumpIndices(OutFile, Mesh);
	dumpAttributeTable(OutFile, Mesh); 	
	dumpAttributeBuffer(OutFile, Mesh);		
	dumpAdjacencyBuffer(OutFile, Mesh);
	
	OutFile.close();

	//
	// Load the textures and set filters.
	//

	D3DXCreateTextureFromFile(
		Device,
		"brick0.jpg",
		&Textures[0]);

	D3DXCreateTextureFromFile(
		Device,
		"brick1.jpg",
		&Textures[1]);

	D3DXCreateTextureFromFile(
		Device,
		"checker.jpg",
		&Textures[2]);

	Device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
	Device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);

	// 
	// Disable lighting.
	//

	Device->SetRenderState(D3DRS_LIGHTING, false);

	//
	// Set camera.
	//

	D3DXVECTOR3 pos(0.0f, 0.f, -4.0f);
	D3DXVECTOR3 target(0.0f, 0.0f, 0.0f);
	D3DXVECTOR3 up(0.0f, 1.0f, 0.0f);

	D3DXMATRIX V;
	D3DXMatrixLookAtLH(
		&V,
		&pos,
		&target,
		&up);

	Device->SetTransform(D3DTS_VIEW, &V);

	//
	// Set projection matrix.
	//

	D3DXMATRIX proj;
	D3DXMatrixPerspectiveFovLH(
			&proj,
			D3DX_PI * 0.5f, // 90 - degree
			(float)Width / (float)Height,
			1.0f,
			1000.0f);
	Device->SetTransform(D3DTS_PROJECTION, &proj);

	return true;
}

void Cleanup()
{
	d3d::Release<ID3DXMesh*>(Mesh);
	d3d::Release<IDirect3DTexture9*>(Textures[0]);
	d3d::Release<IDirect3DTexture9*>(Textures[1]);
	d3d::Release<IDirect3DTexture9*>(Textures[2]);
}

bool Display(float timeDelta)
{
	if( Device )
	{
		//
		// Update: Rotate the cube.
		//

		D3DXMATRIX xRot;
		D3DXMatrixRotationX(&xRot, D3DX_PI * 0.2f);

		static float y = 0.0f;
		D3DXMATRIX yRot;
		D3DXMatrixRotationY(&yRot, y);
		y += timeDelta;

		if( y >= 6.28f )
			y = 0.0f;

		D3DXMATRIX World = xRot * yRot;

		Device->SetTransform(D3DTS_WORLD, &World);

		//
		// Render
		//

		Device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0x00000000, 1.0f, 0);
		Device->BeginScene();

		for(int i = 0; i < NumSubsets; i++)
		{
			Device->SetTexture( 0, Textures[i] );
			Mesh->DrawSubset( i );
		}

		Device->EndScene();
		Device->Present(0, 0, 0, 0);
	}
	return true;
}

//
// WndProc
//
LRESULT CALLBACK d3d::WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch( msg )
	{
	case WM_DESTROY:
		::PostQuitMessage(0);
		break;
		
	case WM_KEYDOWN:
		if( wParam == VK_ESCAPE )
			::DestroyWindow(hwnd);
		break;
	}
	return ::DefWindowProc(hwnd, msg, wParam, lParam);
}

//
// WinMain
//
int WINAPI WinMain(HINSTANCE hinstance,
				   HINSTANCE prevInstance, 
				   PSTR cmdLine,
				   int showCmd)
{
	if(!d3d::InitD3D(hinstance,
		Width, Height, true, D3DDEVTYPE_HAL, &Device))
	{
		::MessageBox(0, "InitD3D() - FAILED", 0, 0);
		return 0;
	}
		
	if(!Setup())
	{
		::MessageBox(0, "Setup() - FAILED", 0, 0);
		return 0;
	}

	d3d::EnterMsgLoop( Display );

	Cleanup();

	Device->Release();

	return 0;
}

//
// Prototype Implementations
//

void dumpVertices(std::ofstream& outFile, ID3DXMesh* mesh)
{
	outFile << "Vertices:" << std::endl;
	outFile << "---------" << std::endl << std::endl;

	Vertex* v = 0;
	mesh->LockVertexBuffer(0, (void**)&v);
	for(int i = 0; i < mesh->GetNumVertices(); i++)
	{
		outFile << "Vertex " << i << ": (";
		outFile << v[i]._x  << ", " << v[i]._y  << ", " << v[i]._z  << ", ";
		outFile << v[i]._nx << ", " << v[i]._ny << ", " << v[i]._nz << ", ";
		outFile << v[i]._u  << ", " << v[i]._v  << ")"  << std::endl;
	}
	mesh->UnlockVertexBuffer();

	outFile << std::endl << std::endl;
}

void dumpIndices(std::ofstream& outFile, ID3DXMesh* mesh)
{
	outFile << "Indices:" << std::endl;
	outFile << "--------" << std::endl << std::endl;

	WORD* indices = 0;
	mesh->LockIndexBuffer(0, (void**)&indices);

	for(int i = 0; i < mesh->GetNumFaces(); i++)
	{
		outFile << "Triangle " << i << ": ";
		outFile << indices[i * 3    ] << " ";
		outFile << indices[i * 3 + 1] << " ";
		outFile << indices[i * 3 + 2] << std::endl;
	}
	mesh->UnlockIndexBuffer();

	outFile << std::endl << std::endl;
}

void dumpAttributeBuffer(std::ofstream& outFile, ID3DXMesh* mesh)
{
	outFile << "Attribute Buffer:" << std::endl;
	outFile << "-----------------" << std::endl << std::endl;

	DWORD* attributeBuffer = 0;
	mesh->LockAttributeBuffer(0, &attributeBuffer);

	// an attribute for each face
	for(int i = 0; i < mesh->GetNumFaces(); i++)
	{
		outFile << "Triangle lives in subset " << i << ": ";
		outFile << attributeBuffer[i] << std::endl;
	}
	mesh->UnlockAttributeBuffer();

	outFile << std::endl << std::endl;
}

void dumpAdjacencyBuffer(std::ofstream& outFile, ID3DXMesh* mesh)
{
	outFile << "Adjacency Buffer:" << std::endl;
	outFile << "-----------------" << std::endl << std::endl;

	// three enttries per face
	std::vector<DWORD> adjacencyBuffer(mesh->GetNumFaces() * 3);

	mesh->GenerateAdjacency(0.0f, &adjacencyBuffer[0]);

	for(int i = 0; i < mesh->GetNumFaces(); i++)
	{
		outFile << "Triangle's adjacent to triangle " << i << ": ";
		outFile << adjacencyBuffer[i * 3    ] << " ";
		outFile << adjacencyBuffer[i * 3 + 1] << " ";
		outFile << adjacencyBuffer[i * 3 + 2] << std::endl;
	}

	outFile << std::endl << std::endl;
}

void dumpAttributeTable(std::ofstream& outFile, ID3DXMesh* mesh)
{
	outFile << "Attribute Table:" << std::endl;
	outFile << "----------------" << std::endl << std::endl;	

	// number of entries in the attribute table
	DWORD numEntries = 0;

	mesh->GetAttributeTable(0, &numEntries);

	std::vector<D3DXATTRIBUTERANGE> table(numEntries);

	mesh->GetAttributeTable(&table[0], &numEntries);

	for(int i = 0; i < numEntries; i++)
	{
		outFile << "Entry " << i << std::endl;
		outFile << "-----------" << std::endl;

		outFile << "Subset ID:    " << table[i].AttribId    << std::endl;
		outFile << "Face Start:   " << table[i].FaceStart   << std::endl;
		outFile << "Face Count:   " << table[i].FaceCount   << std::endl;
		outFile << "Vertex Start: " << table[i].VertexStart << std::endl;
		outFile << "Vertex Count: " << table[i].VertexCount << std::endl;
		outFile << std::endl;
	}

	outFile << std::endl << std::endl;
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲人妖av一区二区| 全国精品久久少妇| 国产**成人网毛片九色| 久久一区二区视频| 成人高清视频在线| 亚洲欧洲在线观看av| 在线观看91视频| 毛片av一区二区| 国产欧美日韩在线观看| 色一情一伦一子一伦一区| 一区二区三区在线视频播放| 欧美日韩国产首页在线观看| 国产一区二区导航在线播放| 久久精品水蜜桃av综合天堂| 99亚偷拍自图区亚洲| 日本不卡一区二区三区高清视频| 久久综合久久99| 欧洲精品一区二区| 九九**精品视频免费播放| 亚洲国产一区二区a毛片| 久久久精品tv| 欧美久久久久久久久中文字幕| 国产精品一区二区在线播放 | 国产精品视频免费| 欧美色视频在线观看| 粉嫩av一区二区三区粉嫩| 亚洲欧美日本在线| 精品日韩99亚洲| 91精品国产一区二区三区| 99久久国产综合精品色伊| 免费人成精品欧美精品| 日本aⅴ免费视频一区二区三区| 亚洲午夜精品网| 国产精品久久久久久久久图文区 | 在线电影国产精品| 欧美日韩精品免费| 欧美日韩大陆一区二区| 色欧美88888久久久久久影院| 91在线视频网址| 91女人视频在线观看| 波波电影院一区二区三区| 一本大道综合伊人精品热热| 色偷偷88欧美精品久久久| 一本色道亚洲精品aⅴ| 色88888久久久久久影院野外| 欧美综合色免费| 欧美大尺度电影在线| 国产午夜精品一区二区三区嫩草 | 久久青草国产手机看片福利盒子| 精品久久人人做人人爱| 国产欧美va欧美不卡在线| 中文字幕中文乱码欧美一区二区 | 午夜久久久久久| 国精品**一区二区三区在线蜜桃| 久久精品国产亚洲5555| gogo大胆日本视频一区| 在线不卡a资源高清| 国产精品色眯眯| 五月天激情综合网| 一本一本大道香蕉久在线精品 | 国产精品网站在线播放| 亚洲国产wwwccc36天堂| 精品一区二区三区的国产在线播放| 国产九色sp调教91| 日韩视频免费观看高清完整版在线观看 | 婷婷中文字幕一区三区| 欧美aaa在线| 欧美日韩在线综合| 亚洲手机成人高清视频| 亚洲三级在线免费观看| 国产美女在线观看一区| 欧美美女黄视频| 亚洲天堂福利av| 99热精品一区二区| 国产精品美女一区二区在线观看| 亚洲最色的网站| 欧美在线观看一区| 亚洲理论在线观看| 97精品超碰一区二区三区| 日本一区二区三区久久久久久久久不 | 制服.丝袜.亚洲.另类.中文| 蜜桃视频第一区免费观看| 三级在线观看一区二区| 日韩伦理电影网| 三级一区在线视频先锋| 国产一区二区久久| 精品少妇一区二区三区视频免付费 | 亚洲欧美另类在线| 精品视频一区三区九区| 青娱乐精品视频| 亚洲人成网站色在线观看| 欧美大片在线观看| www.爱久久.com| 奇米在线7777在线精品| 亚洲欧洲日韩综合一区二区| 日韩欧美一区在线观看| 欧美羞羞免费网站| 99久久精品国产导航| 国产aⅴ综合色| 久久精品国产99国产| 亚洲二区在线视频| 日本一区二区动态图| 日韩欧美综合在线| 欧美久久久久免费| 在线免费一区三区| 91色婷婷久久久久合中文| 国产.欧美.日韩| 久久电影网电视剧免费观看| 日本91福利区| 青娱乐精品视频在线| 亚洲成人1区2区| 亚洲成av人影院在线观看网| 亚洲人精品一区| 亚洲人精品午夜| 亚洲欧美怡红院| 1区2区3区国产精品| 精品久久久久久综合日本欧美| 日韩免费观看高清完整版在线观看| 欧洲色大大久久| 欧美色爱综合网| 欧美精品乱码久久久久久| 在线观看免费亚洲| 欧美日韩一区久久| 欧美精品日韩一本| 91精品国产综合久久精品app | 国产精品一区免费在线观看| 狠狠久久亚洲欧美| 国产精品综合一区二区| 国产精品亚洲成人| 成人av在线影院| 日本高清视频一区二区| 欧美日韩中文字幕一区二区| 欧美三级中文字| 欧美一激情一区二区三区| 精品美女在线播放| 国产精品卡一卡二| 一二三四社区欧美黄| 日韩精品免费专区| 国产一级精品在线| 色先锋aa成人| 欧美精品第一页| 久久免费美女视频| 亚洲视频在线观看三级| 午夜一区二区三区视频| 精品无码三级在线观看视频| 国产高清久久久| 欧美影院一区二区三区| 日韩欧美国产一区二区三区| 久久久久国产精品厨房| 一区二区三区精品在线| 蜜臀av性久久久久蜜臀aⅴ| 国产精品亚洲一区二区三区妖精| 91亚洲大成网污www| 欧美一区午夜精品| 国产婷婷色一区二区三区| 夜夜精品浪潮av一区二区三区| 午夜精品久久一牛影视| 国产91在线观看丝袜| 在线视频国产一区| 欧美白人最猛性xxxxx69交| 最新热久久免费视频| 奇米影视一区二区三区小说| 成人国产精品免费观看视频| 欧美一区二区三区视频免费播放| 国产精品丝袜91| 丝瓜av网站精品一区二区| 懂色av一区二区三区免费看| 欧美美女一区二区在线观看| 国产欧美日韩中文久久| 日本女优在线视频一区二区| 本田岬高潮一区二区三区| 日韩一区二区三区四区五区六区| 亚洲精品乱码久久久久久| 久久国产免费看| 91久久精品一区二区二区| 久久综合久久久久88| 亚洲一二三四区不卡| 波多野结衣一区二区三区 | 免费在线观看成人| 日本精品视频一区二区三区| 国产色综合一区| 理论片日本一区| 欧美日本在线观看| 一级日本不卡的影视| 国产精品系列在线播放| 91精品国产欧美日韩| 亚洲综合一区二区| 91视频国产观看| 国产精品网站导航| 成人在线视频首页| 国产欧美日本一区视频| 久久99精品国产麻豆婷婷洗澡| 欧美日韩一卡二卡三卡 | 国产婷婷一区二区| 韩国女主播成人在线| 欧美精品色一区二区三区| 亚洲成人免费视频| 欧美日韩国产综合一区二区| 亚洲人成在线播放网站岛国 | 亚洲欧美另类图片小说|