设为首页 加入收藏

TOP

(Visual C++)游戏开发笔记之三――绘制图元 (六)
2014-11-23 20:17:44 来源: 作者: 【 】 浏览:235
Tags:Visual 游戏 开发 笔记 之三 制图
/ Release any and all resources.
Shutdown();
// Unregister our window.
UnregisterClass(WINDOW_CLASS, wc.hInstance);
return 0;
}
bool InitializeD3D(HWND hWnd, bool fullscreen)
{
D3DDISPLAYMODE displayMode;
// Create the D3D object.
g_D3D = Direct3DCreate9(D3D_SDK_VERSION);
if(g_D3D == NULL) return false;
// Get the desktop display mode.
if(FAILED(g_D3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT,
&displayMode))) return false;
// Set up the structure used to create the D3DDevice.
D3DPRESENT_PARAMETERS d3dpp;
ZeroMemory(&d3dpp, sizeof(d3dpp));
if(fullscreen)
{
d3dpp.Windowed = FALSE;
d3dpp.BackBufferWidth = 640;
d3dpp.BackBufferHeight = 480;
}
else
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.BackBufferFormat = displayMode.Format;
// Create the D3DDevice
if(FAILED(g_D3D->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, hWnd, D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, &g_D3DDevice))) return false;
// Initialize any objects we will be displaying.
if(!InitializeObjects()) return false;
return true;
}
bool InitializeObjects()
{
unsigned long col = D3DCOLOR_XRGB(255, 255, 255);
// Fill in our structure to draw an object.
// x, y, z, color.
stD3DVertex objData[] =
{
{ 420.0f, 150.0f, 0.5f, col, },
{ 420.0f, 350.0f, 0.5f, col, },
{ 220.0f, 150.0f, 0.5f, col, },
{ 220.0f, 350.0f, 0.5f, col, },
};
// Create the vertex buffer.
if(FAILED(g_D3DDevice->CreateVertexBuffer(sizeof(objData), 0,
D3DFVF_VERTEX, D3DPOOL_DEFAULT, &g_VertexBuffer,
NULL))) return false;
// Fill the vertex buffer.
void *ptr;
if(FAILED(g_VertexBuffer->Lock(0, sizeof(objData),
(void**)&ptr, 0))) return false;
memcpy(ptr, objData, sizeof(objData));
g_VertexBuffer->Unlock();
return true;
}
void RenderScene()
{
// Clear the backbuffer.
g_D3DDevice->Clear(0, NULL, D3DCLEAR_TARGET,
D3DCOLOR_XRGB(0,0,0), 1.0f, 0);
// Begin the scene. Start rendering.
g_D3DDevice->BeginScene();
// Render object.
g_D3DDevice->SetStreamSource(0, g_VertexBuffer, 0,
sizeof(stD3DVertex));
g_D3DDevice->SetFVF(D3DFVF_VERTEX);
g_D3DDevice->DrawPrimitive(D3DPT_LINELIST, 0, 2);
// End the scene. Stop rendering.
g_D3DDevice->EndScene();
// Display the scene.
g_D3DDevice->Present(NULL, NULL, NULL, NULL);
}
void Shutdown()
{
if(g_D3DDevice != NULL) g_D3DDevice->Release();
if(g_D3D != NULL) g_D3D->Release();
if(g_VertexBuffer != NULL) g_VertexBuffer->Release();
g_D3DDevice = NULL;
g_D3D = NULL;
g_VertexBuffer = NULL;
}

编译并运行该程序,就可以在屏幕中间看到两条白色垂直并列的线段。

\


笔记三到这里就结束了。

本节源代码请点击这里下载:【Visual C++】Code_Note_3http://download.csdn.net/detail/zhmxy555/4175163

请大家继续关注【 Visual C++】游戏开发笔记系列。


非常希望能与大家一起交流,共同学习和进步。


最后,谢谢大家一直的支持~~~




摘自 枫落★流年


摘自
首页 上一页 3 4 5 6 下一页 尾页 6/6/6
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇(Visual C++)游戏开发笔记之一.. 下一篇(Visual C++)游戏开发笔记之四..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: