my first d3d application 哈哈哈。
呵呵,其实还蛮简单的,在d3d第一个例子,createdevice的基础上 照着书打了一个三角形的代码
总结一下,流程就是,main函数-》创建d3d设备-》创建顶点buff-》渲染。就出现了。
下一步研究下怎么贴图~
//-----------------------------------------------------------------------------// File: CreateDevice.cpp//// Desc: This is the first tutorial for using Direct3D. In this tutorial, all// we are doing is creating a Direct3D device and using it to clear the// window.//// Copyright (c) Microsoft Corporation. All rights reserved.//-----------------------------------------------------------------------------#include <d3d9.h>#pragma warning( disable : 4996 ) // disable deprecated warning #include <strsafe.h>#pragma warning( default : 4996 ) //-----------------------------------------------------------------------------// Global variables//-----------------------------------------------------------------------------LPDIRECT3D9 g_pD3D = NULL; // Used to create the D3DDeviceLPDIRECT3DDEVICE9 g_pd3dDevice = NULL; // Our rendering deviceLPDIRECT3DVERTEXBUFFER9 g_pVB=NULL; struct CUSTOMVERTEX{float x,y,z,rhw; DWORD color;}; HRESULT InitVB(){ CUSTOMVERTEX vertices[]= { {100.0f,400.0f,0.5f,1.0f,0xffff0000,}, {300.0f,50.0f,0.5f,1.0f,0xff00ff00,}, {500.0f,400.0f,0.5f,1.0f,0xff0000ff,}, }; if(FAILED(g_pd3dDevice->CreateVertexBuffer(3*sizeof(CUSTOMVERTEX),0,D3DFVF_XYZRHW|D3DFVF_DIFFUSE,D3DPOOL_DEFAULT,&g_pVB,NULL))) {return E_FAIL; } VOID *pVertices; if(FAILED(g_pVB->Lock(0,sizeof(vertices),(void**)&pVertices,0))) {return E_FAIL; } memcpy(pVertices,vertices,sizeof(vertices)); g_pVB->Unlock();return S_OK;}//-----------------------------------------------------------------------------// Name: InitD3D()// Desc: Initializes Direct3D//-----------------------------------------------------------------------------HRESULT InitD3D( HWND hWnd ){// Create the D3D object, which is needed to create the D3DDevice. if( NULL == ( g_pD3D = Direct3DCreate9( D3D_SDK_VERSION ) ) )return E_FAIL; // Set up the structure used to create the D3DDevice. Most parameters are// zeroed out. We set Windowed to TRUE, since we want to do D3D in a// window, and then set the SwapEffect to "discard", which is the most// efficient method of presenting the back buffer to the display. And // we request a back buffer format that matches the current desktop display // format. D3DPRESENT_PARAMETERS d3dpp; ZeroMemory( &d3dpp, sizeof( d3dpp ) ); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.BackBufferFormat = D3DFMT_UNKNOWN; // Create the Direct3D device. Here we are using the default adapter (most// systems only have one, unless they have multiple graphics hardware cards// installed) and requesting the HAL (which is saying we want the hardware// device rather than a software one). Software vertex processing is // specified since we know it will work on all cards. On cards that support // hardware vertex processing, though, we would see a big performance gain // by specifying hardware vertex processing. if( FAILED( g_pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &g_pd3dDevice ) ) ) {return E_FAIL; } // Device state would normally be set here return S_OK;} //-----------------------------------------------------------------------------// Name: Cleanup()// Desc: Releases all previously initialized objects//-----------------------------------------------------------------------------VOID Cleanup(){if( g_pd3dDevice != NULL ) g_pd3dDevice->Release(); if( g_pD3D != NULL ) g_pD3D->Release(); if( g_pVB != NULL ) g_pVB->Release();} //-----------------------------------------------------------------------------// Name: Render()// Desc: Draws the scene//-----------------------------------------------------------------------------VOID Render(){if( NULL == g_pd3dDevice )return; // Clear the backbuffer to a blue color g_pd3dDevice->Clear( 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB( 45, 50, 170 ), 1.0f, 0 ); // Begin the scene if( SUCCEEDED( g_pd3dDevice->BeginScene() ) ) { g_pd3dDevice->SetStreamSource(0,g_pVB,0,sizeof(CUSTOMVERTEX)); g_pd3dDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE); g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST,0,1); g_pd3dDevice->EndScene(); } // Present the backbuffer contents to the display g_pd3dDevice->Present( NULL, NULL, NULL, NULL );} //-----------------------------------------------------------------------------// Name: MsgProc()// Desc: The window's message handler//-----------------------------------------------------------------------------LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ){switch( msg ) {case WM_DESTROY: Cleanup(); PostQuitMessage( 0 );return 0; case WM_PAINT: Render(); ValidateRect( hWnd, NULL );return 0; } return DefWindowProc( hWnd, msg, wParam, lParam );} //-----------------------------------------------------------------------------// Name: wWinMain()// Desc: The application's entry point//-----------------------------------------------------------------------------INT WINAPI wWinMain( HINSTANCE hInst, HINSTANCE, LPWSTR, INT ){ UNREFERENCED_PARAMETER( hInst ); // Register the window class WNDCLASSEX wc = {sizeof( WNDCLASSEX ), CS_CLASSDC, MsgProc, 0L, 0L, GetModuleHandle( NULL ), NULL, NULL, NULL, NULL, L"D3D Tutorial", NULL }; RegisterClassEx( &wc ); // Create the application's window HWND hWnd = CreateWindow( L"D3D Tutorial", L"D3D Tutorial 01: CreateDevice", WS_OVERLAPPEDWINDOW, 200, 100, 600, 500, NULL, NULL, wc.hInstance, NULL ); // Initialize Direct3D if( SUCCEEDED( InitD3D( hWnd ) ) ) {// Show the window InitVB(); ShowWindow( hWnd, SW_SHOWDEFAULT ); UpdateWindow( hWnd ); // Enter the message loop MSG msg;while( GetMessage( &msg, NULL, 0, 0 ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } } UnregisterClass( L"D3D Tutorial", wc.hInstance );return 0;}
转载于:https://www.cnblogs.com/qhgongzi/archive/2011/07/13/2247701.html
my first d3d application 哈哈哈。相关推荐
- [cgdc12][nvidia]显卡底层知识
原文是<stuttering in game graphics:detection and solutions>由nv的技术总监cem cebenoyan在cgdc12上带来. 非常好的介 ...
- spring boot和spring cloud的区别_Spring聊聊application和bootstrap
用过Spring 的小伙伴都知道, application.yml或者 application.properties 是Spring 的引导配置文件,但是有了解过其中区别吗?本文将从这个问题入手,深入 ...
- 在Browser Application中使用XNA
在WPF中,我们使用Mode3D等API来绘制三维场景,当期间的"三角形"超过一定数量时,整个场景的渲染速率直线下降,无论显卡的运行速度有多快,帧率都维持在3.5帧每秒. XNA是 ...
- D3D中的粒子系统(1)
许多自然现象是由很多小的小颗粒组成的,它们有相似的行为.(例如,雪花落下,闪烁的火焰,冲出枪管的"子弹"),粒子系统用来模拟这种现象. 14.1 粒子和点精灵(Point Spri ...
- Designing Data-Intensive Application《数据密集型应用系统设计》笔记
Designing Data-Intensive Application 中译<设计数据密集型应用>又名<数据密集型应用系统设计>,我看的是冯若航在gitbook开源的翻译版本 ...
- openGL、D3D、vulkan区别简介
跨平台之王--OpenGL OpenGL发展至今,已经有20余年,作为一个成熟并久负盛名的跨平台计算机图形应用程序接口规范,它被广泛使用在游戏.影视.军事.航空航天.地理.医学.机械设计,以及各类科学 ...
- DirectX、Direct3D、OpenGL的区别(DX、D3D、OpenGL)
翻译自:https://www.extremetech.com/computing/54604-top-tip-what-are-opengl-direct3d-directx-etc 首先一点澄清: ...
- [转] Carmack 谈 d3d 与 ogl,定位专业应用的OpenGL,专注娱乐应用的DirectX,未来:OpenGL、DirectX并行发展
http://blog.csdn.net/xieyuquan/archive/2006/10/05/1321801.aspx 我找不到一个理由不让这篇文章多一份Copy 原地址:http://bbs. ...
- [转] Carmack 谈 d3d 与 ogl, 定位专业应用的OpenGL, 专注娱乐应用的DirectX, 未来:OpenGL、DirectX并行发展...
我找不到一个理由不让这篇文章多一份Copy 原地址:http://bbs.emu-zone.org/forums/archive/index.php/t-70.html 在经过这段时间的积累和沉淀 再 ...
- This application failed to start because it could not find or load the Qt platform plugin
还是不会来解决方法"windeployqt.exe" --release 和 --debug 要选对 C:\Windows\system32>"C:\Qt_X86\ ...
最新文章
- HDU2925(约瑟夫环问题)
- Java中比较对象的两个接口Comparable接口和Comparator接口
- C++容器(三):pair类型
- c/c++反混淆方法
- linux module原理,NodeJS的模块原理
- 如何将namedtuples序列化为JSON
- Flink CDC 系列 - Flink MongoDB CDC 在 XTransfer 的生产实践
- python怎么判断日期是星期几_【Java编程基本功】(八)逆序输出、是否为回文数,判断星期几,升序排列...
- 大规模分布式系统概念介绍
- autocad插件无法加载无法运行的解决办法
- 电驴无法增加服务器怎么办,电驴连接不上服务器怎么办?
- 现代控制理论公式大赏
- RPA拾取界面元素方式
- 头歌Python,7号的,作业,
- 情人节送什么礼物?四款情人节潮流数码好物推荐
- intellij idea 创建web 项目
- 一句话可以彻底改变一个人的命运
- 智源社区AI周刊:Hinton预测破解大脑机制时间;Gary Marcus批判追捧深度学习风潮;谷歌发布Imagen...
- 7-5 直捣黄龙 单源最短路 映射的使用和遍历
- 河北工业大学 计算机导师,河北工业大学