当前位置: 首页>>代码示例>>C++>>正文


C++ LPDIRECT3DDEVICE9类代码示例

本文整理汇总了C++中LPDIRECT3DDEVICE9的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DDEVICE9类的具体用法?C++ LPDIRECT3DDEVICE9怎么用?C++ LPDIRECT3DDEVICE9使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了LPDIRECT3DDEVICE9类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Render

//-------------------------------------------------------------
// ȭ�鷻��
//-------------------------------------------------------------
void CBigSquare::Render( LPDIRECT3DDEVICE9 pd3dDevice )
{
	pd3dDevice->SetFVF( FVF );
	pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof(SHADOWVERTEX));
	pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );
}
开发者ID:jjuiddong,项目名称:Dx9-Shader,代码行数:9,代码来源:main.cpp

示例2: RenderFrameDX9

// `使用Direct3D9來繪圖`
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// `消除畫面`
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
	// `開始下繪圖指令`
	device->BeginScene(); 
	// `設定資料格式`
	device->SetFVF(D3DFVF_XYZ | D3DFVF_NORMAL);
	// `套用shader`
	device->SetVertexShader(g_pSelected_VS);
	device->SetPixelShader(g_pVertexColor_PS);
	// `設定光源`
	SetupLightingDX9();
	// `設定轉換矩陣`
	Matrix4x4 world_view_proj_matrix = g_world_matrix * g_view_proj_matrix;
	device->SetVertexShaderConstantF(0, &world_view_proj_matrix[0][0], 4);
	device->SetVertexShaderConstantF(4, &g_world_matrix[0][0], 4);
	// `鏡頭位置, 計算Specular會用到.`
	device->SetVertexShaderConstantF(8, &g_eye[0], 1);
	// `畫出格子`
	device->DrawIndexedPrimitiveUP(D3DPT_TRIANGLESTRIP, 0, g_iNumGridVertices, g_iNumGridTriangles, 
		g_pGridIndices, D3DFMT_INDEX16, g_pGridVertices, sizeof(Vertex_V3N3) );
	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 
	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}
开发者ID:as2120,项目名称:ZNginx,代码行数:29,代码来源:render_dx9.cpp

示例3: loadDDSIntoSystemMemory

ID3D11Texture2D * 
#endif
TextureGPU::gfxLoadDDSTexture(char *filename, bool genMips /*= true*/)
{	
	DDS::DDSTextureInSystemMemory dds;
	uint32_t test =  loadDDSIntoSystemMemory(filename,&dds);
	if(test==false) 
	{
		printf("failed to load\n");
		exit(0);
	}
	
	bool haveMips = dds.mips > 1;
	bool needToGenerateMips = !haveMips && genMips;
	bool willHaveMips = haveMips || genMips;

	if (false)
	{
		int32_t w = dds.width;
		int32_t h = dds.height;

		for (uint32_t i = 0; i < dds.mips; i++)
		{
			unsigned char r = i % 3 ? 0x00 : 0xFF;
			unsigned char g = (i+2) % 3 ? 0x00 : 0xFF;
			unsigned char b = (i+1) % 3 ? 0x00 : 0xFF;

		
			if (dds.uncompressedFormat && dds.components == 4)
			{	
				unsigned char *data = dds.image[0].pixels[i];
				for (int y = 0; y < h; y++)
					for (int x = 0; x < w; x++)
					{
						unsigned char solid = ((x % 8) > 3) ^ ((y % 8) > 3); 
						*data++ = b * solid;
						*data++ = g * solid;
						*data++ = r * solid;
						*data++ = 0;
					}
			}

			// we use componets == 3 becasue on IOS we dont have GL_BGR flag at all. event to use is as temp variable for storing dds format
			if (dds.uncompressedFormat && dds.components == 3)
			{
				unsigned char *data = dds.image[0].pixels[i];
				for (int y = 0; y < h; y++)
					for (int x = 0; x < w; x++)
					{
						*data++ = r;
						*data++ = g;
						*data++ = b;
					}
			}
			w/=2; h/=2;
			if (w == 0) w = 1;
			if (h == 0) h = 1;
		}
	}

	assert(m_samplerState != SamplerState_INVALID);

	SamplerState &ss = SamplerStateManager::getInstance()->getSamplerState(m_samplerState);

	if (willHaveMips)
	{
		//check that we want t use existing mips
		if (!ss.needsMipMaps())
		{
			PEWARN("Mipmap filtering is disabled while mipams exist and are loaded. Texture: %s", filename);
		}
	}
	else
	{
		//check that we dont want a value that assumes mip map existance
		if (ss.needsMipMaps())
		{
			PEWARN("Trying to enable mip map filtering when no mipmaps exist. Texture: %s", filename);
		}
	}
	
	int32_t w = dds.width;
	int32_t h = dds.height;

	#if APIABSTRACTION_D3D9

	D3D9Renderer *pD3D9Renderer = static_cast<D3D9Renderer *>(m_pContext->getGPUScreen());
	LPDIRECT3DDEVICE9 pDevice = pD3D9Renderer->m_pD3D9Device;

	//choose api format best suited for loaded texture
	D3DFORMAT destApiFormat = D3DFMT_UNKNOWN;
	if (dds.compressedFormat)
	{
		assert(!"Dont support compressed textures yet!");
	}
	else
	{
		if (dds.components == 1)
		{
			if (dds.uncompressedFormat == DDSF_L)
//.........这里部分代码省略.........
开发者ID:AlexSincennes,项目名称:522AIProject,代码行数:101,代码来源:Texture_DDS_Loader_D3D.cpp

示例4:

// @brief  : 描画が無効のときの挙動
//--------------------------------------------------------------------
void DirectionalLightDx9::OnDisable( void )
{
    LPDIRECT3DDEVICE9 device = DirectX9::Instance().Device;
    device->LightEnable(m_Index,FALSE);
}
开发者ID:AyumiYasui,项目名称:Material,代码行数:7,代码来源:directionalLightDx9.cpp

示例5: CreateBackBuffer

void clsDXDevice::CreateBackBuffer(LPDIRECT3DDEVICE9 ldd)
{
	ldd->GetBackBuffer(0,0,D3DBACKBUFFER_TYPE_MONO,&backbuffer);
}
开发者ID:SoseUIT034,项目名称:game-2d-mapplestory,代码行数:4,代码来源:clsDXDevice.cpp

示例6: DrawModel

//=============================================================================
// 描画処理
//=============================================================================
void DrawModel(LPDIRECT3DDEVICE9 pDevice)
{
	//LPDIRECT3DDEVICE9 pDevice = GetDevice();
	
	D3DXMATERIAL * 	pD3DXMat;
	D3DMATERIAL9	matDef;
	
	D3DXMATRIX mtxScale,mtxRot,mtxTrans;
	
	pDevice->SetFVF(Player.pD3DXMeshModel->GetFVF());

	//ワールドマトリクスの初期化
	D3DXMatrixIdentity(&Player.mtxWorld);	// Identity:単位○○

	//現在のマテリアルを取得
	pDevice->GetMaterial(&matDef);
	
	// スケールを反映
	D3DXMatrixScaling(
		&mtxScale,		//格納先
		Player.scaleModel.x,
		Player.scaleModel.y,
		Player.scaleModel.z
	);
	D3DXMatrixMultiply(
		&Player.mtxWorld,	//格納先(A*B)
		&Player.mtxWorld,	//A
		&mtxScale		//B
	);

	// 回転を反映
	D3DXMatrixRotationYawPitchRoll(
		&mtxRot,		//格納先
		Player.rotModel.y,	//ヨー(左右)
		Player.rotModel.x,	//ピッチ(前後)
		Player.rotModel.z	//ロール(回転)
	);
	D3DXMatrixMultiply(
		&Player.mtxWorld,	//格納先(A*B)
		&Player.mtxWorld,	//A
		&mtxRot			//B
	);

	// 移動を反映
	D3DXMatrixTranslation(
		&mtxTrans,		//格納先
		Player.posModel.x,	//
		Player.posModel.y,	//
		Player.posModel.z	//
	);
	D3DXMatrixMultiply(
		&Player.mtxWorld,	//格納先(A*B)
		&Player.mtxWorld,	//A
		&mtxTrans		//B
	);

	//ワールドマトリクスの設定
	pDevice->SetTransform(D3DTS_WORLD,&Player.mtxWorld);

	//マテリアル情報に対するポインタを取得
	pD3DXMat = (D3DXMATERIAL*)Player.pD3DXBuffMatModel->GetBufferPointer();
	

	for(int nCntMat = 0; nCntMat < (int)Player.nNumMatModel; nCntMat ++){
		//マテリアルの設定
		pDevice->SetMaterial(&pD3DXMat[nCntMat].MatD3D);
		//テクスチャの設定
		pDevice->SetTexture(0, Player.pMeshTex[nCntMat]);
		//描画
		Player.pD3DXMeshModel->DrawSubset(nCntMat);
	}
	
	//マテリアルを元に戻す
	pDevice->SetMaterial(&matDef);
}
开发者ID:SasakiMizuki,项目名称:MizukiRepository,代码行数:78,代码来源:model.cpp

示例7: SetupLightingDX9

static void SetupLightingDX9(void)
{
	// `取得Direct3D9裝置`
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();

	int base = 12;
	Vector4 vShininess = g_fMaterialShininess;
	Vector4 vAmbient, vDiffuse, vSpecular, vSpotLightCoeff;
	// `設定環境光`
	device->SetVertexShaderConstantF(base, &g_vAmbientLight[0], 1);

	// `設定光源`
	switch(g_iSelectedLight)
	{
		// `方向光`
	default:
	case 0:
		g_pSelected_VS = g_pDirLight_VS;

		vAmbient = g_vMaterialAmbient * g_Lights[0].m_vAmbientColor;
		vDiffuse = g_vMaterialDiffuse * g_Lights[0].m_vDiffuseColor;
		vSpecular = g_vMaterialSpecular * g_Lights[0].m_vSpecularColor;

		device->SetVertexShaderConstantF(base + 1, &g_Lights[0].m_vDirection.x, 1);
		device->SetVertexShaderConstantF(base + 2, &vAmbient.x, 1);
		device->SetVertexShaderConstantF(base + 3, &vDiffuse.x, 1);
		device->SetVertexShaderConstantF(base + 4, &vSpecular.x, 1);
		device->SetVertexShaderConstantF(base + 5, &vShininess.x, 1);

		break;
		// `點光源`
	case 1:
		g_pSelected_VS = g_pPointLight_VS;

		vAmbient = g_vMaterialAmbient * g_Lights[1].m_vAmbientColor;
		vDiffuse = g_vMaterialDiffuse * g_Lights[1].m_vDiffuseColor;
		vSpecular = g_vMaterialSpecular * g_Lights[1].m_vSpecularColor;

		device->SetVertexShaderConstantF(base + 1, &g_Lights[1].m_vPosition.x, 1);
		device->SetVertexShaderConstantF(base + 2, &g_Lights[1].m_vAttenuation.x, 1);
		device->SetVertexShaderConstantF(base + 3, &vAmbient.x, 1);
		device->SetVertexShaderConstantF(base + 4, &vDiffuse.x, 1);
		device->SetVertexShaderConstantF(base + 5, &vSpecular.x, 1);
		device->SetVertexShaderConstantF(base + 6, &vShininess.x, 1);

		break;
		// `聚光燈`
	case 2:
		g_pSelected_VS = g_pSpotLight_VS;

		vAmbient = g_vMaterialAmbient * g_Lights[2].m_vAmbientColor;
		vDiffuse = g_vMaterialDiffuse * g_Lights[2].m_vDiffuseColor;
		vSpecular = g_vMaterialSpecular * g_Lights[2].m_vSpecularColor;

		float spotlight_cutoff_cosine = FastMath::Cos( FastMath::DegreeToRadian(g_Lights[2].m_fSpotlightCutoff * 0.5f) );
		vSpotLightCoeff.Set(spotlight_cutoff_cosine, g_Lights[2].m_fSpotlightExponent, 0.0f, 0.0f);

		device->SetVertexShaderConstantF(base + 1, &g_Lights[2].m_vPosition.x, 1);
		device->SetVertexShaderConstantF(base + 2, &g_Lights[2].m_vDirection.x, 1);
		device->SetVertexShaderConstantF(base + 3, &g_Lights[2].m_vAttenuation.x, 1);
		device->SetVertexShaderConstantF(base + 4, &vSpotLightCoeff.x, 1);
		device->SetVertexShaderConstantF(base + 5, &vAmbient.x, 1);
		device->SetVertexShaderConstantF(base + 6, &vDiffuse.x, 1);
		device->SetVertexShaderConstantF(base + 7, &vSpecular.x, 1);
		device->SetVertexShaderConstantF(base + 8, &vShininess.x, 1);

		break;
	}
}
开发者ID:as2120,项目名称:ZNginx,代码行数:69,代码来源:render_dx9.cpp

示例8: fillTexture

bool DirectXTextureManager::loadTileSetFromTexture(	Game *game, 
													wstring dir,
													wstring sourceImageFileName,
													int tileWidth,
													int tileHeight)
{
	// CONVERT THE FILE NAME INTO A WINDOW LONG CHAR wchar_t (LPCWSTR)
	wstring sourcePath = dir + sourceImageFileName;

	LPDIRECT3DTEXTURE9 textureToDivide;
	LPDIRECT3DSURFACE9 surfaceToDivide;

	unsigned int result = fillTexture(sourcePath, &textureToDivide);
	textureToDivide->GetSurfaceLevel(0, &surfaceToDivide);
	if (result != S_OK) return false;

	// DETERMINE THE NUMBER OF TILE ROWS AND COLUMNS
	D3DSURFACE_DESC surfaceDesc;
	surfaceToDivide->GetDesc(&surfaceDesc);
	int textureWidth = surfaceDesc.Width;
	int textureHeight = surfaceDesc.Height;
	int columns = textureWidth/tileWidth;
	int rows = textureHeight/tileHeight;
	DirectXGraphics *dxg = (DirectXGraphics*)graphics;

	LPDIRECT3DDEVICE9 graphicsDevice = ((DirectXGraphics*)graphics)->getGraphicsDevice();

	// THE TILE SET IMAGE LOADED SUCCESSFULLY, SO LET'S CUT IT UP
	for (int row = 0; row < rows; row++)
	{
		for (int column = 0; column < columns; column++)
		{
			LPDIRECT3DTEXTURE9 extractedTexture;
			LPDIRECT3DSURFACE9 extractedSurface;
			result = graphicsDevice->CreateRenderTarget(tileWidth,
					tileHeight,
					D3DFMT_A8R8G8B8,
					D3DMULTISAMPLE_NONE, 0, false, &extractedSurface, NULL);
			if (result != S_OK) return false;
	
			RECT sourceRect;
			sourceRect.left = column * tileWidth;
			sourceRect.right = tileWidth + (column * tileWidth) - 1;
			sourceRect.top = row * tileHeight;
			sourceRect.bottom = tileHeight + (row * tileHeight) - 1;
			
			graphicsDevice->StretchRect(surfaceToDivide, &sourceRect, extractedSurface, NULL, D3DTEXF_NONE);

			// BUILD A UNIQUE FILE NAME FOR THIS TEXTURE
			wstring textureFilename = sourceImageFileName;

			unsigned int id = wstringTable.getNumWStringsInTable();
			wchar_t dot = '.';
			int dotIndex = textureFilename.rfind(dot);
			textureFilename = textureFilename.substr(0, dotIndex);
			wstringstream idWss;
			idWss << id;
			wstring idText;
			idWss >> idText;
			textureFilename = textureFilename + idText + L".png";
			textureFilename = wstring(dir.begin(), dir.end()) + textureFilename;
				
			// LET'S PUT THE SURFACE IN AN IMAGE FILE
			D3DXSaveSurfaceToFileW(textureFilename.c_str(), D3DXIFF_PNG, extractedSurface, NULL, NULL); 
			D3DXIMAGE_INFO info;
			HRESULT result = D3DXGetImageInfoFromFile(textureFilename.c_str(), &info);
			if (result != S_OK) return false;

			// AND THEN LOAD IT BACK IN AS A TEXTURE
			result = D3DXCreateTextureFromFileEx(	graphicsDevice,		// GPU
													textureFilename.c_str(),			// BITMAP FILE PATH/NAME
													tileWidth,			// BITMAP IMAGE WIDTH
													tileHeight,		// BITMAP IMAGE HEIGHT
													1,					// MIP-MAP LEVELS (1 FOR NO CHAIN)
													D3DPOOL_DEFAULT,	// THE TYPE OF SURFACE (STANDARD)
													D3DFMT_UNKNOWN,		// SURFACE FORMAT (DEFAULT)
													D3DPOOL_DEFAULT,	// MEMORY CLASS FOR THE TEXTURE
													D3DX_DEFAULT,		// IMAGE FILTER
													D3DX_DEFAULT,		// MIP FILTER
													NULL,			// COLOR KEY
													&info,				// BITMAP FILE INFO
													NULL,				// COLOR PALETTE
													&extractedTexture );	// THE TEXTURE WE ARE CREATING AND LOADING					
			if (result != S_OK) return false;

			// ADD IT TO THE STRING TABLE
			wstringTable.putWStringInTable(textureFilename);

			// AND ADD IT TO THE TEXTURES
			textures[textureFilename] = extractedTexture;

			//Delete File After Use
			int length;
			int slength = (int)textureFilename.length() + 1;
			length = WideCharToMultiByte(CP_ACP, 0, textureFilename.c_str(), slength, 0, 0, 0, 0);
			char* buffer = new char[length];
			WideCharToMultiByte(CP_ACP, 0, textureFilename.c_str(), slength, buffer, length, 0, 0); 
			std::string file(buffer);
			delete[] buffer;
			if (remove(file.c_str()) != 0)
//.........这里部分代码省略.........
开发者ID:tommarion,项目名称:Ninja_Espionage_4.7_CSE380_Final,代码行数:101,代码来源:DirectXTextureManager.cpp

示例9: RenderFrameDX9

// 使用Direct3D9來繪圖
void RenderFrameDX9(void)
{
	LPDIRECT3DDEVICE9 device = GutGetGraphicsDeviceDX9();
	// `消除畫面`
	device->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1.0f, 0);
	// `開始下繪圖指令`
	device->BeginScene(); 
	// `設定矩陣`
	Matrix4x4 view_matrix = g_Control.GetViewMatrix();
	Matrix4x4 object_matrix = g_Control.GetObjectMatrix();
	device->SetTransform(D3DTS_VIEW, (D3DMATRIX *) &view_matrix);
	device->SetTransform(D3DTS_WORLD, (D3DMATRIX *) &object_matrix);
	// `設定資料格式`
	device->SetFVF(D3DFVF_XYZ|D3DFVF_TEX1); 
	// `套用貼圖`
	device->SetTexture(0, g_pTexture);

	device->SetSamplerState(0, D3DSAMP_ADDRESSU, D3DTADDRESS_WRAP);
	device->SetSamplerState(0, D3DSAMP_ADDRESSV, D3DTADDRESS_WRAP);

	switch(g_iFilterMode)
	{
	case 1: // linear filtering
		// `貼圖被放大時, 取最接近4個點來內插.`
		device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
		// `貼圖被縮小時, 取最接近4個點來平均.`
		device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
		// `不使用Mipmap`
		device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_NONE);
		break;
	case 2: // bilinear filtering
		// `貼圖被放大時, 取最接近4個點來內插.`
		device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
		// `貼圖被縮小時, 取最接近4個點來平均.`
		device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
		// `取最接近大小的圖層`
		device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_POINT);
		break;
	case 3: // trilinear filtering
		// `貼圖被放大時, 取最接近4個點來內插.`
		device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
		// `貼圖被縮小時, 取最接近4個點來平均.`
		device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
		// `取最接近大小的兩個圖層, 然後再內插.`
		device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
		break;
	case 4: // anisotropic filtering
		// `會根據縮放的長寬比例來取用貼圖, 不固定是取哪幾個圖.`
		device->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
		device->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_ANISOTROPIC);
		device->SetSamplerState(0, D3DSAMP_MAXANISOTROPY, 8);
		// `取最接近大小的兩個圖層, 然後再內插.`
		device->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);
		break;
	}
	// `畫出矩形`
	device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, g_Quad, sizeof(Vertex_VT));
	// `宣告所有的繪圖指令都下完了`
	device->EndScene(); 
	// `把背景backbuffer的畫面呈現出來`
	device->Present( NULL, NULL, NULL, NULL );
}
开发者ID:chenbk85,项目名称:3dlearn,代码行数:63,代码来源:render_dx9.cpp

示例10: setBlendingMode

void Graphics::setBlendingMode(BlendingOperation source, BlendingOperation destination) {
	device->SetRenderState(D3DRS_SRCBLEND, convert(source));
	device->SetRenderState(D3DRS_DESTBLEND, convert(destination));
}
开发者ID:KTXSoftware,项目名称:Kha-haxelib,代码行数:4,代码来源:Direct3D9.cpp

示例11: InitVB

//////////////////////////////////////////////////////////////////////////
// 버텍스 버퍼 생성
//
// CreateVertexBuffer() 함수를 이용해 만들어진 버텍스 버퍼는 위치가 고정되어 있지 않다.
// 사용 할 때에는 반드시 Lock()으로 주소를 얻어 온 후, 버퍼에 내용을 써 넣고 Unlock() 해야 한다.
//
// 버텍스 버퍼나 인덱스 버퍼는 기본 시스템 메모리 외에도 디바이스 메모리(그래픽 카드 메모리)에 생성 될 수 있다.
// 대부분의 그래픽 카드에서는 이렇게 할 경우 속도가 매우 향상 된다.
//////////////////////////////////////////////////////////////////////////
HRESULT InitVB()
{
	// 삼각형을 렌더링 하기 위해 세 개의 버텍스 선언
	CUSTOMVERTEX vertices[] =
	{
		{ 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color
		{ 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, },
		{ 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, },
	};

	// 버텍스 버퍼 생성
	// 3개의 사용자 버텍스를 보관할 메모리를 할당
	// FVF를 지정하여 버텍스의 형식을 지정한다
	if ( FAILED( g_pd3dDevice->CreateVertexBuffer( 
		
		// 생성 할 버텍스 버퍼의 바이트 단위 크기
		3 * sizeof( CUSTOMVERTEX ),
		
		// 버텍스 버퍼 종류, 처리 방식(SW, HW) 지정
		0,
		
		// 커스텀 버텍스 구조체 FVF 플래그 값
		D3DFVF_CUSTOMVERTEX,
		
		// 버텍스 버퍼가 저장 될 메모리의 위치(그래픽 카드, 시스템 메모리)와 관리 방식
		D3DPOOL_DEFAULT,
		
		// 리턴 받을 버텍스 버퍼 변수
		&g_pVB,
		
		// 예약 되었음
		NULL
		
		) ) )
	{
		return E_FAIL;
	}

	// 버텍스 버퍼를 값으로 채운다. 
	// 버텍스 버퍼의 Lock()함수를 호출하여 포인터를 가져온다.
	VOID* pVertices;
	if ( FAILED( g_pVB->Lock( 

		// Lock 버퍼 시작점
		// 다음 인자와 함께 모두 0이면 전체 버퍼
		0,
		
		// Lock을 할 버퍼 크기
		// 이전 인자와 함께 모두 0이면 전체 버퍼
		sizeof( vertices ),
		
		// Lock으로 받아오는 메모리 영역의 포인터를 담을 변수
		(void**)&pVertices,
		
		// Lock을 수행할 때 함께 사용할 플래그
		0
		
		) ) )
	{
		return E_FAIL;
	}
	memcpy( pVertices, vertices, sizeof( vertices ) );
	
	// 반드시 Unlock 해야 한다. Unlock을 하지 않을 경우 그래픽카드가 다운 될 수 있음! - 교재에서
	//
	// 교수님 말씀에 따르면 실제 해 봐도 다운이 되지 않는다고 함
	g_pVB->Unlock();
	
	return S_OK;
}
开发者ID:blastingzone,项目名称:ComputerGraphicsAdvenced,代码行数:79,代码来源:Chapter2.cpp

示例12: ReadModelFile

bool ReadModelFile( const string &fileName, LPDIRECT3DVERTEXBUFFER9 &vtxBuff, int &vtxSize,  LPDIRECT3DINDEXBUFFER9 &idxBuff, int &faceSize )
{
	using namespace std;
	ifstream fin(fileName.c_str());
	if (!fin.is_open())
		return false;

	string vtx, vtx_eq;
	int numVertices;
	fin >> vtx >> vtx_eq >> numVertices;

	if (numVertices <= 0)
		return  false;

	vtxSize = numVertices;

	// 버텍스 버퍼 생성.
	if (FAILED(g_pDevice->CreateVertexBuffer( numVertices * sizeof(Vertex),
		D3DUSAGE_WRITEONLY, Vertex::FVF,
		D3DPOOL_MANAGED, &vtxBuff, NULL)))
	{
		return false;
	}

	// 버텍스 버퍼 초기화.
	Vertex* vertices;
	if (FAILED(vtxBuff->Lock( 0, sizeof(Vertex), (void**)&vertices, 0)))
		return false;
	float num1, num2, num3;
	for (int i = 0; i < numVertices; i++)
	{
		fin >> num1 >> num2 >> num3;
		vertices[i] = Vertex(num1, num2, num3);
	}
	vtxBuff->Unlock();


	string norm, norm_eq;
	int numNormal;
	fin >> norm >> norm_eq >> numNormal;

	if (numNormal <= 0)
		return false;

	if (FAILED(vtxBuff->Lock( 0, sizeof(Vertex), (void**)&vertices, 0)))
		return false;
	for (int i = 0; i < numVertices; i++)
	{
		fin >> num1 >> num2 >> num3;
		vertices[i].n = Vector3(num1, num2, num3);
	}
	vtxBuff->Unlock();


	string idx, idx_eq;
	int numIndices;
	fin >> idx >> idx_eq >> numIndices;

	if (numIndices <= 0)
		return false;

	faceSize = numIndices;

	if (FAILED(g_pDevice->CreateIndexBuffer(numIndices*3*sizeof(WORD), 
		D3DUSAGE_WRITEONLY,
		D3DFMT_INDEX16,
		D3DPOOL_MANAGED,
		&idxBuff, NULL)))
	{
		return false;
	}

	WORD *indices = NULL;
	idxBuff->Lock(0, 0, (void**)&indices, 0);
	int num4, num5, num6;
	for (int i = 0; i < numIndices*3; i+=3)
	{
		fin >> num4 >> num5 >> num6;
		indices[ i] = num4;
		indices[ i+1] = num5;
		indices[ i+2] = num6;	
	}
	idxBuff->Unlock();

	//ComputeNormals(vtxBuff, vtxSize, idxBuff, faceSize);
	return true;
}
开发者ID:mylovejong,项目名称:Game,代码行数:87,代码来源:GameApp.cpp

示例13: RGetApproxVMem

int	 RGetApproxVMem()		{ if(g_pd3dDevice==0) return 0; return g_pd3dDevice->GetAvailableTextureMem()*0.5f;}
开发者ID:Kallontz,项目名称:gunz-the-tps-mmorpg,代码行数:1,代码来源:RealSpace2.cpp

示例14: InitVertexBuffer

bool InitVertexBuffer()
{
	HRESULT hr;
	ID3DXBuffer *adjBuff = NULL;
	ID3DXBuffer *mtrlBuff = NULL;
	DWORD numMtrls = 0;

	// 메쉬 정보 로드
	hr = D3DXLoadMeshFromXA( "../../media/bigship1.x", D3DXMESH_MANAGED, 
		g_pDevice, &adjBuff, &mtrlBuff, 0, &numMtrls, &g_pMesh );
	if (FAILED(hr))
		return false;

	/////////////////////////////////////////////////////////////////////////////
	// 매터리얼 설정
	if( mtrlBuff && numMtrls > 0 )
	{
		D3DXMATERIAL *mtrls = (D3DXMATERIAL*)mtrlBuff->GetBufferPointer();

		for( int i=0; i < (int)numMtrls; ++i )
		{
			mtrls[ i].MatD3D.Ambient = mtrls[ i].MatD3D.Diffuse;
			g_Mtrls.push_back( mtrls[ i].MatD3D );

			if( mtrls[ i].pTextureFilename )
			{
				IDirect3DTexture9 *tex = NULL;
				string filePath = "../../media/";
				filePath += mtrls[ i].pTextureFilename;
				D3DXCreateTextureFromFileA( g_pDevice, filePath.c_str(), &tex );
				g_Texture.push_back( tex );
			}
			else
			{
				g_Texture.push_back( 0 );
			}
		}
	}
	mtrlBuff->Release();

	// 메쉬 최적화
	hr = g_pMesh->OptimizeInplace( 
		D3DXMESHOPT_COMPACT | D3DXMESHOPT_ATTRSORT | D3DXMESHOPT_VERTEXCACHE, 
		(DWORD*)adjBuff->GetBufferPointer(), (DWORD*)adjBuff->GetBufferPointer(), 0, 0 );

	if (FAILED(hr))
		return false;

	// 프로그레시브 메쉬 생성.
	hr = D3DXGeneratePMesh(g_pMesh, (DWORD*)adjBuff->GetBufferPointer(), 0, 0, 1, 
		D3DXMESHSIMP_FACE, &g_pPMesh );
	g_pMesh->Release();
	g_pMesh = NULL;
	adjBuff->Release();
	if (FAILED(hr))
		return false;

	//DWORD maxFaces = g_pPMesh->GetMaxFaces();
	//g_pPMesh->SetNumFaces( maxFaces );




	D3DXCOLOR color(1,1,1,1);
	ZeroMemory(&g_Light, sizeof(g_Light));
	g_Light.Type = D3DLIGHT_DIRECTIONAL;
	g_Light.Ambient = color * 0.4f;
	g_Light.Diffuse = color;
	g_Light.Specular = color * 0.6f;
	g_Light.Direction = *(D3DXVECTOR3*)&Vector3(0,-1,0);	



	Matrix44 V;
	Vector3 camPos(0,0,-20);
	Vector3 lookAtPos(0,0,0);
	Vector3 dir = lookAtPos - camPos;
	dir.Normalize();
	V.SetView(camPos, dir, Vector3(0,1,0));
	g_pDevice->SetTransform(D3DTS_VIEW, (D3DXMATRIX*)&V);

	Matrix44 proj;
	proj.SetProjection(D3DX_PI * 0.5f, (float)WINSIZE_X / (float) WINSIZE_Y, 1.f, 1000.0f) ;
	g_pDevice->SetTransform(D3DTS_PROJECTION, (D3DXMATRIX*)&proj) ;

	g_pDevice->SetLight(0, &g_Light); // 광원 설정.
	g_pDevice->LightEnable(
		0, // 활성화/ 비활성화 하려는 광원 리스트 내의 요소
		true); // true = 활성화 , false = 비활성화

	g_pDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
	g_pDevice->SetRenderState(D3DRS_SPECULARENABLE, true);

	return true;
}
开发者ID:kami36,项目名称:Study,代码行数:95,代码来源:RenderPMesh.cpp

示例15: DrawBillboard

void DrawBillboard()
{
	// 알파채널을 사용해서 투명텍스처 효과를 낸다
	g_pd3dDevice->SetRenderState( D3DRS_ALPHABLENDENABLE, TRUE );
	g_pd3dDevice->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
	g_pd3dDevice->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
	g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, TRUE );
	g_pd3dDevice->SetRenderState( D3DRS_ALPHAREF, 0x08 );
	g_pd3dDevice->SetRenderState( D3DRS_ALPHAFUNC, D3DCMP_GREATEREQUAL );

	struct MYVERTEX
	{
		enum { FVF = D3DFVF_XYZ | D3DFVF_TEX1 };
		float px, py, pz;
		float tu, tv;
	};

	// 빌보드 정점
	MYVERTEX vtx[4] =
	{
		{ -1, 0, 0, 0, 1 },
		{ -1, 4, 0, 0, 0 },
		{ 1, 0, 0, 1, 1 },
		{ 1, 4, 0, 1, 0 }
	};
	D3DXMATRIXA16	matBillboard;
	D3DXMatrixIdentity( &matBillboard );

	// 0번 텍스처에 빌보드 텍스처를 올린다
	g_pd3dDevice->SetTexture( 1, NULL );
	g_pd3dDevice->SetFVF( MYVERTEX::FVF );

	if ( g_bBillboard )
	{
		// Y축 회전행렬은 _11, _13, _31, _33번 행렬에 회전값이 들어간다
		// 카메라의 Y축 회전행렬값을 읽어서 역행렬을 만들면 X,Z축이 고정된
		// Y축 회전 빌보드 행렬을 만들수 있다
		matBillboard._11 = g_pCamera->GetViewMatrix()->_11;
		matBillboard._13 = g_pCamera->GetViewMatrix()->_13;
		matBillboard._31 = g_pCamera->GetViewMatrix()->_31;
		matBillboard._33 = g_pCamera->GetViewMatrix()->_33;
		D3DXMatrixInverse( &matBillboard, NULL, &matBillboard );
	}

	// 빌보드의 좌표를 바꿔가며 찍는다
	for ( int z = 0; z <= 40; z += 5 )
	{
		for ( int x = 0; x <= 40; x += 5 )
		{
			matBillboard._41 = static_cast<float>( x - 20 );
			matBillboard._42 = 0;
			matBillboard._43 = static_cast<float>( z - 20 );
			g_pd3dDevice->SetTexture( 0, g_pTexBillboard[( x + z ) % 4] );
			g_pd3dDevice->SetTransform( D3DTS_WORLD, &matBillboard );
			g_pd3dDevice->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vtx, sizeof( MYVERTEX ) );
		}
	}

	g_pd3dDevice->SetRenderState( D3DRS_ALPHATESTENABLE, FALSE );
	g_pd3dDevice->SetTransform( D3DTS_WORLD, &g_matWorld );
}
开发者ID:blastingzone,项目名称:ComputerGraphicsAdvenced,代码行数:61,代码来源:main.cpp


注:本文中的LPDIRECT3DDEVICE9类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。