本文整理汇总了C++中LPDIRECT3DVERTEXBUFFER8::Release方法的典型用法代码示例。如果您正苦于以下问题:C++ LPDIRECT3DVERTEXBUFFER8::Release方法的具体用法?C++ LPDIRECT3DVERTEXBUFFER8::Release怎么用?C++ LPDIRECT3DVERTEXBUFFER8::Release使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LPDIRECT3DVERTEXBUFFER8
的用法示例。
在下文中一共展示了LPDIRECT3DVERTEXBUFFER8::Release方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
//-----------------------------------------------------------------------------
// Name: ApplyEnvironmentMap()
// Desc: Performs a calculation on each of the vertices' normals to determine
// what the texture coordinates should be for the environment map (in this
// case the bump map).
//-----------------------------------------------------------------------------
VOID CMyD3DApplication::ApplyEnvironmentMap()
{
EMBOSSVERTEX* pv;
DWORD dwNumVertices;
dwNumVertices = m_pObject->GetLocalMesh()->GetNumVertices();
LPDIRECT3DVERTEXBUFFER8 pVB;
m_pObject->GetLocalMesh()->GetVertexBuffer( &pVB );
pVB->Lock( 0, 0, (BYTE**)&pv, 0 );
// Get the World matrix
D3DXMATRIX WV,InvWV;
m_pd3dDevice->GetTransform( D3DTS_WORLD, &WV );
D3DXMatrixInverse( &InvWV, NULL, &WV );
// Get the current light position in object space
D3DXVECTOR4 vTransformed;
D3DXVec3Transform( &vTransformed, (D3DXVECTOR3*)&m_Light.Position, &InvWV );
m_vBumpLightPos.x = vTransformed.x;
m_vBumpLightPos.y = vTransformed.y;
m_vBumpLightPos.z = vTransformed.z;
// Dimensions of texture needed for shifting tex coords
D3DSURFACE_DESC d3dsd;
m_pEmbossTexture->GetLevelDesc( 0, &d3dsd );
// Loop through the vertices, transforming each one and calculating
// the correct texture coordinates.
for( WORD i = 0; i < dwNumVertices; i++ )
{
// Find light vector in tangent space
D3DXVECTOR3 vLightToVertex;
D3DXVec3Normalize( &vLightToVertex, &(m_vBumpLightPos - pv[i].p) );
// Create rotation matrix (rotate into tangent space)
FLOAT r = D3DXVec3Dot( &vLightToVertex, &pv[i].n );
if( r < 0.f )
{
// Don't shift coordinates when light below surface
pv[i].tu2 = pv[i].tu;
pv[i].tv2 = pv[i].tv;
}
else
{
// Shift coordinates for the emboss effect
D3DXVECTOR2 vEmbossShift;
vEmbossShift.x = D3DXVec3Dot( &vLightToVertex, &m_pTangents[i] );
vEmbossShift.y = D3DXVec3Dot( &vLightToVertex, &m_pBinormals[i] );
D3DXVec2Normalize( &vEmbossShift, &vEmbossShift );
pv[i].tu2 = pv[i].tu + vEmbossShift.x/d3dsd.Width;
pv[i].tv2 = pv[i].tv - vEmbossShift.y/d3dsd.Height;
}
}
pVB->Unlock();
pVB->Release();
}
示例2: ZeroMemory
//-----------------------------------------------------------------------------
// Name:
// Desc:
//-----------------------------------------------------------------------------
VOID CMyD3DApplication::ComputeTangentsAndBinormals()
{
EMBOSSVERTEX* pVertices;
WORD* pIndices;
DWORD dwNumVertices;
DWORD dwNumIndices;
// Gain access to the object's vertex and index buffers
LPDIRECT3DVERTEXBUFFER8 pVB;
m_pObject->GetSysMemMesh()->GetVertexBuffer( &pVB );
pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 );
dwNumVertices = m_pObject->GetSysMemMesh()->GetNumVertices();
LPDIRECT3DINDEXBUFFER8 pIB;
m_pObject->GetSysMemMesh()->GetIndexBuffer( &pIB );
pIB->Lock( 0, 0, (BYTE**)&pIndices, 0 );
dwNumIndices = m_pObject->GetSysMemMesh()->GetNumFaces() * 3;
// Allocate space for the vertices' tangents and binormals
m_pTangents = new D3DXVECTOR3[dwNumVertices];
m_pBinormals = new D3DXVECTOR3[dwNumVertices];
ZeroMemory( m_pTangents, sizeof(D3DXVECTOR3)*dwNumVertices );
ZeroMemory( m_pBinormals, sizeof(D3DXVECTOR3)*dwNumVertices );
// Generate the vertices' tangents and binormals
for( DWORD i=0; i<dwNumIndices; i+=3 )
{
WORD a = pIndices[i+0];
WORD b = pIndices[i+1];
WORD c = pIndices[i+2];
// To find a tangent that heads in the direction of +tv(texcoords),
// find the components of both vectors on the tangent surface ,
// and add a linear combination of the two projections that head in the +tv direction
m_pTangents[a] += ComputeTangentVector( pVertices[a], pVertices[b], pVertices[c] );
m_pTangents[b] += ComputeTangentVector( pVertices[b], pVertices[a], pVertices[c] );
m_pTangents[c] += ComputeTangentVector( pVertices[c], pVertices[a], pVertices[b] );
}
for( i=0; i<dwNumVertices; i++ )
{
// Normalize the tangents
D3DXVec3Normalize( &m_pTangents[i], &m_pTangents[i] );
// Compute the binormals
D3DXVec3Cross( &m_pBinormals[i], &pVertices[i].n, &m_pTangents[i] );
}
// Unlock and release the vertex and index buffers
pIB->Unlock();
pVB->Unlock();
pIB->Release();
pVB->Release();
}
示例3: Cleanup
//-----------------------------------------------------------------------------
// Name: Cleanup()
// Desc: Releases all previously initialized objects
//-----------------------------------------------------------------------------
VOID Cleanup()
{
if( g_pVB != NULL )
g_pVB->Release();
if( g_pd3dDevice != NULL )
g_pd3dDevice->Release();
if( g_pD3D != NULL )
g_pD3D->Release();
}
示例4:
// Rendering library invalid handle
void D3D_RendInvalid ( IDirect3DDevice8 *pDevice )
{
unsigned int n;
if ( m_pOrigTarget )
m_pOrigTarget->Release();
// Release the vertex buffer
if ( m_pVertexBuffer )
m_pVertexBuffer->Release();
// Release all fonts
for ( n=0; n<m_uiNumFonts; n++ )
{
m_pFonts[n]->pFont->Release ( );
m_pFonts[n]->pFont=NULL;
}
}
示例5: memcpy
//-----------------------------------------------------------------------------
// Name: InitDeviceObjects()
// Desc: This creates all device-dependent managed objects, such as managed
// textures and managed vertex buffers.
//-----------------------------------------------------------------------------
HRESULT CMyD3DApplication::InitDeviceObjects()
{
// Initialize the font's internal textures
m_pFont->InitDeviceObjects( m_pd3dDevice );
// Create the tree textures
for( DWORD i=0; i<NUMTREETEXTURES; i++ )
{
if( FAILED( D3DUtil_CreateTexture( m_pd3dDevice, g_strTreeTextures[i],
&m_pTreeTextures[i] ) ) )
return D3DAPPERR_MEDIANOTFOUND;
}
// Create a quad for rendering each tree
if( FAILED( m_pd3dDevice->CreateVertexBuffer( NUM_TREES*4*sizeof(TREEVERTEX),
D3DUSAGE_WRITEONLY, D3DFVF_TREEVERTEX,
D3DPOOL_MANAGED, &m_pTreeVB ) ) )
{
return E_FAIL;
}
// Copy tree mesh data into vertexbuffer
TREEVERTEX* v;
m_pTreeVB->Lock( 0, 0, (BYTE**)&v, 0 );
INT iTree;
DWORD dwOffset = 0;
for( iTree = 0; iTree < NUM_TREES; iTree++ )
{
memcpy( &v[dwOffset], m_Trees[iTree].v, 4*sizeof(TREEVERTEX) );
m_Trees[iTree].dwOffset = dwOffset;
dwOffset += 4;
}
m_pTreeVB->Unlock();
// Load the skybox
if( FAILED( m_pSkyBox->Create( m_pd3dDevice, _T("SkyBox2.x") ) ) )
return D3DAPPERR_MEDIANOTFOUND;
// Load the terrain
if( FAILED( m_pTerrain->Create( m_pd3dDevice, _T("SeaFloor.x") ) ) )
return D3DAPPERR_MEDIANOTFOUND;
// Add some "hilliness" to the terrain
LPDIRECT3DVERTEXBUFFER8 pVB;
if( SUCCEEDED( m_pTerrain->GetSysMemMesh()->GetVertexBuffer( &pVB ) ) )
{
struct VERTEX { FLOAT x,y,z,tu,tv; };
VERTEX* pVertices;
DWORD dwNumVertices = m_pTerrain->GetSysMemMesh()->GetNumVertices();
pVB->Lock( 0, 0, (BYTE**)&pVertices, 0 );
for( DWORD i=0; i<dwNumVertices; i++ )
pVertices[i].y = HeightField( pVertices[i].x, pVertices[i].z );
pVB->Unlock();
pVB->Release();
}
return S_OK;
}
示例6: CreateCompatibleDC
//.........这里部分代码省略.........
// Set text properties
SelectObject(hDC, hFont);
SetTextColor(hDC, RGB(255,255,255));
SetBkColor(hDC, 0x00000000);
SetTextAlign(hDC, TA_TOP);
GetTextExtentPoint32(hDC, filename, strlen(filename), &size);
width = size.cx;
height = size.cy;
// Create a new texture for the font
result = pd3dDevice->CreateTexture(width, height, 1, 0, D3DFMT_A4R4G4B4,
D3DPOOL_MANAGED, &pTexture);
if (FAILED(result)) {
goto done;
}
// Prepare to create a bitmap
ZeroMemory(&bmi.bmiHeader, sizeof(BITMAPINFOHEADER));
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = width;
bmi.bmiHeader.biHeight = -height; // negative means top-down
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biCompression = BI_RGB;
bmi.bmiHeader.biBitCount = 32;
hbmBitmap = CreateDIBSection(hDC, &bmi, DIB_RGB_COLORS,
(VOID**)&pBitmapBits, NULL, 0);
SelectObject(hDC, hbmBitmap);
ExtTextOut(hDC, 0, 0, ETO_OPAQUE, NULL, filename, strlen(filename), NULL);
// Lock the surface and write the alpha values for the set pixels
pTexture->LockRect(0, &d3dlr, 0, 0);
pDstRow = (BYTE*)d3dlr.pBits;
for (y = 0; y < height; y++) {
WORD *pDst16 = (WORD *)pDstRow;
for (x = 0; x < width; x++) {
BYTE bAlpha = (BYTE)((pBitmapBits[width*y + x] & 0xff) >> 4);
if (bAlpha > 0) {
*pDst16++ = (WORD)((bAlpha << 12) | 0x0fff);
} else {
*pDst16++ = (WORD)(0x0000);
}
}
pDstRow += d3dlr.Pitch;
}
// Done updating texture
pTexture->UnlockRect(0);
// Create vertices
result = pd3dDevice->CreateVertexBuffer(4*sizeof(FONT2DVERTEX),
D3DUSAGE_WRITEONLY | D3DUSAGE_DYNAMIC, 0, D3DPOOL_DEFAULT, &pVB);
if (FAILED(result)) {
goto done;
}
notice = new Filename_notice;
notice->width = width;
notice->height = height;
notice->pd3dDevice = pd3dDevice;
notice->pTexture = pTexture;
pTexture = NULL;
notice->pVB = pVB;
pVB = NULL;
pd3dDevice->BeginStateBlock();
apply_render_state(pd3dDevice);
pd3dDevice->SetTexture(0, notice->pTexture);
pd3dDevice->EndStateBlock(¬ice->dwSavedStateBlock);
pd3dDevice->BeginStateBlock();
apply_render_state(pd3dDevice);
pd3dDevice->SetTexture(0, notice->pTexture);
pd3dDevice->EndStateBlock(¬ice->dwDrawTextStateBlock);
done:
if (pVB != NULL) {
pVB->Release();
}
if (pTexture != NULL) {
pTexture->Release();
}
if (hbmBitmap != NULL) {
DeleteObject(hbmBitmap);
}
if (hFont != NULL) {
DeleteObject(hFont);
}
if (hDC != NULL) {
DeleteDC(hDC);
}
return notice;
}
示例7: if
HRESULT CMyD3DApplication::LoadMeshData
(
LPD3DXMESH *ppMesh,
LPD3DXBUFFER *ppAdjacencyBuffer
)
{
LPDIRECT3DVERTEXBUFFER8 pMeshVB = NULL;
LPD3DXBUFFER pD3DXMtrlBuffer = NULL;
BYTE* pVertices;
TCHAR strMesh[512];
HRESULT hr = S_OK;
BOOL bNormalsInFile;
LPD3DXMESH pMeshSysMem = NULL;
LPD3DXMESH pMeshTemp;
DWORD *rgdwAdjacencyTemp = NULL;
DWORD i;
D3DXMATERIAL* d3dxMaterials;
DWORD dw32Bit;
// Get a path to the media file
DXUtil_FindMediaFile( strMesh, m_strMeshFilename );
// Load the mesh from the specified file
hr = D3DXLoadMeshFromX( strMesh, D3DXMESH_SYSTEMMEM, m_pd3dDevice,
ppAdjacencyBuffer, &pD3DXMtrlBuffer,
&m_dwNumMaterials, &pMeshSysMem );
if( FAILED(hr) )
goto End;
// remember if the mesh is 32 or 16 bit, to be added in on the clones
dw32Bit = pMeshSysMem->GetOptions() & D3DXMESH_32BIT;
// Get the array of materials out of the returned buffer, and allocate a texture array
d3dxMaterials = (D3DXMATERIAL*)pD3DXMtrlBuffer->GetBufferPointer();
m_pMeshMaterials = new D3DMATERIAL8[m_dwNumMaterials];
m_pMeshTextures = new LPDIRECT3DTEXTURE8[m_dwNumMaterials];
for( i=0; i<m_dwNumMaterials; i++ )
{
m_pMeshMaterials[i] = d3dxMaterials[i].MatD3D;
m_pMeshMaterials[i].Ambient = m_pMeshMaterials[i].Diffuse;
m_pMeshTextures[i] = NULL;
// Get a path to the texture
TCHAR strPath[512];
if (d3dxMaterials[i].pTextureFilename != NULL)
{
DXUtil_FindMediaFile( strPath, d3dxMaterials[i].pTextureFilename );
// Load the texture
D3DXCreateTextureFromFile( m_pd3dDevice, strPath, &m_pMeshTextures[i] );
}
}
// Done with the material buffer
SAFE_RELEASE( pD3DXMtrlBuffer );
// Lock the vertex buffer, to generate a simple bounding sphere
hr = pMeshSysMem->GetVertexBuffer( &pMeshVB );
if( SUCCEEDED(hr) )
{
hr = pMeshVB->Lock( 0, 0, &pVertices, D3DLOCK_NOSYSLOCK );
if( SUCCEEDED(hr) )
{
hr = D3DXComputeBoundingSphere( pVertices, pMeshSysMem->GetNumVertices(),
pMeshSysMem->GetFVF(),
&m_vObjectCenter, &m_fObjectRadius );
pMeshVB->Unlock();
}
pMeshVB->Release();
}
if( FAILED(hr) )
goto End;
// remember if there were normals in the file, before possible clone operation
bNormalsInFile = pMeshSysMem->GetFVF() & D3DFVF_NORMAL;
// if using 32byte vertices, check fvf
if (m_bForce32ByteFVF)
{
// force 32 byte vertices
if (pMeshSysMem->GetFVF() != (D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1))
{
hr = pMeshSysMem->CloneMeshFVF( pMeshSysMem->GetOptions(), D3DFVF_XYZ|D3DFVF_NORMAL|D3DFVF_TEX1,
m_pd3dDevice, &pMeshTemp );
if( FAILED(hr) )
goto End;
pMeshSysMem->Release();
pMeshSysMem = pMeshTemp;
}
}
// otherwise, just make sure that there is a normal mesh
else if ( !(pMeshSysMem->GetFVF() & D3DFVF_NORMAL) )
{
hr = pMeshSysMem->CloneMeshFVF( pMeshSysMem->GetOptions(), pMeshSysMem->GetFVF() | D3DFVF_NORMAL,
m_pd3dDevice, &pMeshTemp );
if (FAILED(hr))
return hr;
//.........这里部分代码省略.........