本文整理汇总了C++中IDirect3DDevice9::CreateVertexBuffer方法的典型用法代码示例。如果您正苦于以下问题:C++ IDirect3DDevice9::CreateVertexBuffer方法的具体用法?C++ IDirect3DDevice9::CreateVertexBuffer怎么用?C++ IDirect3DDevice9::CreateVertexBuffer使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDirect3DDevice9
的用法示例。
在下文中一共展示了IDirect3DDevice9::CreateVertexBuffer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HDAPIException
void DX9VB::create(int sizeInBytes, int stride, HDResourceMgr *pMgr)
{
ASSERT(sizeInBytes > 0);
ASSERT(stride > 0);
ASSERT(pMgr);
destroy();
//
DX9ResourceMgr* pDX9Mgr = (DX9ResourceMgr*)pMgr;
IDirect3DDevice9* pDev = pDX9Mgr->getDX9Device();
HRESULT hr;
hr = pDev->CreateVertexBuffer(sizeInBytes,
D3DUSAGE_WRITEONLY, // usage
0, // FVF
D3DPOOL_MANAGED,
&m_pVB, NULL);
if(FAILED(hr))
{
LOG("vertex buffer create failed, size = %d\r\n", sizeInBytes);
throw HDAPIException("vertex buffer create failed.");
}
//
m_sizeInBytes = sizeInBytes;
m_stride = stride;
}
示例2: locker
IDirect3DVertexBuffer9* MythRenderD3D9::CreateVertexBuffer(IDirect3DTexture9* texture)
{
D3D9Locker locker(this);
IDirect3DDevice9* dev = locker.Acquire();
if (!dev)
return NULL;
if (texture && !m_textures.contains(texture))
return false;
IDirect3DVertexBuffer9* temp_vbuf = NULL;
HRESULT hr = dev->CreateVertexBuffer(
sizeof(TEXTUREVERTEX)*4, D3DUSAGE_DYNAMIC|D3DUSAGE_WRITEONLY,
D3DFVF_TEXTUREVERTEX, D3DPOOL_DEFAULT,
&temp_vbuf, NULL);
if (FAILED(hr))
{
VERBOSE(VB_IMPORTANT, D3DERR + "Failed to create vertex buffer");
return false;
}
m_vertexbuffers[temp_vbuf] = MythD3DVertexBuffer(texture);
return temp_vbuf;
}
示例3: Create
bool VertexBuffer::Create()
{
Release();
if (!vertexCount_ || !elementMask_)
return true;
if (graphics_)
{
if (graphics_->IsDeviceLost())
{
URHO3D_LOGWARNING("Vertex buffer creation while device is lost");
return true;
}
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
HRESULT hr = device->CreateVertexBuffer(
vertexCount_ * vertexSize_,
usage_,
0,
(D3DPOOL)pool_,
(IDirect3DVertexBuffer9**)&object_,
0);
if (FAILED(hr))
{
URHO3D_SAFE_RELEASE(object_);
URHO3D_LOGD3DERROR("Could not create vertex buffer", hr);
return false;
}
}
return true;
}
示例4: Create
bool VertexBuffer::Create()
{
Release();
if (!vertexCount_ || !elementMask_)
return true;
if (graphics_)
{
if (graphics_->IsDeviceLost())
{
LOGWARNING("Vertex buffer creation while device is lost");
return true;
}
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
if (!device || FAILED(device->CreateVertexBuffer(
vertexCount_ * vertexSize_,
usage_,
0,
(D3DPOOL)pool_,
(IDirect3DVertexBuffer9**)&object_,
0)))
{
LOGERROR("Could not create vertex buffer");
return false;
}
}
return true;
}
示例5: _CreateBuffer
bool CSprite::_CreateBuffer()
{
const int iVertexCount = 6;
const UINT bufferSize = sizeof(SFaceVertex) * iVertexCount;
HRESULT hr;
CGraphicsManager *pGraphicsManager = CGraphicsManager::GetInstance();
IDirect3DDevice9 *pDevice = pGraphicsManager->GetDevice();
hr = pDevice->CreateVertexBuffer(bufferSize, 0, SFaceVertex::_fvf, D3DPOOL_DEFAULT, &m_pVertexBuffer, NULL);
if(FAILED(hr))
{
LogErrorHr("Failed to create vertex buffer for image rectangle", hr);
return false;
}
SFaceVertex *pVertices = NULL;
hr = m_pVertexBuffer->Lock(0, bufferSize, (void**)&pVertices, 0);
if(FAILED(hr))
{
LogErrorHr("Failed to lock image rectangle vertex buffer", hr);
return false;
}
_FillRectVertices(pVertices);
hr = m_pVertexBuffer->Unlock();
if(FAILED(hr))
{
LogErrorHr("Failed to unlock image rectangle vertex buffer", hr);
return false;
}
return true;
}
示例6: ZeroMemory
bool GPUContextDX9::initialize()
{
_window = DX9Window::create();
if( _window == NULL )
{
DX9WARN << "Could not create offscreen window.";
return false;
}
HWND windowHandle = _window->getWindowHandle();
_direct3D = Direct3DCreate9( D3D_SDK_VERSION );
if( _direct3D == NULL )
{
DX9WARN << "Could not create Direct3D interface.";
return false;
}
D3DPRESENT_PARAMETERS deviceDesc;
ZeroMemory( &deviceDesc, sizeof(deviceDesc) );
deviceDesc.Windowed = TRUE;
deviceDesc.SwapEffect = D3DSWAPEFFECT_DISCARD;
deviceDesc.BackBufferFormat = D3DFMT_UNKNOWN;
deviceDesc.EnableAutoDepthStencil = FALSE;
deviceDesc.AutoDepthStencilFormat = D3DFMT_D24S8;
HRESULT result = _direct3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, windowHandle,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &deviceDesc, &_device );
if( FAILED(result) )
{
DX9WARN << "Could not create Direct3D device.";
return false;
}
// create vertex buffer
static const int kMaxVertexCount = 64;
result = _device->CreateVertexBuffer(
kMaxVertexCount*sizeof(DX9Vertex), D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &_vertexBuffer, NULL );
DX9AssertResult( result, "CreateVertexBuffer failed" );
result = _device->CreateVertexDeclaration( kDX9VertexElements, &_vertexDecl );
DX9AssertResult( result, "CreateVertexDeclaration failed" );
// TIM: set up initial state
result = _device->SetRenderState( D3DRS_ZENABLE, D3DZB_FALSE );
GPUAssert( !FAILED(result), "SetRenderState failed" );
_passthroughVertexShader = createVertexShader( kPassthroughVertexShaderSource );
_passthroughPixelShader = createPixelShader( kPassthroughPixelShaderSource );
for( size_t i = 0; i < kMaximumOutputCount; i++ )
_boundOutputs[i] = NULL;
for( size_t t = 0; t < kMaximumSamplerCount; t++ )
_boundTextures[t] = NULL;
return true;
}
示例7: Error
gl::Error Blit9::initialize()
{
if (mGeometryLoaded)
{
return gl::Error(GL_NO_ERROR);
}
static const float quad[] =
{
-1, -1,
-1, 1,
1, -1,
1, 1
};
IDirect3DDevice9 *device = mRenderer->getDevice();
HRESULT result = device->CreateVertexBuffer(sizeof(quad), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &mQuadVertexBuffer, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to create internal blit vertex shader, result: 0x%X.", result);
}
void *lockPtr = NULL;
result = mQuadVertexBuffer->Lock(0, 0, &lockPtr, 0);
if (FAILED(result) || lockPtr == NULL)
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
SafeRelease(mQuadVertexBuffer);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal blit vertex shader, result: 0x%X.", result);
}
memcpy(lockPtr, quad, sizeof(quad));
mQuadVertexBuffer->Unlock();
static const D3DVERTEXELEMENT9 elements[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
D3DDECL_END()
};
result = device->CreateVertexDeclaration(elements, &mQuadVertexDeclaration);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
SafeRelease(mQuadVertexBuffer);
return gl::Error(GL_OUT_OF_MEMORY, "Failed to lock internal blit vertex declaration, result: 0x%X.", result);
}
mGeometryLoaded = true;
return gl::Error(GL_NO_ERROR);
}
示例8: assertion
//----------------------------------------------------------------------------
PdrVertexBuffer::PdrVertexBuffer (Renderer* renderer,
const VertexBuffer* vbuffer)
{
IDirect3DDevice9* device = renderer->mData->mDevice;
UINT numBytes = (UINT)vbuffer->GetNumBytes();
DWORD usage = gDX9BufferUsage[vbuffer->GetUsage()];
HRESULT hr = device->CreateVertexBuffer(numBytes, usage, 0,
D3DPOOL_DEFAULT, &mBuffer, 0);
WM5_UNUSED(hr);
assertion(hr == D3D_OK, "Failed to create vertex buffer: %s\n",
DXGetErrorString(hr));
void* data = Lock(Buffer::BL_WRITE_ONLY);
memcpy(data, vbuffer->GetData(), vbuffer->GetNumBytes());
Unlock();
}
示例9: initGeometry
void Blit::initGeometry()
{
static const float quad[] =
{
-1, -1,
-1, 1,
1, -1,
1, 1
};
IDirect3DDevice9 *device = getDevice();
HRESULT result = device->CreateVertexBuffer(sizeof(quad), D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &mQuadVertexBuffer, NULL);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY);
}
void *lockPtr = NULL;
result = mQuadVertexBuffer->Lock(0, 0, &lockPtr, 0);
if (FAILED(result) || lockPtr == NULL)
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY);
}
memcpy(lockPtr, quad, sizeof(quad));
mQuadVertexBuffer->Unlock();
static const D3DVERTEXELEMENT9 elements[] =
{
{ 0, 0, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
D3DDECL_END()
};
result = device->CreateVertexDeclaration(elements, &mQuadVertexDeclaration);
if (FAILED(result))
{
ASSERT(result == D3DERR_OUTOFVIDEOMEMORY || result == E_OUTOFMEMORY);
return error(GL_OUT_OF_MEMORY);
}
}
示例10: f2dGraphicsImpl
f2dGraphics2DImpl::f2dGraphics2DImpl(f2dRenderDeviceImpl* pParent, fuInt VertexBufferCount, fuInt IndexBufferCount)
: f2dGraphicsImpl(pParent),
m_pVB(NULL), m_pIB(NULL),
m_VBMaxCount(VertexBufferCount), m_IBMaxCount(IndexBufferCount),
m_VBUsedCount(0), m_IBUsedCount(0), m_VBAlloced(0), m_IBAlloced(0),
m_pVBData(NULL), m_pIBData(NULL),
m_ColorBlendType(F2DGRAPH2DBLENDTYPE_ADD)
{
// 设置默认的投影矩阵
SetProjTransform(fcyMatrix4::GetOrthoOffCenterLH(
0.f,
(float)pParent->GetBufferWidth(),
(float)pParent->GetBufferHeight(),
0.f, 0.f, 100.f
));
// 创建缓存
HRESULT tHR;
IDirect3DDevice9* pDev = (IDirect3DDevice9*)m_pParent->GetHandle();
if(FAILED(tHR = pDev->CreateVertexBuffer(
m_VBMaxCount * sizeof(f2dGraphics2DVertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
FVF,
D3DPOOL_DEFAULT,
&m_pVB,
NULL)))
{
throw fcyWin32COMException("f2dGraphics2DImpl::f2dGraphics2DImpl", "IDirect3DDevice9::CreateVertexBuffer Failed.", tHR);
}
if(FAILED(tHR = pDev->CreateIndexBuffer(
m_IBMaxCount * sizeof(fuShort),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_DEFAULT,
&m_pIB,
NULL)))
{
FCYSAFEKILL(m_pVB);
throw fcyWin32COMException("f2dGraphics2DImpl::f2dGraphics2DImpl", "IDirect3DDevice9::CreateIndexBuffer Failed.", tHR);
}
// 注册监听器
m_pParent->AttachListener(this);
}
示例11: sizeof
void f2dGraphics2DImpl::OnRenderDeviceReset()
{
IDirect3DDevice9* pDev = (IDirect3DDevice9*)m_pParent->GetHandle();
pDev->CreateVertexBuffer(
m_VBMaxCount * sizeof(f2dGraphics2DVertex),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
FVF,
D3DPOOL_DEFAULT,
&m_pVB,
NULL);
pDev->CreateIndexBuffer(
m_IBMaxCount * sizeof(fuShort),
D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16,
D3DPOOL_DEFAULT,
&m_pIB,
NULL);
}
示例12: Create
bool VertexBuffer::Create()
{
Release();
if (!vertexCount_ || elements_.Empty())
return true;
if (graphics_)
{
if (graphics_->IsDeviceLost())
{
ATOMIC_LOGWARNING("Vertex buffer creation while device is lost");
return true;
}
unsigned pool = dynamic_ ? D3DPOOL_DEFAULT : D3DPOOL_MANAGED;
unsigned d3dUsage = dynamic_ ? D3DUSAGE_DYNAMIC | D3DUSAGE_WRITEONLY : 0;
IDirect3DDevice9* device = graphics_->GetImpl()->GetDevice();
HRESULT hr = device->CreateVertexBuffer(
vertexCount_ * vertexSize_,
d3dUsage,
0,
(D3DPOOL)pool,
(IDirect3DVertexBuffer9**)&object_.ptr_,
0);
if (FAILED(hr))
{
ATOMIC_SAFE_RELEASE(object_.ptr_);
ATOMIC_LOGD3DERROR("Could not create vertex buffer", hr);
return false;
}
}
return true;
}
示例13: _FillBoxVBNormal
bool CBasicObjects::_FillBoxVBNormal()
{
HRESULT hr;
const int iTriangleCount = 2 * 6;
SNormalVertex boxCorners[2][2][2];
SNormalVertex boxTriangles[iTriangleCount * 3];
memset(boxCorners, 0, sizeof(boxCorners));
memset(boxTriangles, 0, sizeof(boxTriangles));
IDirect3DDevice9 * pDevice = CGraphicsManager::GetInstance()->GetDevice();
int iX, iY, iZ;
// fill corners
for(iX = 0; iX < 2; iX++)
{
for(iY = 0; iY < 2; iY++)
{
for(iZ = 0; iZ < 2; iZ++)
{
boxCorners[iX][iY][iZ].x = (float)iX;
boxCorners[iX][iY][iZ].y = (float)iY;
boxCorners[iX][iY][iZ].z = (float)iZ;
}
}
}
SNormalVertex * pBoxPoint = boxTriangles;
// fill triangles
// bottom
*pBoxPoint = boxCorners[0][0][0]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
_SetPrevFaceNormals(pBoxPoint, 0.0f, 0.0f, -1.0f);
// back
*pBoxPoint = boxCorners[0][0][0]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
_SetPrevFaceNormals(pBoxPoint, 0.0f, -1.0f, 0.0f);
// left
*pBoxPoint = boxCorners[0][0][0]; pBoxPoint++;
*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
_SetPrevFaceNormals(pBoxPoint, -1.0f, 0.0f, 0.0f);
// front
*pBoxPoint = boxCorners[0][1][0]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
_SetPrevFaceNormals(pBoxPoint, 0.0f, 1.0f, 0.0f);
// right
*pBoxPoint = boxCorners[1][1][0]; pBoxPoint++;
*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][0]; pBoxPoint++;
_SetPrevFaceNormals(pBoxPoint, 1.0f, 0.0f, 0.0f);
// top
*pBoxPoint = boxCorners[0][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][0][1]; pBoxPoint++;
*pBoxPoint = boxCorners[1][1][1]; pBoxPoint++;
*pBoxPoint = boxCorners[0][1][1]; pBoxPoint++;
_SetPrevFaceNormals(pBoxPoint, 0.0f, 0.0f, 1.0f);
if(m_pNormalBox != NULL)
{
LogError("Expected normal box VB to be NULL");
return false;
}
hr = pDevice->CreateVertexBuffer(sizeof(boxTriangles), 0, SNormalVertex::_fvf, D3DPOOL_DEFAULT, &m_pNormalBox,
NULL);
if(FAILED(hr))
{
LogErrorHr("Failed to create vertex buffer for normal box", hr);
return false;
}
VOID * pDevBox = NULL;
//.........这里部分代码省略.........
示例14: sizeof
void NX::Sphere::CreateTriangles() {
int nV = (m_iStacks - 1) * (m_iSlices + 1) + 2, r, c;
int nI = (m_iStacks - 2) * (m_iSlices + 1) * 2 + (m_iSlices + 2) * 2;
float rr = kfPiOver2, rc, dr = kfPi / m_iStacks, dc = kf2Pi / m_iSlices;
float sr, cr, sc, cc;
IDirect3DDevice9 *pDevice = glb_GetD3DDevice();
m_pVertexs = new Vertex[nV];
{//calculate vertex data
Vertex *pVertex = m_pVertexs;
*pVertex++ = { 0.f, m_fRadius, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f };
for (r = 1; r < m_iStacks; ++r) {
rr -= dr;
rc = 0.f;
cr = std::cosf(rr), sr = std::sinf(rr);
for (c = 0; c <= m_iSlices; ++c) {
sc = std::sinf(rc);
cc = std::cosf(rc);
*pVertex++ = { m_fRadius * cr * cc, m_fRadius * sr, m_fRadius * cr * sc, c * 1.f / m_iSlices, r * 1.f / m_iStacks, cr * cc, sr, cr * sc };
rc += dc;
}
}
*pVertex = { 0.f, -m_fRadius, 0.f, 0.f, 1.f, 0.f, -1.f, 0.f };
pDevice->CreateVertexBuffer(sizeof(Vertex) * nV, D3DUSAGE_WRITEONLY, 0, D3DPOOL_DEFAULT, &m_pVertexBuffer, nullptr);
void *pBase = nullptr;
m_pVertexBuffer->Lock(0, 0, &pBase, D3DLOCK_DISCARD);
memcpy(pBase, m_pVertexs, sizeof(Vertex) * nV);
m_pVertexBuffer->Unlock();
}
{//vertex desc
D3DVERTEXELEMENT9 VertexDesc[] = {
{ 0, CLS_MEM_OFFSET(Vertex, x), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
{ 0, CLS_MEM_OFFSET(Vertex, u), D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
{ 0, CLS_MEM_OFFSET(Vertex,nx), D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
D3DDECL_END(),
};
pDevice->CreateVertexDeclaration(VertexDesc, &m_pVertexDesc);
}
{//calculate index data
pDevice->CreateIndexBuffer(nI * sizeof(int), D3DUSAGE_WRITEONLY, D3DFMT_INDEX32, D3DPOOL_DEFAULT, &m_pIndexBuffer, nullptr);
int *pBase = nullptr;
m_pIndexBuffer->Lock(0, 0, (void**)&pBase, D3DLOCK_DISCARD);
for (int i = 0; i <= m_iSlices + 1; ++i) {//first stack, triangle_fan
*pBase++ = i;
}
int a = 1;
for (int i = 1; i < m_iStacks - 1; ++i) {//inner stacks, triangle_list
for (int j = 0; j <= m_iSlices; ++j) {
*pBase++ = a;
*pBase++ = a + m_iSlices + 1;
++a;
}
}
*pBase++ = (m_iStacks - 1) * (m_iSlices + 1) + 1;
for (int i = 0; i <= m_iSlices; ++i) {
*pBase++ = (m_iStacks - 2) * (m_iSlices + 1) + 1 + i;
}
m_pIndexBuffer->Unlock();
}
}
示例15: WinMain
int __stdcall WinMain(HINSTANCE, HINSTANCE, LPSTR, int){
Application app("Okienko");
// Inicjalizacja Direct3D
IDirect3D9* d3d = Direct3DCreate9(D3D_SDK_VERSION);
// Parametry urzadzenia
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = true;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferCount = 1;
d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8;
d3dpp.BackBufferHeight = app.get_height();
d3dpp.BackBufferWidth = app.get_width();
d3dpp.EnableAutoDepthStencil = true;
d3dpp.AutoDepthStencilFormat = D3DFMT_D24S8;
// Tworzenie urzadzenia
IDirect3DDevice9* dev;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, app.window_handle(),
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &dev);
app.init_font(dev, "Courier New");
dev->SetRenderState(D3DRS_CULLMODE, D3DCULL_NONE); // Brak obcinania scian
dev->SetRenderState(D3DRS_LIGHTING, false); // Brak swiatla
// Inicjalizacja kamery
// D3DXVECTOR3 eye(0, 5, -10);
D3DXVECTOR3 target(0, 0, 0);
D3DXVECTOR3 up(0, 1, 0);
D3DXMATRIXA16 view;
D3DXMATRIX mProjection;
D3DXMatrixPerspectiveFovLH(&mProjection, D3DX_PI * 0.5f, app.get_width()/(float)app.get_height(), 1, 50);
dev->SetTransform(D3DTS_PROJECTION, &mProjection);
// Model pudelka
Vertex box[] = {
// X Y Z Color
{ 1, 1, 1, D3DCOLOR_XRGB(255, 255, 255)},
{-1, 1, 1, D3DCOLOR_XRGB(0, 255, 255)},
{-1, 1, -1, D3DCOLOR_XRGB(0, 255, 0)},
{ 1, 1, -1, D3DCOLOR_XRGB(255, 255, 0)},
{ 1, -1, 1, D3DCOLOR_XRGB(255, 0, 255)},
{-1, -1, 1, D3DCOLOR_XRGB(0, 0, 255)},
{-1, -1, -1, D3DCOLOR_XRGB(0, 0, 0)},
{ 1, -1, -1, D3DCOLOR_XRGB(255, 0, 0)},
box[0], box[4], box[1], box[5], box[2], box[6], box[3], box[7], box[0], box[4]
};
int box_size = (16 + 2) * sizeof(Vertex);
// Tworzenie bufora wierzcholkow
IDirect3DVertexBuffer9* box_buffer;
dev->CreateVertexBuffer(box_size, 0, Vertex_Format, D3DPOOL_MANAGED, &box_buffer, NULL);
VOID* pVoid;
box_buffer->Lock(0, box_size, (void**)&pVoid, 0);
memcpy(pVoid, box, box_size);
box_buffer->Unlock();
dev->SetFVF(Vertex_Format);
dev->SetStreamSource(0, box_buffer, 0, sizeof(Vertex));
float radius = 3;
while(app.running()){
float alfa = app.get_alfa();
float beta = app.get_beta();
// Aktualizujemy kamere
D3DXVECTOR3 eye(
radius * cos(alfa) * sin(beta),
radius * cos(beta),
radius * sin(alfa) * sin(beta)
);
D3DXMatrixLookAtLH(&view, &eye, &target, &up);
dev->SetTransform(D3DTS_VIEW, &view);
// Rysujemy pudeleczko
dev->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
dev->BeginScene();
for(int i = 0; i < 2; i++) dev->DrawPrimitive(D3DPT_TRIANGLEFAN, i*4, 2);
dev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 8, 8);
app.print(10, 10, "Mysz X = %d", app.get_mouse_x());
app.print(10, 24, "Mysz Y = %d", app.get_mouse_y());
dev->EndScene();
dev->Present(NULL, NULL, NULL, NULL);
}
// Zwalniamy zasoby
box_buffer->Release();
dev->Release();
d3d->Release();
//.........这里部分代码省略.........